From 50bb63b924245f4fdbca9f666d5c8950c277fa4e Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sun, 28 Jul 2024 08:30:55 +0200 Subject: [PATCH] build docker image via jib --- .github/workflows/mfdzbuild.yml | 66 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/.github/workflows/mfdzbuild.yml b/.github/workflows/mfdzbuild.yml index 154d0c69710..918005c9e88 100644 --- a/.github/workflows/mfdzbuild.yml +++ b/.github/workflows/mfdzbuild.yml @@ -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 \ No newline at end of file + 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