-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
32071f7
add job build-and-cache
lisac 352feea
update trivy job to use the previously-built image
lisac 30f2a9c
update anchore scan to use the previously-built image
lisac 8bebaee
update dockle job to use the previously-built image
lisac 47b8168
remove check on disk space
lisac cdc863f
remove debugging around disk space
lisac b8e1fb4
fix outdated documentation link
lisac 409afe0
Update .github/workflows/vulnerability-scans.yml
lisac ec4acfb
rename job: build-and-cache -> build
lisac f93ad60
fix order: check that the cache exists before we try to use it
lisac e615687
move the cache-hit check to earlier in the job
lisac 0f0985e
(lint fix) specify the path associated with the key we want to look up
lisac 8f1f396
oops. need to check out the repo in order to use the Makefile.
lisac b5d6823
skip the trivy and anchore scans (temporarily)
lisac a622e54
modify 'release-build' make command to allow for additional build flags
lisac 1430fd4
simplify. remove logic for caching the buildx layers. reduce the task…
lisac 95a8a18
experiment: don't checkout the repo unless we have to build the docke…
lisac 057ebb1
specify 'fail-on-cache-miss: true' for the subsequent jobs that expec…
lisac 3c71f76
Revert "experiment: don't checkout the repo unless we have to build t…
lisac e7e8072
refactor the steps for building and caching the image into a new comp…
lisac 0c6fcc6
update the build-and-publish to use the new composite action
lisac d6367d6
limit concurrency for the build action
lisac 111fff0
update value to one that is defined
lisac 04c44e2
move concurrency configuration to the job level
lisac d770279
re-try enforcing concurrency limit
lisac 39d9fb5
Merge branch 'main' into lisac/ci-vulnerability-scans-build-image-once
lisac 35353a2
move container registry check into its own job; and run the build-and…
lisac e760275
(debugging) add a sleep, to make more apparent whether multiple insta…
lisac 3a27d6a
fix syntax
lisac 1d970fc
re-try fixing syntax
lisac ba457e9
set id-token to have write permission
lisac 2e5552c
specify the github ref to checkout
lisac 541e272
update description text of the composite action
lisac 73e97a0
revert 2e5552c. ineffective.
lisac 32333f3
fix format - EOF newline
lisac 9fde625
move 'docker load' to the composite action
lisac c58be8b
retrieve the image from cache rather than just checking for a cache hit
lisac ec69330
fix syntax. was missing required property 'shell'
lisac d05c648
debug: if we call 'docker load' from the composite action, will the c…
lisac ca3da45
debug: observe the environment variables describing the version of th…
lisac 3124e7f
debugging - check that we get a cache hit after saving the cache, and…
lisac cf38b58
create composite action for get-commit-hash, copying logic from build…
lisac 82b68ff
update build-and-publish.yml to call the get-commit-hash composite ac…
lisac db0f928
fix concurrency group - github.ref will not be reliable, need to use …
lisac f4c816e
adjust a condition for readability and to be more exact
lisac ee98361
correct concurrency group to use hash instead of github.ref. in vulne…
lisac 1cc95b8
debug: the subsequent jobs may need to explicitly run docker load
lisac 800fe0b
fix syntax
lisac 772ddd4
fix (id for steps need to be unique, within a workflow)
lisac e56d5fa
use existing Makefile command for getting the commit sha
lisac dc57850
remove debugging, update some descriptive properties (name, description)
lisac c211561
restore original code for getting the commit hash
lisac 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,52 @@ | ||
| name: 'Build release candidates' | ||
| description: 'Builds, caches, and loads the docker image' | ||
| inputs: | ||
| app_name: | ||
| description: 'Name of application' | ||
| outputs: | ||
| image_cache_key: | ||
| description: "Cache key for the .tar of the docker image" | ||
| value: ${{ steps.create-image-identifier.outputs.image }} | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
|
|
||
| - name: Create image identifier | ||
| id: create-image-identifier | ||
| 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" | ||
| shell: bash | ||
|
|
||
| - name: Retrieve the image from cache | ||
| id: retrieve-image-from-cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ steps.create-image-identifier.outputs.image }} | ||
|
|
||
| - name: Build and tag Docker image | ||
| if: steps.retrieve-image-from-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| make APP_NAME=${{ inputs.app_name }} release-build | ||
| shell: bash | ||
|
|
||
| - name: Save Docker image | ||
| if: steps.retrieve-image-from-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| docker save ${{ steps.create-image-identifier.outputs.image }} > /tmp/docker-image.tar | ||
| shell: bash | ||
|
|
||
| - name: Cache Docker image | ||
| if: steps.retrieve-image-from-cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: /tmp/docker-image.tar | ||
| key: ${{ steps.create-image-identifier.outputs.image }} | ||
|
|
||
| - name: Load the Docker image | ||
| run: | | ||
| docker load < /tmp/docker-image.tar | ||
| shell: bash |
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ on: | |
| outputs: | ||
| commit_hash: | ||
| description: The SHA that was built | ||
| value: ${{ jobs.get-commit-hash.outputs.commit_hash }} | ||
| value: ${{ jobs.check-image-already-published.outputs.commit_hash }} | ||
| workflow_dispatch: | ||
| inputs: | ||
| app_name: | ||
|
|
@@ -28,41 +28,69 @@ on: | |
| type: string | ||
|
|
||
| jobs: | ||
| get-commit-hash: | ||
| name: Get commit hash | ||
| check-image-already-published: | ||
| name: Check whether the image is already published | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| outputs: | ||
| commit_hash: ${{ steps.get-commit-hash.outputs.commit_hash }} | ||
| is_image_published: ${{ steps.check-image-published.outputs.is_image_published }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.ref }} | ||
|
|
||
| - name: Get commit hash | ||
| id: get-commit-hash | ||
| - id: get-commit-hash | ||
| run: | | ||
| # HEAD should be the same as inputs.ref since we checked out inputs.ref | ||
| COMMIT_HASH=$(git rev-parse HEAD) | ||
| echo "Commit hash: $COMMIT_HASH" | ||
| echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Set up Terraform | ||
| uses: ./.github/actions/setup-terraform | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: ./.github/actions/configure-aws-credentials | ||
| with: | ||
| app_name: ${{ inputs.app_name }} | ||
| environment: shared | ||
|
|
||
| - name: Check if image is already published | ||
| id: check-image-published | ||
| run: | | ||
| is_image_published=$(./bin/is-image-published "${{ inputs.app_name }}" "${{ steps.get-commit-hash.outputs.commit_hash }}") | ||
| echo "Is image published: $is_image_published" | ||
| echo "is_image_published=$is_image_published" >> "$GITHUB_OUTPUT" | ||
|
|
||
| build-and-publish: | ||
| name: Build and publish | ||
| runs-on: ubuntu-latest | ||
| needs: get-commit-hash | ||
| concurrency: build-and-publish-${{ inputs.app_name }}-${{ needs.get-commit-hash.outputs.commit_hash }} | ||
| needs: check-image-already-published | ||
| if: ${{ needs.check-image-already-published.outputs.is_image_published != 'true' }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| concurrency: | ||
| group: build-${{ inputs.app_name }}-${{ needs.check-image-already-published.outputs.commit_hash }} | ||
| cancel-in-progress: false | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.ref }} | ||
|
|
||
| - id: build-release-candidate | ||
| uses: ./.github/actions/build-release-candidate | ||
| with: | ||
| app_name: ${{ inputs.app_name }} | ||
|
|
||
| - name: Set up Terraform | ||
| uses: ./.github/actions/setup-terraform | ||
|
|
||
|
|
@@ -72,17 +100,5 @@ jobs: | |
| app_name: ${{ inputs.app_name }} | ||
| environment: shared | ||
|
|
||
| - name: Check if image is already published | ||
| id: check-image-published | ||
| run: | | ||
| is_image_published=$(./bin/is-image-published "${{ inputs.app_name }}" "${{ needs.get-commit-hash.outputs.commit_hash }}") | ||
| echo "Is image published: $is_image_published" | ||
| echo "is_image_published=$is_image_published" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Build release | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the reason for making this a separate job? |
||
| if: steps.check-image-published.outputs.is_image_published == 'false' | ||
| run: make APP_NAME=${{ inputs.app_name }} release-build | ||
|
|
||
| - name: Publish release | ||
| if: steps.check-image-published.outputs.is_image_published == 'false' | ||
| run: make APP_NAME=${{ inputs.app_name }} release-publish | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this concurrency is important to keep. the concurrency statement later on that uses
github.refwon't work since different github.refs can refer to the same commit hash (e.g. main, origin/main, HEAD, , ) can all be valid refs that point to the same commit hash, so there'd be a race condition where multiple jobs are trying to build the same commit hash but don't realize it since they are referencing the commit via different refs. that's why we have the separate job beforehand that gets the commit hash.