Skip to content

Commit

Permalink
Publish docker image only once (#926)
Browse files Browse the repository at this point in the history
  Checks for the existence of a docker image in github container
  repository before publishing a duplicate build of the same
  into github container repository.
  • Loading branch information
nichlaes authored Sep 23, 2024
1 parent cede74b commit fe2ded9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
registry:
required: false
type: string
default: 'ghcr.io'
default: "ghcr.io"
image-name:
required: true
type: string
version:
required: true
type: string
default: 'latest'
default: "latest"
dockerfile:
required: true
type: string
Expand All @@ -23,8 +23,8 @@ jobs:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
contents: read
packages: write

steps:
- name: Checkout Repository
Expand All @@ -37,7 +37,19 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check if version exists
id: check_version
run: |
if docker manifest inspect ${{ inputs.registry }}/${{ inputs.image-name }}:${{ inputs.version }} > /dev/null 2>&1; then
echo "Version ${{ inputs.version }} already exists."
echo "exists=true" >> $GITHUB_ENV
else
echo "Version ${{ inputs.version }} does not exist."
echo "exists=false" >> $GITHUB_ENV
fi
- name: Build and push Docker image
if: env.exists == 'false'
uses: docker/build-push-action@v5
with:
context: .
Expand Down

0 comments on commit fe2ded9

Please sign in to comment.