Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,23 @@ jobs:
username: ${{ secrets.username }}
password: ${{ secrets.password }}

- name: Build Docker Image
- name: Build Docker image
uses: docker/build-push-action@v6
with:
build-args: ${{ inputs.build-args }}
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
load: true # Make the image available on runner
Comment thread
jbern0rd marked this conversation as resolved.
push: false # Don't push yet, wait for security checks
tags: ${{ inputs.image-name }}:${{ inputs.image-tag }}

- name: Build Docker Image as Tarball
if: ${{ inputs.security-scan }}
run: |
BUILD_ARGS=""
if [ -n "${{ inputs.build-args }}" ]; then
while IFS= read -r line; do
if [ -n "$line" ]; then
BUILD_ARGS="$BUILD_ARGS --build-arg $line"
fi
done <<< "${{ inputs.build-args }}"
fi
docker build $BUILD_ARGS -t ${{ inputs.image-name }}:${{ inputs.image-tag }} -f ${{ inputs.dockerfile }} ${{ inputs.context }}
docker save -o vuln-image.tar ${{ inputs.image-name }}:${{ inputs.image-tag }}

- name: Run Trivy vulnerability scanner
id: trivy
if: ${{ inputs.security-scan }}
uses: aquasecurity/trivy-action@0.29.0
uses: aquasecurity/trivy-action@0.33.1
with:
input: vuln-image.tar
image-ref: ${{ inputs.image-name }}:${{ inputs.image-tag }}
format: ${{ (inputs.security-report == 'sarif' && 'sarif') || 'table' }}
ignore-unfixed: true
vuln-type: "os,library"
Expand Down Expand Up @@ -196,3 +183,33 @@ jobs:
${{ steps.read_hadolint.outputs.report }}
```
</details>

- name: Fail build on CRITICAL or HIGH vulnerabilities
if: ${{ inputs.security-scan }}
uses: aquasecurity/trivy-action@0.33.1
Comment thread
jbern0rd marked this conversation as resolved.
with:
image-ref: ${{ inputs.image-name }}:${{ inputs.image-tag }}
format: ${{ (inputs.security-report == 'sarif' && 'sarif') || 'table' }}
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
hide-progress: true
skip-setup-trivy: true
exit-code: 1

- name: Build and push Docker image
Comment thread
jbern0rd marked this conversation as resolved.
Outdated
if: ${{ inputs.push }}
uses: docker/build-push-action@v6
with:
build-args: ${{ inputs.build-args }}
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
platforms: ${{ inputs.platforms }}
push: true
tags: ${{ inputs.image-name }}:${{ inputs.image-tag }}
Comment thread
jbern0rd marked this conversation as resolved.
Outdated

- name: Cleanup files
if: always()
run: |
rm -f trivy.txt trivy-results.sarif
docker image rm -f ${{ inputs.image-name }}:${{ inputs.image-tag }}