Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Publish Docker image
name: Build and publish Docker image

on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
build-scan-push:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -22,6 +24,7 @@ jobs:
- uses: docker/setup-buildx-action@v3

- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
Expand Down Expand Up @@ -56,8 +59,8 @@ jobs:
id: scan-ref
run: |
TAGS="${{ steps.meta.outputs.tags }}"
FIRST_TAG="${TAGS%%$'\n'*}"
echo "ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}" >> $GITHUB_OUTPUT
FIRST_REF="${TAGS%%$'\n'*}"
echo "ref=${FIRST_REF}" >> $GITHUB_OUTPUT

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
Expand All @@ -68,7 +71,8 @@ jobs:
format: table

- name: Push image
if: github.event_name != 'pull_request'
run: |
echo "${{ steps.meta.outputs.tags }}" | while read t; do
[ -n "$t" ] && docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$t"
echo "${{ steps.meta.outputs.tags }}" | while read ref; do
[ -n "$ref" ] && docker push "$ref"
done