Skip to content

Commit fc37b9b

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

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

.github/workflows/pipeline.yml

Lines changed: 22 additions & 5 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:
@@ -212,25 +212,42 @@ jobs:
212212
"org.opencontainers.image.url": "https://github.com/abhisheksr01/spring-boot-microservice-best-practices",
213213
"org.opencontainers.image.source": "https://github.com/abhisheksr01/spring-boot-microservice-best-practices",
214214
"org.opencontainers.image.version": ${{ steps.bump-version.outputs.bump-version }},
215-
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
215+
"org.opencontainers.image.created": "$(date +"%Y%m%d%H%M%S")",
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=oci,dest=companieshouse.tar
228+
platforms: linux/amd64
229+
- name: Scan Image
230+
uses: aquasecurity/[email protected]
231+
with:
232+
image-ref: companieshouse.tar
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+
buildctl image import < companieshouse.tar
242+
buildctl image push --name ${{ steps.meta.outputs.tags }}
243+
227244
create-release:
228245
if: ${{ needs.docker-build-push.outputs.is-dryrun-version-bumped == 'true' }} # Only release when new version is available
229246
runs-on: ubuntu-latest
230247
permissions:
231248
contents: write # to be able to publish a GitHub release
232249
needs:
233-
- docker-build-push
250+
- docker-build-scan-push
234251
environment:
235252
name: approve-release # Manual Approval to decide if we are ready to push tags and release
236253
steps:

0 commit comments

Comments
 (0)