-
Notifications
You must be signed in to change notification settings - Fork 0
PF-2200 Add Trivy scan support for Docker images in ci-pr-checks-image #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bragesande94
merged 9 commits into
main
from
PF-2200-legg-til-stotte-for-trivy-scan-pa-pr-workflow-for-dockerfile-apps
Jul 20, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0e0c333
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 85f22c8
Merge branch 'main' into PF-2200-legg-til-stotte-for-trivy-scan-pa-pr…
bragesande94 3641fed
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 a9825db
Merge branch 'PF-2200-legg-til-stotte-for-trivy-scan-pa-pr-workflow-f…
bragesande94 c001806
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 56fa388
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 e308798
Apply suggestions from code review
emilarnesen ab6fee3
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 9b4bbb8
PF-2200 Legg til støtte for Trivy scan på PR workflow for Dockerfile …
bragesande94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # Workflow Name: Docker container scan | ||
| # | ||
| # Owner: Digdir Platform team | ||
| # | ||
| # Purpose: | ||
| # This is part of the golden path for PRs towards main branch. The workflow | ||
| # should not normally be used directly, but called from the ci-pr-checks-image | ||
| # workflow, which checks certain things before calling this workflow with the | ||
| # correct parameters. This workflow will build a temporary Docker image | ||
| # based on the Dockerfile found in the 'application-path' directory, or at | ||
| # 'docker/Dockerfile' relative to the repository root when | ||
| # 'add-git-package-token' is true (mirroring | ||
| # ci-docker-build-publish-image.yml, so PR-time scanning builds the same | ||
| # artifact the merge-time publish workflow will build). After building the | ||
| # image, the workflow will run Trivy vulnerability scans. | ||
| # | ||
| # Flow: | ||
| # 1. Set image metadata (name and tag) | ||
| # 2. Checkout repository | ||
| # 3. Build Docker image | ||
| # 4. Run Trivy vulnerability scan on the built image | ||
| # | ||
| # Trigger: | ||
| # Triggered by workflow calls (workflow_call) | ||
| # | ||
| # Inputs: | ||
| # See input section | ||
| # | ||
| # Outputs: | ||
| # None | ||
| # | ||
|
|
||
| name: Docker container scan | ||
|
|
||
| permissions: {} | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| add-git-package-token: | ||
| description: Adds GIT_PACKAGE_TOKEN build argument for Docker | ||
| default: false | ||
| required: false | ||
| type: boolean | ||
| application-path: | ||
| description: Path to the application directory containing the Dockerfile, and to scan with Trivy | ||
| default: "./" | ||
| required: false | ||
| type: string | ||
| docker-build-context: | ||
| description: Docker build context directory (resolves COPY/ADD paths). Defaults to the repository root. | ||
| default: "." | ||
| required: false | ||
| type: string | ||
| image-name: | ||
| description: Name of Docker image | ||
| required: false | ||
| type: string | ||
| trivy-library-disable-scan: | ||
| description: Disable Trivy library scan | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
| trivy-library-ignore-unfixed: | ||
| description: Ignore unfixed vulnerabilities in Trivy library scan | ||
| type: boolean | ||
| required: false | ||
| default: true | ||
| trivy-library-severity: | ||
| description: When to fail the scan with Trivy library vulnerabilities | ||
| type: string | ||
| required: false | ||
| default: 'HIGH,CRITICAL' | ||
| trivy-os-disable-scan: | ||
| description: Disable Trivy OS scan | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
| trivy-os-ignore-unfixed: | ||
| description: Ignore unfixed vulnerabilities in Trivy OS scan | ||
| type: boolean | ||
| required: false | ||
| default: true | ||
| trivy-os-severity: | ||
| description: When to fail the scan with Trivy OS vulnerabilities | ||
| type: string | ||
| required: false | ||
| default: 'CRITICAL' | ||
| trivy-version: | ||
| description: Version of Trivy to use for scanning | ||
| type: string | ||
| required: false | ||
| default: '' | ||
|
|
||
| jobs: | ||
| build-and-scan-image: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Set image metadata | ||
| id: image-metadata | ||
| uses: felleslosninger/github-workflows/.github/actions/image-metadata@main | ||
| with: | ||
| image-name: ${{ inputs.image-name }} | ||
| container-registry: "my-local-registry" | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # pin@v6.0.2 | ||
|
|
||
| - name: Build image | ||
| env: | ||
| APP_PATH: ${{ inputs.application-path }} | ||
| BUILD_CONTEXT: ${{ inputs.docker-build-context }} | ||
| IMAGE_NAME: ${{ steps.image-metadata.outputs.image-name }} | ||
| IMAGE_TAG: ${{ steps.image-metadata.outputs.image-tag }} | ||
| ADD_TOKEN: ${{ inputs.add-git-package-token }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| if [ "$ADD_TOKEN" = "true" ]; then | ||
| docker build --tag "$IMAGE_NAME:$IMAGE_TAG" --file docker/Dockerfile --build-arg GIT_PACKAGE_TOKEN="$GITHUB_TOKEN" "$BUILD_CONTEXT" | ||
| else | ||
| docker build --tag "$IMAGE_NAME:$IMAGE_TAG" --file "$APP_PATH/Dockerfile" "$BUILD_CONTEXT" | ||
| fi | ||
|
|
||
| - name: Run Trivy vulnerability scanner (image) | ||
| uses: felleslosninger/github-workflows/.github/actions/trivy-scan@main | ||
| with: | ||
| image-ref: ${{ steps.image-metadata.outputs.image-name }}:${{ steps.image-metadata.outputs.image-tag }} | ||
| application-path: ${{ inputs.application-path }} | ||
| library-disable-scan: ${{ inputs.trivy-library-disable-scan }} | ||
| library-ignore-unfixed: ${{ inputs.trivy-library-ignore-unfixed }} | ||
| library-severity: ${{ inputs.trivy-library-severity }} | ||
| os-disable-scan: ${{ inputs.trivy-os-disable-scan }} | ||
| os-ignore-unfixed: ${{ inputs.trivy-os-ignore-unfixed }} | ||
| os-severity: ${{ inputs.trivy-os-severity }} | ||
| os-exit-code: "1" | ||
| trivy-version: ${{ inputs.trivy-version }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.