Skip to content

Commit 5c6ab1e

Browse files
authored
INFRA: Added Docker Support (#5)
Resolves #3 * Added Docker Support * Fix syntax * Introduce Docker Builds on GH Actions * Updated Platforms for build * Update Action name
1 parent b8635de commit 5c6ab1e

File tree

7 files changed

+207
-12
lines changed

7 files changed

+207
-12
lines changed

.github/workflows/twitter-backend-pr-checker.yml

+15-11
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@ jobs:
5050
path: ~/.m2
5151
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
5252
restore-keys: ${{ runner.os }}-m2
53-
54-
- name: Cache SonarCloud packages
55-
uses: actions/cache@v2
56-
with:
57-
path: ~/.sonar/cache
58-
key: ${{ runner.os }}-sonar
59-
restore-keys: ${{ runner.os }}-sonar
6053

61-
- name: Build and Run Analysis
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
54+
- name: Build Package
6555
run: mvn -B clean verify
56+
57+
- name: Set up QEMU
58+
uses: docker/setup-qemu-action@v1
59+
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v1
62+
63+
- name: Build Container
64+
uses: docker/build-push-action@v2
65+
with:
66+
context: .
67+
platforms: linux/amd64,linux/arm64
68+
push: false
69+
tags: ghcr.io/scaleracademy/twitter-backend:pr-snapshot
6670

6771

6872
check-code-formatting:

.github/workflows/twitter-backend.yml

+35
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,41 @@ jobs:
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6464
run: mvn -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
65+
66+
- name: Set up QEMU
67+
uses: docker/setup-qemu-action@v1
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v1
71+
72+
- name: Login to DockerHub
73+
uses: docker/login-action@v1
74+
with:
75+
username: ${{ secrets.DOCKERHUB_USERNAME }}
76+
password: ${{ secrets.DOCKERHUB_TOKEN }}
77+
78+
- name: Login to GitHub Container Registry
79+
uses: docker/login-action@v1
80+
with:
81+
registry: ghcr.io
82+
username: ${{ github.repository_owner }}
83+
password: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Extract Maven project version
86+
run: echo ::set-output name=version::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
87+
id: project
88+
89+
- name: Build and push
90+
uses: docker/build-push-action@v2
91+
with:
92+
context: .
93+
platforms: linux/amd64,linux/arm64
94+
push: true
95+
tags: |
96+
subhrodip/twitter-backend:${{ steps.project.outputs.version }}
97+
subhrodip/twitter-backend:latest-snapshot
98+
ghcr.io/scaleracademy/twitter-backend:${{ steps.project.outputs.version }}
99+
ghcr.io/scaleracademy/twitter-backend:latest-snapshot
65100
66101

67102
check-code-formatting:

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changes
2+
3+
This document main purpose is to list changes which might affect backwards compatibility.
4+
It will not list all releases as Twitter Backend Java is built in a continous delivery fashion.
5+
6+
### 0.1.0-SNAPSHOT
7+
* Fix #1: Added GitHub Action workflows
8+
* Fix #3: Added Docker support

Dockerfile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Twitter Backend - Moo: Twitter Clone Application Backend by Scaler
3+
# Copyright © 2021 Subhrodip Mohanta ([email protected])
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
# Use latest openjdk:11-jre-slim image as the base
20+
FROM openjdk:11-jre-slim
21+
22+
LABEL maintainer="Subhrodip Mohanta <[email protected]>"
23+
LABEL artifact="twitter-backend"
24+
LABEL platform="java"
25+
LABEL name="Twitter Backend"
26+
LABEL org.opencontainers.image.source="https://github.com/scaleracademy/twitter-backend-java"
27+
28+
# If the container is launched with re-mapped ports, these
29+
# ENV vars should be set to the remapped values.
30+
ENV MYSQL_DB_HOST db
31+
ENV MYSQL_DB_PORT 3306
32+
ENV MYSQL_DB_UNAME root
33+
ENV MYSQL_DB_PASSWD root
34+
35+
ARG JAR_FILE=target/*.jar
36+
37+
COPY ${JAR_FILE} app.jar
38+
39+
# If you are changing server port, be sure to change this as well
40+
EXPOSE 8080
41+
42+
#Running the application with `prod` profile
43+
ENTRYPOINT [ "java", "-jar", "-Dspring.profiles.active=prod", "/app.jar" ]

docker-compose.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Twitter Backend - Moo: Twitter Clone Application Backend by Scaler
3+
# Copyright © 2021 Subhrodip Mohanta ([email protected])
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
version: "3"
20+
21+
services:
22+
23+
db:
24+
image: mariadb:10.5
25+
volumes:
26+
- db_data:/var/lib/mysql
27+
restart: always
28+
environment:
29+
MYSQL_ROOT_PASSWORD: root
30+
MYSQL_DATABASE: twitter
31+
MYSQL_USER: twitter
32+
MYSQL_PASSWORD: twitter
33+
34+
twitter-backend:
35+
depends_on:
36+
- db
37+
image: subhrodip/twitter-backend:latest
38+
ports:
39+
- "8080:8080"
40+
restart: always
41+
environment:
42+
MYSQL_DB_HOST: db
43+
MYSQL_DB_PORT: 3306
44+
MYSQL_DB_UNAME: root
45+
MYSQL_DB_PASSWD: root
46+
47+
volumes:
48+
db_data: {}

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<groupId>xyz.subho.clone</groupId>
3434
<artifactId>twitter</artifactId>
35-
<version>0.0.1-SNAPSHOT</version>
35+
<version>0.1.0-SNAPSHOT</version>
3636
<name>Twitter Backend</name>
3737
<description>Moo: Twitter Clone Application Backend by Scaler</description>
3838

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Twitter Backend - Moo: Twitter Clone Application Backend by Scaler
3+
# Copyright © 2021 Subhrodip Mohanta ([email protected])
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
###### THIS IS THE DEV PROPERTIES #####
20+
21+
# =====================================
22+
# ========= SPRING SECURITY ===========
23+
# =====================================
24+
25+
26+
27+
# =====================================
28+
# =========== DATA SOURCE =============
29+
# =====================================
30+
31+
# Set here configurations for the database connection
32+
spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/twitter?createDatabaseIfNotExist=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Kolkata&useSSL=false
33+
34+
# Username and secret
35+
spring.datasource.username=${MYSQL_DB_UNAME}
36+
spring.datasource.password=${MYSQL_DB_PASSWD}
37+
38+
# Keep the connection alive if idle for a long time (needed in production)
39+
spring.datasource.testWhileIdle=true
40+
spring.datasource.validationQuery=SELECT 1
41+
42+
43+
# ====================================
44+
# ========= JPA / HIBERNATE ==========
45+
# ====================================
46+
47+
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
48+
# stripped before adding them to the entity manager).
49+
# Show or not log for each sql query
50+
spring.jpa.show-sql=true
51+
spring.jpa.properties.hibernate.format_sql=true
52+
53+
54+
# Allows Hibernate to generate SQL optimized for a particular DBMS
55+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
56+
spring.jpa.properties.hibernate.id.new_generator_mappings=false
57+

0 commit comments

Comments
 (0)