Skip to content

Commit d23aa5f

Browse files
committed
Add Trivy vulnerability scanning to Docker publish workflow
1 parent 530e072 commit d23aa5f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

.github/workflows/docker-publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
permissions:
1313
contents: read
1414
packages: write
15+
security-events: write
1516

1617
steps:
1718
- name: Checkout
@@ -41,6 +42,29 @@ jobs:
4142
username: ${{ github.actor }}
4243
password: ${{ secrets.GITHUB_TOKEN }}
4344

45+
- name: Build image for scanning
46+
uses: docker/build-push-action@v6
47+
with:
48+
context: docker
49+
load: true
50+
tags: ghcr.io/${{ github.repository }}:scan
51+
52+
- name: Scan image with Trivy
53+
id: trivy-scan
54+
uses: aquasecurity/trivy-action@master
55+
with:
56+
image-ref: ghcr.io/${{ github.repository }}:scan
57+
format: sarif
58+
output: trivy-results.sarif
59+
severity: CRITICAL,HIGH
60+
exit-code: '1'
61+
62+
- name: Upload Trivy scan results to GitHub Security
63+
uses: github/codeql-action/upload-sarif@v3
64+
if: always() && steps.trivy-scan.conclusion != 'skipped'
65+
with:
66+
sarif_file: trivy-results.sarif
67+
4468
- name: Build and push
4569
uses: docker/build-push-action@v6
4670
with:

0 commit comments

Comments
 (0)