chore: update docker image tag #102
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
# Build | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
# Checkout repository with fetch-depth: 0 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.TOKEN }} | |
submodules: true | |
fetch-depth: 0 # Fetch the full Git history | |
# Set up JDK 17 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: gradle | |
# Cache Gradle dependencies | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# Build project with Gradle (excluding tests) | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
# Docker build and push | |
- name: Docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker build -t ${{ secrets.DOCKERHUB_REPOSITORY }} . | |
docker tag ${{ secrets.DOCKERHUB_REPOSITORY }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
# Deploy | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# Checkout repository with fetch-depth: 0 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensure SHA consistency | |
# Deploy using SSH | |
- name: Deploy application | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VM_INSTANCE }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
sudo docker-compose down | |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest donut | |
sudo docker-compose up -d --remove-orphans | |