Skip to content

Commit

Permalink
build docker image via jib
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed Jul 28, 2024
1 parent f409a61 commit 50bb63b
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions .github/workflows/mfdzbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,44 @@ jobs:
mvn --batch-mode jacoco:prepare-agent test jacoco:report -P prettierCheck -Dprettier.nodePath=node -Dprettier.npmPath=npm
mvn --batch-mode package -Dmaven.test.skip -P prettierSkip
- name: set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: log into the GitHub Container Registry
uses: docker/login-action@v3
container-image:
if: github.repository_owner == 'mfdz' && github.event_name == 'push' && (github.ref == 'refs/heads/aachen')
runs-on: ubuntu-latest
needs:
- build-linux
steps:
- uses: actions/checkout@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: set env vars for repo, branch and image tag
run: |
echo "DATE_TAG=$(date +%Y-%m-%dT%H-%M)" >> $GITHUB_ENV
echo "BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
echo "REPO=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV

- name: build and push Docker image
if: github.event_name == 'push' && (github.ref == 'refs/heads/aachen')
uses: docker/build-push-action@v6
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
- uses: actions/setup-node@v4
with:
push: true
tags: |
ghcr.io/${{ env.REPO }}:${{ env.BRANCH }}
ghcr.io/${{ env.REPO }}:${{ env.BRANCH }}-${{ env.DATE_TAG }}
platforms: linux/amd64,linux/arm64
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
cache-from: type=gha
cache-to: type=gha,mode=max
node-version: 18
- name: Build container image with Jib, push to Dockerhub
env:
CONTAINER_REPO: docker.io/mfdz/opentripplanner
CONTAINER_REGISTRY_USER: ${{ secrets.DOCKER_USER }}
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }}
run: |
# we give the container two tags
# - "aachen-latest"
# - a string like "aachen-2.3_2022-12-12T21-38"
version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout`
version=${version_with_snapshot/-SNAPSHOT/}
image_version=${version}
## if the Maven version contains SNAPSHOT, then add date to tag
if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then
image_date=`date +%Y-%m-%dT%H-%M`
image_version="${version}_${image_date}"
echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag"
fi
mvn --batch-mode -P prettierSkip compile com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=aachen-latest,aachen-$image_version

0 comments on commit 50bb63b

Please sign in to comment.