diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 24c9f16b..db4f09d0 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: ${ DOCKER_TAGS } cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - name: Image digest