improve multi-arch docker image build #36
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
strategy: | |
matrix: | |
os: [ ubuntu-latest, self-hosted ] | |
runs-on: ${{ matrix.os }} | |
outputs: | |
version_tag: ${{ steps.image.outputs.version_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 22 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '22' | |
distribution: 'liberica' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Run Check with Gradle | |
run: ./gradlew check | |
- name: Build native image | |
run: ./gradlew bootBuildImage | |
- name: Retrieve image infos | |
id: image | |
run: | | |
echo "version_tag=$(grep 'version = ' ./build.gradle.kts | awk -F'\"' '{print $2}')" >> "$GITHUB_OUTPUT" | |
echo "os_suffix=${{ matrix.os == 'ubuntu-latest' && 'amd64' || 'aarch64' }}" >> "$GITHUB_ENV" | |
- name: Log in to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push Images to Docker Registry | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/gateway:${{ steps.image.outputs.version_tag }}-${os_suffix} | |
manifest: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Log in to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Create Multi-architecture Manifest | |
run: | | |
docker manifest create ${{ secrets.DOCKERHUB_USERNAME }}/gateway:latest \ | |
--amend ${{ secrets.DOCKERHUB_USERNAME }}/gateway:${{ needs.build.outputs.version_tag }}-amd64 \ | |
--amend ${{ secrets.DOCKERHUB_USERNAME }}/gateway:${{ needs.build.outputs.version_tag }}-aarch64 | |
docker manifest push ${{ secrets.DOCKERHUB_USERNAME }}/gateway:latest |