Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 71 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,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: [linux/amd64, linux/arm64]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -47,7 +50,8 @@ jobs:
with:
java-version: ${{ env.java_version }}
distribution: ${{ env.java_distribution }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
Expand All @@ -73,23 +77,24 @@ jobs:
AXION_VERSION="$(./gradlew currentVersion -q -Prelease.quiet)"
echo "Set AXION_VERSION=${AXION_VERSION}"

# Use a platform-specific tag to avoid tag collision between parallel matrix jobs
PLATFORM_SLUG="${{ matrix.platform }}"
PLATFORM_SLUG="${PLATFORM_SLUG//\//-}" # replace / with - e.g. linux/amd64 -> linux-amd64

# determine docker tags
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
# tag releases with version determined by axion-release-plugin
DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}"
DOCKER_TAGS="${DOCKER_IMAGE}:${AXION_VERSION}-${PLATFORM_SLUG}"
else
# tag pushes to master as "latest"
DOCKER_TAGS="${DOCKER_IMAGE}:latest"
# tag pushes to master with platform suffix to avoid race condition
DOCKER_TAGS="${DOCKER_IMAGE}:latest-${PLATFORM_SLUG}"
fi
echo "Set DOCKER_TAGS=${DOCKER_TAGS}"

echo "version=${AXION_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT

# 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:
Expand All @@ -98,22 +103,77 @@ 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
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
- name: Test Docker container image
run: docker run --rm ${{ steps.prep.outputs.tags }} --help
- name: Push Docker container image
run: docker run --rm --platform ${{ matrix.platform }} ${{ 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 ${{ env.java_version }}-${{ env.java_distribution }}
uses: actions/setup-java@v3
with:
java-version: ${{ env.java_version }}
distribution: ${{ env.java_distribution }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- 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"
Comment thread
davidgamez marked this conversation as resolved.
DOCKER_TAGS="${DOCKER_IMAGE}:latest"
fi
echo "Set DOCKER_TAGS=${DOCKER_TAGS}"

echo "version=${AXION_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build and push multi-platform Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
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
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:17-jdk-noble AS build
FROM --platform=$BUILDPLATFORM eclipse-temurin:17-jdk-noble AS build

COPY --chown=gradle:gradle . /build
WORKDIR /build
Expand All @@ -9,7 +9,7 @@ RUN ./gradlew shadowJar \
-Prelease.forceVersion="${VERSION_TAG%-SNAPSHOT}"


FROM eclipse-temurin:17-jdk-noble AS runtime
FROM --platform=$TARGETPLATFORM eclipse-temurin:17-jdk-noble AS runtime
COPY --from=build /build/cli/build/libs/gtfs-validator-*-cli.jar /gtfs-validator-cli.jar
WORKDIR /

Expand Down
Loading