@@ -34,10 +34,13 @@ jobs:
3434 name : Test report - Java
3535 path : build/reports/tests/unit-test/aggregated-results/
3636
37- build_push :
37+ build_test :
3838 needs : test
39- name : Build and push Docker image
39+ name : Build/test Docker image
4040 runs-on : ubuntu-latest
41+ strategy :
42+ matrix :
43+ platform : [linux/amd64, linux/arm64]
4144 steps :
4245 - uses : actions/checkout@v3
4346 with :
4750 with :
4851 java-version : ${{ env.java_version }}
4952 distribution : ${{ env.java_distribution }}
50-
53+ - name : Set up QEMU
54+ uses : docker/setup-qemu-action@v3
5155 - name : Set up Docker Buildx
5256 uses : docker/setup-buildx-action@v2
5357 - name : Login to GitHub Container Registry
@@ -73,23 +77,24 @@ jobs:
7377 AXION_VERSION="$(./gradlew currentVersion -q -Prelease.quiet)"
7478 echo "Set AXION_VERSION=${AXION_VERSION}"
7579
80+ # Use a platform-specific tag to avoid tag collision between parallel matrix jobs
81+ PLATFORM_SLUG="${{ matrix.platform }}"
82+ PLATFORM_SLUG="${PLATFORM_SLUG//\//-}" # replace / with - e.g. linux/amd64 -> linux-amd64
83+
7684 # determine docker tags
7785 if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
7886 # tag releases with version determined by axion-release-plugin
79- DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}"
87+ DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}-${PLATFORM_SLUG} "
8088 else
81- # tag pushes to master as "latest"
82- DOCKER_TAGS="${DOCKER_IMAGE}:latest"
89+ # tag pushes to master with platform suffix to avoid race condition
90+ DOCKER_TAGS="${DOCKER_IMAGE}:latest-${PLATFORM_SLUG} "
8391 fi
8492 echo "Set DOCKER_TAGS=${DOCKER_TAGS}"
8593
8694 echo "version=${AXION_VERSION}" >> $GITHUB_OUTPUT
8795 echo "tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
8896 echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
8997
90- # Build and push steps are split up in order to test the built contaire image in between
91- # - build-args and labels inputs _must_ be kept matching between both to prevent rebuild
92- # - See: https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md
9398 - name : Build Docker container image
9499 uses : docker/build-push-action@v3
95100 with :
@@ -98,22 +103,77 @@ jobs:
98103 build-args : |
99104 VERSION_TAG=${{ steps.prep.outputs.version }}
100105 load : true
106+ platforms : ${{ matrix.platform }}
101107 tags : ${{ steps.prep.outputs.tags }}
102108 labels : |
103109 org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git
104110 org.opencontainers.image.created=${{ steps.prep.outputs.created }}
105111 org.opencontainers.image.revision=${{ github.sha }}
106112 org.opencontainers.image.version=${{ steps.prep.outputs.version }}
107113 - name : Test Docker container image
108- run : docker run --rm ${{ steps.prep.outputs.tags }} --help
109- - name : Push Docker container image
114+ run : docker run --rm --platform ${{ matrix.platform }} ${{ steps.prep.outputs.tags }} --help
115+ push_multiplatform :
116+ name : Build/Push multi-platform image
117+ needs : build_test
118+ runs-on : ubuntu-latest
119+ steps :
120+ - uses : actions/checkout@v3
121+ with :
122+ fetch-depth : 0 # need full clone so `./gradlew currentVersion` can search parents for older tags when needed
123+ - name : Set up JDK ${{ env.java_version }}-${{ env.java_distribution }}
124+ uses : actions/setup-java@v3
125+ with :
126+ java-version : ${{ env.java_version }}
127+ distribution : ${{ env.java_distribution }}
128+ - name : Set up QEMU
129+ uses : docker/setup-qemu-action@v3
130+ - name : Set up Docker Buildx
131+ uses : docker/setup-buildx-action@v2
132+ - name : Login to GitHub Container Registry
133+ uses : docker/login-action@v1
134+ with :
135+ registry : ghcr.io
136+ username : ${{ github.repository_owner }}
137+ password : ${{ secrets.GITHUB_TOKEN }}
138+ - name : Initialize Gradle
139+ run : |
140+ # The first time gradlew is invoked it downloads gradle and outputs progress about that to STDOUT.
141+ # This "dummy" invokation gets that out of the way so future gradlew commands have clean output
142+ ./gradlew --version
143+ - name : Prepare version metadata
144+ id : prep
145+ run : |
146+ # ghcr.io path should match current repo but be all lowercase
147+ DOCKER_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}
148+ echo "Set DOCKER_IMAGE=${DOCKER_IMAGE}"
149+
150+ # delegate to axion-release-plugin to generate version string from Git repository state
151+ echo "Detecting version with ./gradlew currentVersion"
152+ AXION_VERSION="$(./gradlew currentVersion -q -Prelease.quiet)"
153+ echo "Set AXION_VERSION=${AXION_VERSION}"
154+
155+ # determine docker tags
156+ if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
157+ # tag releases with version determined by axion-release-plugin
158+ DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}"
159+ else
160+ # tag pushes to master as "latest"
161+ DOCKER_TAGS="${DOCKER_IMAGE}:latest"
162+ fi
163+ echo "Set DOCKER_TAGS=${DOCKER_TAGS}"
164+
165+ echo "version=${AXION_VERSION}" >> $GITHUB_OUTPUT
166+ echo "tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
167+ echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
168+ - name : Build and push multi-platform Docker image
110169 uses : docker/build-push-action@v3
111170 with :
112171 context : .
113172 file : ./Dockerfile
114173 build-args : |
115174 VERSION_TAG=${{ steps.prep.outputs.version }}
116175 push : true
176+ platforms : linux/amd64,linux/arm64
117177 tags : ${{ steps.prep.outputs.tags }}
118178 labels : |
119179 org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git
0 commit comments