Skip to content

#142 - Setup CI/CD 1️⃣ 🫸🌀✏️📗 :octocat:🐧🐳 #1

#142 - Setup CI/CD 1️⃣ 🫸🌀✏️📗 :octocat:🐧🐳

#142 - Setup CI/CD 1️⃣ 🫸🌀✏️📗 :octocat:🐧🐳 #1

Workflow file for this run

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