Skip to content

Commit 61e3b4f

Browse files
Added a new workflow to scan the docker image using Trivy.
1 parent 659cb3f commit 61e3b4f

2 files changed

Lines changed: 61 additions & 38 deletions

File tree

.github/workflows/ci-tests.yml

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Continuous Integration Tests
22

33
on:
44
pull_request:
5+
push:
6+
branches:
7+
- other/scan-notification
58

69
jobs:
710
unit-tests:
@@ -145,41 +148,3 @@ jobs:
145148
with:
146149
go-version-file: go.mod
147150
go-package: ./...
148-
149-
checkDockerImage:
150-
runs-on: ubuntu-latest
151-
name: scan Docker Image with Trivy
152-
steps:
153-
- name: Checkout code
154-
uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598 #2.0.0
155-
156-
157-
- name: Set up Docker
158-
uses: docker/setup-buildx-action@cf09c5c41b299b55c366aff30022701412eb6ab0 #v1.0.0
159-
160-
- name: Log in to Docker Hub
161-
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b #v2
162-
with:
163-
username: ${{ secrets.DOCKER_USERNAME }}
164-
password: ${{ secrets.DOCKER_PASSWORD }}
165-
- name: Build the project
166-
run: go build -o ./cx ./cmd
167-
- name: Build Docker image
168-
run: docker build -t ast-cli:${{ github.sha }} .
169-
- name: Run Trivy scanner without downloading DBs
170-
uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2 #v0.28.0
171-
with:
172-
scan-type: 'image'
173-
image-ref: ast-cli:${{ github.sha }}
174-
format: 'table'
175-
exit-code: '1'
176-
ignore-unfixed: true
177-
vuln-type: 'os,library'
178-
output: './trivy-image-results.txt'
179-
env:
180-
TRIVY_SKIP_JAVA_DB_UPDATE: true
181-
182-
- name: Inspect action report
183-
if: always()
184-
shell: bash
185-
run: cat ./trivy-image-results.txt
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Docker Image Security Scan
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- other/scan-notification
8+
# workflow_run:
9+
# workflows: ["Continuous Integration Tests"]
10+
# types:
11+
# - completed
12+
13+
jobs:
14+
checkDockerImage:
15+
name: Scan Docker Image with Trivy
16+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@cf09c5c41b299b55c366aff30022701412eb6ab0
30+
31+
- name: Log in to Docker Hub
32+
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
33+
with:
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
37+
- name: Build the project
38+
run: go build -o ./cx ./cmd
39+
40+
- name: Build Docker image
41+
run: docker build -t ast-cli:${{ github.event.workflow_run.head_sha }} .
42+
43+
- name: Run Trivy scan
44+
uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2
45+
with:
46+
scan-type: image
47+
image-ref: ast-cli:${{ github.event.workflow_run.head_sha }}
48+
format: table
49+
exit-code: 1
50+
ignore-unfixed: true
51+
vuln-type: os,library
52+
output: trivy-image-results.txt
53+
env:
54+
TRIVY_SKIP_JAVA_DB_UPDATE: true
55+
56+
- name: Show scan results
57+
if: always()
58+
run: cat trivy-image-results.txt

0 commit comments

Comments
 (0)