Build & Sign Container Image using Sigstore Cosign #91
This file contains 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
name: Build & Sign Container Image using Sigstore Cosign | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
schedule: | |
- cron: '30 4 * * *' # every day at 4:30am UTC | |
jobs: | |
build_sign_and_deploy: | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate Image Tag | |
run: echo "IMAGE_TAG=$(date +'%Y-%m-%d').$GITHUB_RUN_ID" >> $GITHUB_ENV | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: "{{defaultContext}}:src" | |
push: true | |
build_args: image_tag=${{ env.IMAGE_TAG }} | |
tags: ${{ vars.IMAGE_FQN }}:${{ env.IMAGE_TAG }},${{ vars.IMAGE_FQN }}:latest | |
- name: Create metadata file | |
env: | |
IMAGE_FQN: ${{ vars.IMAGE_FQN }} | |
run: ./create-metadata-file.sh | |
- name: upload-unsigned-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "unsigned-metadata" | |
path: "./payload.json" | |
if-no-files-found: error | |
- name: Sign metadata file | |
id: sign-step | |
uses: SignPath/[email protected] | |
with: | |
api-token: '${{ secrets.SIGNPATH_API_TOKEN }}' | |
organization-id: '${{ vars.SIGNPATH_ORGANIZATION_ID }}' | |
project-slug: '${{ vars.SIGNPATH_PROJECT_SLUG }}' | |
signing-policy-slug: '${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}' | |
artifact-configuration-slug: '${{ vars.SIGNPATH_ARTIFACT_CONFIGURATION_SLUG }}' | |
github-artifact-name: "unsigned-metadata" | |
output-artifact-directory: "signed-metadata" | |
- name: Attach signature to image | |
run: ./attach-signature.sh | |
- name: Verify signature | |
env: | |
SIGNPATH_API_TOKEN: '${{ secrets.SIGNPATH_API_TOKEN }}' | |
SIGNPATH_ORGANIZATION_ID: '${{ vars.SIGNPATH_ORGANIZATION_ID }}' | |
SIGNING_REQUEST_ID: '${{ steps.sign-step.outputs.signing-request-id }}' | |
run: ./verify.sh |