Skip to content
name: When Release - Build, and Push Docker Image
on:
release:
types: [ published ]
jobs:
build-test-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- id: setup-java-17
name: Setup Java 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: 'maven'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compile and package Maven project
run: mvn clean package -DskipTests
- name: Build and push Docker image
run: |
docker buildx create --use
echo "${{ github.event.release.tag_name }}" > ./build.hash
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg BUILD_HASH=${{ github.event.release.tag_name }} \
-t ghcr.io/${{ github.repository_owner }}/${{ github.repository_name || github.event.repository.name }}:${{ github.event.release.tag_name }} \
-t ghcr.io/${{ github.repository_owner }}/${{ github.repository_name || github.event.repository.name }}:latest \
--push \
--build-arg JAR_FILE=target/*.jar \
.