Skip to content

Commit

Permalink
#142 - Setup CI/CD 1️⃣ 🫸🌀✏️📗 :octocat:🐧🐳
Browse files Browse the repository at this point in the history
  • Loading branch information
hendisantika committed Mar 12, 2024
1 parent 041d0f8 commit bffa4d8
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
109 changes: 109 additions & 0 deletions .github/workflows/app-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: BMI application workflow
on:
pull_request:
branches: [ master ]
paths:
- 'src/**'
- '.github/workflows/app-workflow.yml'
push:
branches: [ master ]
paths:
- 'src/**'
- '.github/workflows/app-workflow.yml'

jobs:
project-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'

- name: Set up the Maven dependencies caching
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Install Maven dependencies
run: mvn clean install

- name: Run tests
run: mvn clean --batch-mode --update-snapshots verify

docker-build:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs:
- project-build
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log into the Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Scrape build info
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
labels: ${{ steps.meta.outputs.labels }}
# tags: hendisantika/bmi:${{ steps.meta.outputs.tags }}
# tags: ${{ steps.meta.outputs.tags }}
# tags: hendisantika/bmi:latest
tags: hendisantika/bmi:${{ github.run_number }}
build-args: |
GIT_VERSION_TAG=${{ env.RELEASE_VERSION }}
GIT_COMMIT_MESSAGE=${{ github.event.head_commit.message }}
GIT_VERSION_HASH=${{ github.sha }}
deploy:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs:
- docker-build
steps:
- uses: actions/checkout@v4
- name: Add Server key
run: |
touch key.txt && echo "${{ secrets.SERVER_KEY }}" > key.txt
chmod 600 key.txt
- name: Deploy the application
env:
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_PORT: ${{ secrets.SERVER_PORT }}
SERVER_USER: ${{ secrets.SERVER_USERNAME }}
run: |
set -e
./deploy.sh
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- mysql
networks:
- spring-boot-app

mysql:
image: mysql:latest
environment:
Expand All @@ -17,7 +18,7 @@ services:
- "3307:3306"
networks:
- spring-boot-app
-

reverse-proxy:
image: nginx:latest
ports:
Expand Down
11 changes: 11 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
events {
}

http {
server {
listen 80;
location / {
proxy_pass http://app:9000;
}
}
}

0 comments on commit bffa4d8

Please sign in to comment.