-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: build & publish multi-platform image(linux/arm64, linux/adm64) Docker images #1528
base: master
Are you sure you want to change the base?
Changes from all commits
3811cf1
25beab5
bd88b16
33b1d15
607409e
3e21a81
37fbb0d
7e7fd30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,13 @@ jobs: | |
name: Test report - Java | ||
path: build/reports/tests/unit-test/aggregated-results/ | ||
|
||
build_push: | ||
build_test: | ||
needs: test | ||
name: Build and push Docker image | ||
name: Build/test Docker image | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
platform: [amd64 , arm64] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
|
@@ -97,9 +100,6 @@ jobs: | |
echo ::set-output name=tags::${DOCKER_TAGS} | ||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
|
||
# Build and push steps are split up in order to test the built contaire image in between | ||
# - build-args and labels inputs _must_ be kept matching between both to prevent rebuild | ||
# - See: https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md | ||
- name: Build Docker container image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
|
@@ -108,6 +108,7 @@ jobs: | |
build-args: | | ||
VERSION_TAG=${{ steps.prep.outputs.version }} | ||
load: true | ||
platforms: ${{ matrix.platform }} | ||
tags: ${{ steps.prep.outputs.tags }} | ||
labels: | | ||
org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git | ||
|
@@ -116,6 +117,78 @@ jobs: | |
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | ||
- name: Test Docker container image | ||
run: docker run --rm ${{ steps.prep.outputs.tags }} --help | ||
push_multiplatform: | ||
name: Build/Push multi-platform image | ||
needs: build_test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # need full clone so `./gradlew currentVersion` can search parents for older tags when needed | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | ||
restore-keys: ${{ runner.os }}-gradle | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Initialize Gradle | ||
run: | | ||
# The first time gradlew is invoked it downloads gradle and outputs progress about that to STDOUT. | ||
# This "dummy" invokation gets that out of the way so future gradlew commands have clean output | ||
./gradlew --version | ||
- name: Prepare version metadata | ||
id: prep | ||
run: | | ||
# ghcr.io path should match current repo but be all lowercase | ||
DOCKER_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,} | ||
echo "Set DOCKER_IMAGE=${DOCKER_IMAGE}" | ||
|
||
# delegate to axion-release-plugin to generate version string from Git repository state | ||
echo "Detecting version with ./gradlew currentVersion" | ||
AXION_VERSION="$(./gradlew currentVersion -q -Prelease.quiet)" | ||
echo "Set AXION_VERSION=${AXION_VERSION}" | ||
|
||
# determine docker tags | ||
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then | ||
# tag releases with version determined by axion-release-plugin | ||
DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}" | ||
else | ||
# tag pushes to master as "latest" | ||
DOCKER_TAGS="${DOCKER_IMAGE}:latest" | ||
fi | ||
echo "Set DOCKER_TAGS=${DOCKER_TAGS}" | ||
|
||
echo ::set-output name=version::${AXION_VERSION} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ::set-output is deprecated. |
||
echo ::set-output name=tags::${DOCKER_TAGS} | ||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
- name: Build Docker container image | ||
uses: docker/build-push-action@v3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why it seems to build an image twice, one here and once in "Push Docker container image" below. The two command lines to build the images are identical (obtained form the logs) except for the --push |
||
with: | ||
context: . | ||
file: ./Dockerfile | ||
build-args: | | ||
VERSION_TAG=${{ steps.prep.outputs.version }} | ||
load: false | ||
platforms: linux/amd64, linux/arm64 | ||
tags: ${{ steps.prep.outputs.tags }} | ||
labels: | | ||
org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git | ||
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | ||
- name: Push Docker container image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
|
@@ -124,6 +197,7 @@ jobs: | |
build-args: | | ||
VERSION_TAG=${{ steps.prep.outputs.version }} | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.prep.outputs.tags }} | ||
labels: | | ||
org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY,,}.git | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem running this action (see https://github.com/MobilityData/gtfs-validator/actions/runs/5833255963)
I suspect it's because with the matrix we build 2 images but give them the same tag (ghcr.io/mobilitydata/gtfs-validator:latest, see line 95 below).
Since it appears the matrix strategy runs in parallel for the 2 platforms, this could cause a race condition and it will fail or not depending on the time it takes to create and put the images in the local registry.
I suggest you add a suffix to the DOCKER_TAGS variable on line 95 below. Something like:
DOCKER_TAGS="${DOCKER_IMAGE}.${{ matrix.platform }}:latest"
And see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it and the problem is still present. Although I think it would not hurt to keep this fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to run the arm64 version on an arm64 platform, or use emulation.