Skip to content

Commit 0e7ccd5

Browse files
committed
ci(gha): perform trivy image scan after docker build
1 parent ee27841 commit 0e7ccd5

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.github/workflows/pipeline.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
env:
160160
PR_URL: ${{github.event.pull_request.html_url}}
161161
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
162-
docker-build-push:
162+
docker-build-scan-push:
163163
if: github.ref == 'refs/heads/main'
164164
runs-on: ubuntu-latest
165165
needs:
@@ -215,22 +215,38 @@ jobs:
215215
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
216216
"org.opencontainers.image.revision": ${{ github.sha }},
217217
"org.opencontainers.image.licenses": "MIT"
218-
- name: Build and push
218+
- name: Build Image
219219
if: ${{ steps.bump-version.outputs.is-dryrun-version-bumped == 'true' }}
220220
uses: docker/build-push-action@v6
221221
with:
222-
push: ${{ github.event_name != 'pull_request' && steps.bump-version.outputs.is-dryrun-version-bumped == 'true' }} # Only push on main branch & when version is bumped with dryrun. We will create tags and creates separately after proper testing
222+
push: false
223223
tags: ${{ steps.meta.outputs.tags }}
224224
labels: ${{ steps.meta.outputs.labels }}
225225
sbom: true
226226
provenance: true
227+
outputs: type=docker,dest=companieshouse.tar
228+
platforms: linux/amd64
229+
- name: Scan Image
230+
uses: aquasecurity/[email protected]
231+
with:
232+
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
233+
format: 'table'
234+
exit-code: '1'
235+
ignore-unfixed: true
236+
vuln-type: 'os,library'
237+
scanners: 'vuln,secret,misconfig,license'
238+
- name: Push Image
239+
if: ${{ github.event_name != 'pull_request' && steps.bump-version.outputs.is-dryrun-version-bumped == 'true' }} # Only push on main branch & when version is bumped with dryrun. We will create tags and creates separately after proper testing
240+
run: |
241+
docker load -i companieshouse.tar
242+
docker push ${{ steps.meta.outputs.tags }}
227243
create-release:
228244
if: ${{ needs.docker-build-push.outputs.is-dryrun-version-bumped == 'true' }} # Only release when new version is available
229245
runs-on: ubuntu-latest
230246
permissions:
231247
contents: write # to be able to publish a GitHub release
232248
needs:
233-
- docker-build-push
249+
- docker-build-scan-push
234250
environment:
235251
name: approve-release # Manual Approval to decide if we are ready to push tags and release
236252
steps:

0 commit comments

Comments
 (0)