Skip to content

Commit c97e03d

Browse files
authored
Added trivy to pipeline
1 parent 913aa26 commit c97e03d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

.github/workflows/docker.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Image
1+
name: Build, Scan and Push Docker Image
22

33
on:
44
push:
@@ -8,10 +8,17 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010

11+
outputs:
12+
image-tag: ${{ steps.tag.outputs.sha_tag }}
13+
1114
steps:
1215
- name: Checkout code
1316
uses: actions/checkout@v3
1417

18+
- name: Set image tag
19+
id: tag
20+
run: echo "sha_tag=${GITHUB_SHA}" >> $GITHUB_OUTPUT
21+
1522
- name: Log in to DockerHub
1623
uses: docker/login-action@v2
1724
with:
@@ -28,3 +35,32 @@ jobs:
2835
IMAGE_BASE=${{ secrets.DOCKERHUB_USERNAME }}/myhello
2936
docker push $IMAGE_BASE:latest
3037
docker push $IMAGE_BASE:${{ github.sha }}
38+
39+
scan:
40+
runs-on: ubuntu-latest
41+
needs: build
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v3
46+
47+
- name: Trivy Image Scan
48+
uses: aquasecurity/trivy-action@master
49+
with:
50+
image-ref: ${{ secrets.DOCKERHUB_USERNAME }}/myhello:${{ needs.build.outputs.image-tag }}
51+
format: 'table'
52+
exit-code: '1'
53+
ignore-unfixed: true
54+
vuln-type: 'os,library'
55+
severity: 'CRITICAL,HIGH'
56+
57+
- name: Trivy FS Scan (source & Dockerfile)
58+
uses: aquasecurity/trivy-action@master
59+
with:
60+
scan-type: 'fs'
61+
scan-ref: '.'
62+
format: 'table'
63+
exit-code: '1'
64+
ignore-unfixed: true
65+
vuln-type: 'os,library'
66+
severity: 'CRITICAL,HIGH'

0 commit comments

Comments
 (0)