From a1ad05d22f66363ce84e78c829ee1f8986ba4276 Mon Sep 17 00:00:00 2001 From: dbernstein Date: Mon, 20 May 2024 12:34:25 -0700 Subject: [PATCH] Publish docker images for PRs that are labelled with version, pr number, and sha. (#73) --- .github/workflows/ci-build.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 24c9f16b..eb2cb527 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -78,7 +78,6 @@ jobs: - name: Login to GHCR.IO uses: docker/login-action@v1 - if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') with: registry: ghcr.io username: ${{ github.repository_owner }} @@ -87,11 +86,9 @@ jobs: - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') - name: Cache Docker layers uses: actions/cache@v2 - #if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} @@ -102,10 +99,23 @@ jobs: run: echo ::set-output name=version::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) id: project_version + + - name: Set docker tags (PR) + if: ${{ github.event_name == 'pull_request' }} + shell: bash + run: | + echo "DOCKER_TAGS=ghcr.io/${{ github.repository }}:${{ steps.project_version.outputs.version }}-PR-${{github.event.number}}-${{github.event.pull_request.head.sha}}" >> ${GITHUB_ENV} + + - name: Set docker tags (Push) + if: ${{ github.event_name == 'push' }} + shell: bash + run: | + echo "DOCKER_TAGS=ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ steps.project_version.outputs.version }}" >> ${GITHUB_ENV} + - name: Build and push id: docker_build uses: docker/build-push-action@v2 - if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') + if: github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main')) with: context: ./ file: ./docker/Dockerfile @@ -113,7 +123,7 @@ jobs: platforms: linux/amd64 push: true build-args: VERSION=${{ steps.project_version.outputs.version }} - tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ steps.project_version.outputs.version }} + tags: ${{ env.DOCKER_TAGS}} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - name: Image digest