-
Notifications
You must be signed in to change notification settings - Fork 2
Update CI vulnerability workflow to reduce how often the docker image is built #196
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
Changes from 7 commits
32071f7
352feea
30f2a9c
8bebaee
47b8168
cdc863f
b8e1fb4
409afe0
ec4acfb
f93ad60
e615687
0f0985e
8f1f396
b5d6823
a622e54
1430fd4
95a8a18
057ebb1
3c71f76
e7e8072
0c6fcc6
d6367d6
111fff0
04c44e2
d770279
39d9fb5
35353a2
e760275
3a27d6a
1d970fc
ba457e9
2e5552c
541e272
73e97a0
32333f3
9fde625
c58be8b
ec69330
d05c648
ca3da45
3124e7f
cf38b58
82b68ff
db0f928
f4c816e
ee98361
1cc95b8
800fe0b
772ddd4
e56d5fa
dc57850
c211561
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| # GitHub Actions CI workflow that runs vulnerability scans on the application's Docker image | ||
| # to ensure images built are secure before they are deployed. | ||
| # GitHub Actions CI workflow that runs vulnerability scans on the application's | ||
| # Dockerfile or Docker image to ensure images built are secure before they are deployed. | ||
|
|
||
| # The docker image is built once and cached, with that image used by the jobs that | ||
| # require access to the image. | ||
|
|
||
| # NOTE: The workflow isn't able to pass the docker image between jobs, so each builds the image. | ||
| # A future PR will pass the image between the scans to reduce overhead and increase speed | ||
| name: Vulnerability Scans | ||
|
|
||
| on: | ||
|
|
@@ -41,8 +42,64 @@ jobs: | |
| if: always() # Runs even if there is a failure | ||
| run: cat hadolint-results.txt >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| build-and-cache: | ||
lisac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| image: ${{ steps.shared-output.outputs.image }} | ||
|
|
||
| steps: | ||
lisac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@master | ||
lisac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with: | ||
| driver: docker | ||
|
|
||
| - name: Cache Docker layers | ||
| id: cache-buildx | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /tmp/.buildx-cache | ||
| key: ${{ inputs.app_name }}-buildx-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ inputs.app_name }}-buildx- | ||
|
|
||
| - name: Ensure Buildx cache exists | ||
| run: | | ||
| mkdir -p /tmp/.buildx-cache | ||
lisac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Set shared outputs | ||
| id: shared-output | ||
| run: | | ||
| IMAGE_NAME=$(make APP_NAME=${{ inputs.app_name }} release-image-name) | ||
| IMAGE_TAG=$(make release-image-tag) | ||
| echo "image=$IMAGE_NAME:$IMAGE_TAG" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Build and tag Docker image for scanning | ||
| # If there's an exact match in cache, skip build entirely | ||
| if: steps.cache-buildx.outputs.cache-hit != 'true' | ||
| run: | | ||
| make release-build \ | ||
| APP_NAME=${{ inputs.app_name }} \ | ||
| OPTIONAL_BUILD_FLAGS=" \ | ||
| --cache-from=type=local,src=/tmp/.buildx-cache \ | ||
| --cache-to=type=local,dest=/tmp/.buildx-cache" | ||
|
||
|
|
||
| - name: Save Docker image | ||
| if: steps.cache-buildx.outputs.cache-hit != 'true' | ||
| run: | | ||
| docker save ${{ steps.shared-output.outputs.image }} > /tmp/docker-image.tar | ||
|
|
||
| - name: Cache Docker image | ||
| if: steps.cache-buildx.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ inputs.app_name }}-docker-image-${{ github.sha }} | ||
|
|
||
| trivy-scan: | ||
| runs-on: ubuntu-latest | ||
| needs: build-and-cache | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
@@ -59,19 +116,23 @@ jobs: | |
| with: | ||
| files: ${{ inputs.app_name }}/trivy-secret.yaml trivy-secret.yaml | ||
|
|
||
| - name: Build and tag Docker image for scanning | ||
| id: build-image | ||
| - name: Restore cached Docker image | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ inputs.app_name }}-docker-image-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ inputs.app_name }}-docker-image- | ||
|
|
||
| - name: Load cached Docker image | ||
| run: | | ||
| make APP_NAME=${{ inputs.app_name }} release-build | ||
| IMAGE_NAME=$(make APP_NAME=${{ inputs.app_name }} release-image-name) | ||
| IMAGE_TAG=$(make release-image-tag) | ||
| echo "image=$IMAGE_NAME:$IMAGE_TAG" >> "$GITHUB_OUTPUT" | ||
| docker load < /tmp/docker-image.tar | ||
|
|
||
| - name: Run Trivy vulnerability scan | ||
| uses: aquasecurity/trivy-action@master | ||
| with: | ||
| scan-type: image | ||
| image-ref: ${{ steps.build-image.outputs.image }} | ||
| image-ref: ${{ needs.build-and-cache.outputs.image }} | ||
| format: table | ||
| exit-code: 1 | ||
| ignore-unfixed: true | ||
|
|
@@ -88,6 +149,7 @@ jobs: | |
|
|
||
| anchore-scan: | ||
| runs-on: ubuntu-latest | ||
| needs: build-and-cache | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
@@ -99,18 +161,22 @@ jobs: | |
| ${{ inputs.app_name }}/.grype.yml | ||
| .grype.yml | ||
|
|
||
| - name: Build and tag Docker image for scanning | ||
| id: build-image | ||
| - name: Restore cached Docker image | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ inputs.app_name }}-docker-image-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ inputs.app_name }}-docker-image- | ||
|
|
||
| - name: Load cached Docker image | ||
| run: | | ||
| make APP_NAME=${{ inputs.app_name }} release-build | ||
| IMAGE_NAME=$(make APP_NAME=${{ inputs.app_name }} release-image-name) | ||
| IMAGE_TAG=$(make release-image-tag) | ||
| echo "image=$IMAGE_NAME:$IMAGE_TAG" >> "$GITHUB_OUTPUT" | ||
| docker load < /tmp/docker-image.tar | ||
|
|
||
| - name: Run Anchore vulnerability scan | ||
| uses: anchore/scan-action@v3 | ||
| with: | ||
| image: ${{ steps.build-image.outputs.image }} | ||
| image: ${{ needs.build-and-cache.outputs.image }} | ||
| output-format: table | ||
| env: | ||
| GRYPE_CONFIG: ${{ steps.grype-config.outputs.found_file }} | ||
|
|
@@ -121,6 +187,7 @@ jobs: | |
|
|
||
| dockle-scan: | ||
| runs-on: ubuntu-latest | ||
| needs: build-and-cache | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
@@ -132,13 +199,17 @@ jobs: | |
| ${{ inputs.app_name }}/.dockleconfig | ||
| .dockleconfig | ||
|
|
||
| - name: Build and tag Docker image for scanning | ||
| id: build-image | ||
| - name: Restore cached Docker image | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ inputs.app_name }}-docker-image-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ inputs.app_name }}-docker-image- | ||
|
|
||
| - name: Load cached Docker image | ||
| run: | | ||
| make APP_NAME=${{ inputs.app_name }} release-build | ||
| IMAGE_NAME=$(make APP_NAME=${{ inputs.app_name }} release-image-name) | ||
| IMAGE_TAG=$(make release-image-tag) | ||
| echo "image=$IMAGE_NAME:$IMAGE_TAG" >> "$GITHUB_OUTPUT" | ||
| docker load < /tmp/docker-image.tar | ||
|
|
||
| # Dockle doesn't allow you to have an ignore file for the DOCKLE_ACCEPT_FILES | ||
| # variable, this will save the variable in this file to env for Dockle | ||
|
|
@@ -151,7 +222,7 @@ jobs: | |
| - name: Run Dockle container linter | ||
| uses: erzz/dockle-action@v1.3.1 | ||
| with: | ||
| image: ${{ steps.build-image.outputs.image }} | ||
| image: ${{ needs.build-and-cache.outputs.image }} | ||
| exit-code: "1" | ||
| failure-threshold: WARN | ||
| accept-filenames: ${{ env.DOCKLE_ACCEPT_FILES }} | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.