Skip to content

Commit 4c69b87

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

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.github/workflows/pipeline.yml

Lines changed: 19 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,37 @@ 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+
- name: Scan Image
229+
uses: aquasecurity/[email protected]
230+
with:
231+
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
232+
format: 'table'
233+
exit-code: '1'
234+
ignore-unfixed: true
235+
vuln-type: 'os,library'
236+
scanners: 'vuln,secret,misconfig,license'
237+
- name: Push Image
238+
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
239+
run: |
240+
docker load -i companieshouse.tar
241+
docker push ${{ steps.meta.outputs.tags }}
227242
create-release:
228243
if: ${{ needs.docker-build-push.outputs.is-dryrun-version-bumped == 'true' }} # Only release when new version is available
229244
runs-on: ubuntu-latest
230245
permissions:
231246
contents: write # to be able to publish a GitHub release
232247
needs:
233-
- docker-build-push
248+
- docker-build-scan-push
234249
environment:
235250
name: approve-release # Manual Approval to decide if we are ready to push tags and release
236251
steps:

0 commit comments

Comments
 (0)