-
Notifications
You must be signed in to change notification settings - Fork 3
sign github actions cache blobs #60
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
Draft
crazy-max
wants to merge
4
commits into
main
Choose a base branch
from
gha-cache-sign
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−50
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3b2e1e4
build: add github actions cache and sign blobs
crazy-max 94ca558
bake: add github actions cache and sign blobs
crazy-max aeba44b
add source and workflow origin policy for gha cache verification
crazy-max 6d3e37f
wip: use buildkit test image
crazy-max 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,20 @@ on: | |
| description: "Upload build output GitHub artifact (for local output)" | ||
| required: false | ||
| default: false | ||
| cache: | ||
| type: boolean | ||
| description: "Enable cache to GitHub Actions cache backend" | ||
| required: false | ||
| default: false | ||
| cache-scope: | ||
| type: string | ||
| description: "Which scope cache object belongs to if cache enabled (defaults to target name)" | ||
| required: false | ||
| cache-mode: | ||
| type: string | ||
| description: "Cache layers to export if cache enabled (min or max)" | ||
| required: false | ||
| default: 'min' | ||
| context: | ||
| type: string | ||
| description: "Context to build from in the Git working tree" | ||
|
|
@@ -124,7 +138,7 @@ on: | |
|
|
||
| env: | ||
| BUILDX_VERSION: "v0.30.1" | ||
| BUILDKIT_IMAGE: "moby/buildkit:v0.26.2" | ||
| BUILDKIT_IMAGE: "crazymax/buildkit:6397" | ||
| DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/[email protected]" | ||
| COSIGN_VERSION: "v3.0.2" | ||
| LOCAL_EXPORT_DIR: "/tmp/buildx-output" | ||
|
|
@@ -136,6 +150,7 @@ jobs: | |
| outputs: | ||
| includes: ${{ steps.set.outputs.includes }} | ||
| sign: ${{ steps.set.outputs.sign }} | ||
| privateRepo: ${{ steps.set.outputs.privateRepo }} | ||
| steps: | ||
| - | ||
| name: Install @docker/actions-toolkit | ||
|
|
@@ -247,6 +262,11 @@ jobs: | |
| } | ||
|
|
||
| const privateRepo = GitHub.context.payload.repository?.private ?? false; | ||
| await core.group(`Set privateRepo output`, async () => { | ||
| core.info(`privateRepo: ${privateRepo}`); | ||
| core.setOutput('privateRepo', privateRepo); | ||
| }); | ||
|
|
||
| await core.group(`Set includes output`, async () => { | ||
| let includes = []; | ||
| if (platforms.length === 0) { | ||
|
|
@@ -329,21 +349,123 @@ jobs: | |
| if: ${{ inputs.setup-qemu }} | ||
| with: | ||
| cache-image: false | ||
| - | ||
| name: Expose GitHub Runtime | ||
| uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0 | ||
| - | ||
| name: Set up Docker Buildx | ||
| id: buildx | ||
| uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 | ||
| with: | ||
| version: ${{ env.BUILDX_VERSION }} | ||
| buildkitd-flags: --debug | ||
| driver-opts: image=${{ env.BUILDKIT_IMAGE }} | ||
| cache-binary: false | ||
| buildkitd-flags: --debug | ||
| driver-opts: | | ||
| image=${{ env.BUILDKIT_IMAGE }} | ||
| env.ACTIONS_ID_TOKEN_REQUEST_TOKEN=${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN }} | ||
| env.ACTIONS_ID_TOKEN_REQUEST_URL=${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }} | ||
| buildkitd-config-inline: | | ||
| [cache] | ||
| [cache.gha] | ||
| [cache.gha.sign] | ||
| command = ["ghacache-sign-script.sh"] | ||
| [cache.gha.verify] | ||
| required = true | ||
| [cache.gha.verify.policy] | ||
| timestampThreshold = 1 | ||
| tlogThreshold = ${{ matrix.privateRepo == 'true' && '0' || '1' }} | ||
| subjectAlternativeName = "https://github.com/docker/github-builder-experimental/.github/workflows/bake.yml*" | ||
| githubWorkflowRepository = "docker/github-builder-experimental" | ||
| issuer = "https://token.actions.githubusercontent.com" | ||
| runnerEnvironment = "github-hosted" | ||
| sourceRepositoryURI = "${{ github.server_url }}/${{ github.repository }}" | ||
| sourceRepositoryRef = "${{ github.event_name != 'pull_request' && github.ref || '' }}" | ||
| - | ||
| name: Install Cosign | ||
| if: ${{ needs.prepare.outputs.sign == 'true' || inputs.cache }} | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| INPUT_COSIGN-VERSION: ${{ env.COSIGN_VERSION }} | ||
| INPUT_BUILDER-NAME: ${{ steps.buildx.outputs.name }} | ||
| INPUT_GHA-CACHE-SIGN-SCRIPT: | | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # Create temporary files | ||
| out_file=$(mktemp) | ||
| in_file=$(mktemp) | ||
| trap 'rm -f "$in_file" "$out_file"' EXIT | ||
| cat > "$in_file" | ||
|
|
||
| set -x | ||
|
|
||
| # Sign with cosign | ||
| cosign sign-blob \ | ||
| --yes \ | ||
| --oidc-provider github-actions \ | ||
| --new-bundle-format \ | ||
| --use-signing-config \ | ||
| --bundle "$out_file" \ | ||
| --tlog-upload=${{ matrix.privateRepo == 'false' }} \ | ||
| "$in_file" | ||
|
|
||
| # Output bundle to stdout | ||
| cat "$out_file" | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
|
|
||
| const { Buildx } = require('@docker/actions-toolkit/lib/buildx/buildx'); | ||
| const { Cosign } = require('@docker/actions-toolkit/lib/cosign/cosign'); | ||
| const { Install } = require('@docker/actions-toolkit/lib/cosign/install'); | ||
|
|
||
| const inpCosignVersion = core.getInput('cosign-version'); | ||
| const inpBuilderName = core.getInput('builder-name'); | ||
| const inpGHACacheSignScript = core.getInput('gha-cache-sign-script'); | ||
|
|
||
| const cosignInstall = new Install(); | ||
| const cosignBinPath = await cosignInstall.download({ | ||
| version: core.getInput('cosign-version'), | ||
| ghaNoCache: true, | ||
| skipState: true, | ||
| verifySignature: true | ||
| }); | ||
| const cosignPath = await cosignInstall.install(cosignBinPath); | ||
|
|
||
| const cosign = new Cosign(); | ||
| await cosign.printVersion(); | ||
|
|
||
| const containerName = `${Buildx.containerNamePrefix}${inpBuilderName}0`; | ||
|
|
||
| const ghaCacheSignScriptPath = path.join(os.tmpdir(), `ghacache-sign-script.sh`); | ||
| core.info(`Writing GitHub Actions cache sign script to ${ghaCacheSignScriptPath}`); | ||
| await fs.writeFileSync(ghaCacheSignScriptPath, inpGHACacheSignScript, {mode: 0o700}); | ||
|
|
||
| core.info(`Copying GitHub Actions cache sign script to BuildKit container ${containerName}`); | ||
| await exec.exec('docker', [ | ||
| 'cp', | ||
| ghaCacheSignScriptPath, | ||
| `${containerName}:/usr/bin/ghacache-sign-script.sh` | ||
| ]); | ||
|
|
||
| core.info(`Copying cosign binary to BuildKit container ${containerName}`); | ||
| await exec.exec('docker', [ | ||
| 'cp', | ||
| cosignPath, | ||
| `${containerName}:/usr/bin/cosign` | ||
| ]); | ||
| - | ||
| name: Prepare | ||
| id: prepare | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| INPUT_PLATFORM: ${{ matrix.platform }} | ||
| INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }} | ||
| INPUT_CACHE: ${{ inputs.cache }} | ||
| INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }} | ||
| INPUT_CACHE-MODE: ${{ inputs.cache-mode }} | ||
| INPUT_CONTEXT: ${{ inputs.context }} | ||
| INPUT_FILES: ${{ inputs.files }} | ||
| INPUT_OUTPUT: ${{ inputs.output }} | ||
|
|
@@ -371,6 +493,9 @@ jobs: | |
|
|
||
| const inpLocalExportDir = core.getInput('local-export-dir'); | ||
|
|
||
| const inpCache = core.getBooleanInput('cache'); | ||
| const inpCacheScope = core.getInput('cache-scope'); | ||
| const inpCacheMode = core.getInput('cache-mode'); | ||
| const inpContext = core.getInput('context'); | ||
| const inpFiles = Util.getInputList('files'); | ||
| const inpOutput = core.getInput('output'); | ||
|
|
@@ -468,6 +593,10 @@ jobs: | |
| if (inpPlatform) { | ||
| bakeOverrides.push(`*.platform=${inpPlatform}`); | ||
| } | ||
| if (inpCache) { | ||
| bakeOverrides.push(`*.cache-from=type=gha,scope=${inpCacheScope || target}${platformPairSuffix}`); | ||
| bakeOverrides.push(`*.cache-to=type=gha,scope=${inpCacheScope || target}${platformPairSuffix},mode=${inpCacheMode}`); | ||
| } | ||
| core.info(JSON.stringify(bakeOverrides, null, 2)); | ||
| core.setOutput('overrides', bakeOverrides.join(os.EOL)); | ||
| }); | ||
|
|
@@ -505,28 +634,6 @@ jobs: | |
| const imageDigest = inpMetadata[inpTarget]['containerimage.digest']; | ||
| core.info(imageDigest); | ||
| core.setOutput('digest', imageDigest); | ||
| - | ||
| name: Install Cosign | ||
| if: ${{ needs.prepare.outputs.sign == 'true' }} | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| INPUT_COSIGN-VERSION: ${{ env.COSIGN_VERSION }} | ||
| with: | ||
| script: | | ||
| const { Cosign } = require('@docker/actions-toolkit/lib/cosign/cosign'); | ||
| const { Install } = require('@docker/actions-toolkit/lib/cosign/install'); | ||
|
|
||
| const cosignInstall = new Install(); | ||
| const cosignBinPath = await cosignInstall.download({ | ||
| version: core.getInput('cosign-version'), | ||
| ghaNoCache: true, | ||
| skipState: true, | ||
| verifySignature: true | ||
| }); | ||
| await cosignInstall.install(cosignBinPath); | ||
|
|
||
| const cosign = new Cosign(); | ||
| await cosign.printVersion(); | ||
| - | ||
| name: Signing attestation manifests | ||
| id: signing-attestation-manifests | ||
|
|
||
Oops, something went wrong.
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.
Needs to verify source repo, build repo (same as san) and I think also ref (master branch/tag should not verify PR cache)
Uh oh!
There was an error while loading. Please reload this page.
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.
Added, see aeba44b