Skip to content

Publish klabis/backend Docker Image #13

Publish klabis/backend Docker Image

Publish klabis/backend Docker Image #13

name: Publish klabis/backend Docker Image
on:
push:
branches:
- main
workflow_dispatch: # Manual trigger
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '21'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Publish Docker Image
working-directory: backend
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Build the Docker image and tag it with both the 'latest', commit hash, and tag if exist
./gradlew bootBuildImage --imageName=ghcr.io/${{ github.repository }}:latest
./gradlew bootBuildImage --imageName=ghcr.io/${{ github.repository }}:$(git rev-parse --short HEAD)
TAG=$(git describe --tags --exact-match 2>/dev/null || echo "")
if [ -n "$TAG" ]; then
./gradlew bootBuildImage --imageName=ghcr.io/${{ github.repository }}:$TAG
fi
- name: Verify image
run: docker images