Skip to content

Commit

Permalink
Publish docker images for PRs that are labelled with version, pr numb…
Browse files Browse the repository at this point in the history
…er, and sha.
  • Loading branch information
dbernstein committed May 20, 2024
1 parent 94a9cd0 commit 1a1fa39
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -102,18 +99,31 @@ 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
builder: ${{ steps.buildx.outputs.name }}
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
Expand Down

0 comments on commit 1a1fa39

Please sign in to comment.