Skip to content

Commit ab44fd4

Browse files
feat: add trivy (#164)
* Update build-docker-artifacts workflow: disable image push and add Trivy vulnerability scanning * Add Trivy scan results upload step to build workflow * Update Trivy action output format to table for improved readability * Update Trivy action to output SARIF format and adjust result file path * Update Trivy action to use table format and add image push step * Add Dockerfile path to push image step in build workflow * Add image scanning step and vulnerability check to build workflow * Comment out image push step in build workflow * Uncomment image push step in build workflow * Set continue-on-error to false for Trivy scan and uncomment Dockerfile path in push image step * Remove commented-out Trivy scan result upload and adjust Trivy action configuration * Add Trivy configuration path for vulnerability scanning in build workflow * Remove Trivy configuration path from vulnerability scan step * Add Trivy configuration path for vulnerability scanning in build workflow * Remove Trivy configuration path from vulnerability scan step * Remove image scanning with aws steps from build workflow * Add image vulnerability scanning step to build workflow * Update Trivy action to version 0.30.0 in build workflow * Update Trivy action to use the main branch in vulnerability scanning step * chore: update Trivy action to version 0.30.0 in build workflow * fix: correct Trivy action version format in vulnerability scanner step * fix: update build-push action to load images instead of outputting type * test: push image * fix: remove image scan by aws steps * Fix: add if condition for trivy * Fix: remove MEDIUM from scanning --------- Co-authored-by: Michael Pühringer <[email protected]>
1 parent d074e64 commit ab44fd4

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

.github/workflows/build-docker-artifacts.yml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ jobs:
208208
with:
209209
context: .
210210
file: ${{ matrix.component.flavor_directory }}/${{ matrix.component.directory }}/Dockerfile
211-
push: true
211+
push: false
212+
load: true
212213
# Disable provenance as it creates weird multi-arch images: https://github.com/docker/build-push-action/issues/755
213214
provenance: false
214215
build-args: |
@@ -239,28 +240,32 @@ jobs:
239240
# https://github.com/docker/build-push-action/issues/1156#issuecomment-2437227730
240241
DOCKER_BUILD_SUMMARY: false
241242

243+
- name: Run Trivy vulnerability scanner
244+
if: ${{ inputs.skip_image_scan != true && fromJson(vars.SKIP_IMAGE_SCAN || 'false') != true && matrix.component.skip_image_scan != true }}
245+
uses: aquasecurity/[email protected]
246+
with:
247+
image-ref: ${{ vars.DV_AWS_ECR_REGISTRY }}/${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }}
248+
format: 'table'
249+
exit-code: '1'
250+
ignore-unfixed: false
251+
vuln-type: 'os,library'
252+
severity: 'HIGH,CRITICAL'
253+
continue-on-error: false
254+
255+
- name: Push image
256+
uses: docker/build-push-action@v6
257+
with:
258+
file: ${{ matrix.component.flavor_directory }}/${{ matrix.component.directory }}/Dockerfile
259+
push: true
260+
provenance: false
261+
context: .
262+
tags: |
263+
${{ vars.DV_AWS_ECR_REGISTRY }}/${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }}
264+
242265
- name: Log out from Amazon ECR
243266
shell: bash
244267
run: docker logout ${{ steps.login-ecr.outputs.registry }}
245268

246-
- name: Scan image
247-
if: ${{ inputs.skip_image_scan != true && fromJson(vars.SKIP_IMAGE_SCAN || 'false') != true && matrix.component.skip_image_scan != true }}
248-
id: get-ecr-scan-result
249-
uses: ./tmp/github-workflows/.github/actions/get-ecr-scan-result
250-
with:
251-
aws_role: ${{ vars.DV_AWS_ECR_ROLE }}
252-
aws_region: ${{ vars.DV_AWS_REGION }}
253-
ecr_registry: ${{ vars.DV_AWS_ECR_REGISTRY }}
254-
ecr_repository: ${{ matrix.component.ecr_repository }}
255-
image_tag: ${{ matrix.component.image_tag }}
256-
- name: Check scan results
257-
if: ${{ inputs.skip_image_scan != true && fromJson(vars.SKIP_IMAGE_SCAN || 'false') != true && matrix.component.skip_image_scan != true }}
258-
run: |
259-
if [ "${{ steps.get-ecr-scan-result.outputs.critical }}" != "null" ] || [ "${{ steps.get-ecr-scan-result.outputs.high }}" != "null" ]; then
260-
echo "Docker image contains vulnerabilities at critical or high level"
261-
exit 1 #exit execution due to docker image vulnerabilities
262-
fi
263-
264269
retag-images:
265270
name: Retag images of flavor ${{ matrix.flavor || 'default' }}
266271
needs: [get-flavors, build-flavors]

0 commit comments

Comments
 (0)