Skip to content
Draft
Changes from all commits
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: 53 additions & 0 deletions .github/workflows/bakery-build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
default: "exclude"
required: false
type: string
scan-image:
description: "Scan built images with Trivy [default: false]"
default: false
required: false
type: boolean
scan-fail-on-severity:
description: "Comma-separated severities that fail the scan if found (e.g. CRITICAL). Empty means findings never fail."
default: ""
required: false
type: string
trivy-version:
description: "Trivy release to install (e.g. v0.73.0). 'latest' disables binary caching in setup-trivy."
default: "v0.73.0"
required: false
type: string
retry:
description: "Number of times to retry a failed build"
default: 1
Expand Down Expand Up @@ -309,6 +324,44 @@
--matrix-versions "$MATRIX_VERSIONS" \
--context "$BAKERY_CONTEXT"

- name: Setup trivy
if: ${{ inputs.scan-image }}
uses: aquasecurity/setup-trivy@81e514348e19b6112ce2a7e3ecbafe19c1e1f567 # v0.3.1
with:
version: ${{ inputs.trivy-version }}
cache: true

# After Test: only Test's `docker run` makes every target addressable
# locally. Scanning earlier resolves stale tags and silently scans the
# published image instead of the one just built.
- name: Trivy Scan
if: ${{ inputs.scan-image }}
continue-on-error: true
env:
IMAGE_NAME: ${{ matrix.img.image }}
IMAGE_VERSION: ${{ matrix.img.version }}
NORMALIZED_PLATFORM: ${{ steps.normalize-platform.outputs.platform }}
IMG_DEV: ${{ matrix.img.dev }}
MATRIX_VERSIONS: ${{ inputs.matrix-versions }}
BAKERY_CONTEXT: ${{ inputs.context }}
FAIL_ON_SEVERITY: ${{ inputs.scan-fail-on-severity }}
run: |
if [ "$IMG_DEV" = "true" ]; then
DEV_VERSIONS=only
else
DEV_VERSIONS=exclude
fi
FAIL_FLAGS=()
[[ -n "$FAIL_ON_SEVERITY" ]] && FAIL_FLAGS=(--fail-on-severity "$FAIL_ON_SEVERITY")
bakery trivy scan \
--image-name "^${IMAGE_NAME}$" \
--image-version "$IMAGE_VERSION" \
--image-platform "$NORMALIZED_PLATFORM" \
--dev-versions "$DEV_VERSIONS" \
--matrix-versions "$MATRIX_VERSIONS" \
"${FAIL_FLAGS[@]}" \
--context "$BAKERY_CONTEXT"

build-test-result:
name: Build/Test result
needs: build-test
Expand Down
Loading