Skip to content

Commit

Permalink
Sign image using cosign (ko-build#595)
Browse files Browse the repository at this point in the history
Annotate signature with run information
  • Loading branch information
imjasonh authored Feb 13, 2022
1 parent 98ff104 commit 0187841
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
branches: ['main']
workflow_dispatch:

permissions:
contents: read
packages: write
id-token: write

jobs:
image:
runs-on: ubuntu-latest
Expand All @@ -13,13 +18,20 @@ jobs:
- uses: actions/setup-go@v1
with:
go-version: 1.17.x
- uses: sigstore/cosign-installer@v2.0.0

# Build ko from HEAD, set up auth to ghcr.io, build and push an image
# tagged with the SHA.
- name: Build and publish image
# Build ko from HEAD, build and push an image tagged with the commit SHA,
# then keylessly sign it with cosign.
- name: Publish and sign image
env:
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}
COSIGN_EXPERIMENTAL: 'true'
run: |
go build ./
echo "${{ github.token }}" | ./ko login ghcr.io --username "${{ github.actor }}" --password-stdin
./ko build --bare --platform=all -t latest -t ${{ github.sha }} .
img=$(./ko build --bare --platform=all -t latest -t ${{ github.sha }} ./)
echo "built ${img}"
cosign sign ${img} \
-a sha=${{ github.sha }} \
-a run_id=${{ github.run_id }} \
-a run_attempt=${{ github.run_attempt }}

0 comments on commit 0187841

Please sign in to comment.