Skip to content

.github/workflows/e2e.container-based.schedule.main.registry-username.yml #25

.github/workflows/e2e.container-based.schedule.main.registry-username.yml

.github/workflows/e2e.container-based.schedule.main.registry-username.yml #25

on:
schedule:
# Twice a month scheduled cron for rebuilding the base builder image.
- cron: "0 3 1,15 * *"
# Verify container-based workflow with the base builder image daily.
- cron: "0 3 * * *"
workflow_dispatch:
inputs:
trigger_build:
description: "Trigger a build"
required: false
default: false
type: boolean
permissions: read-all
concurrency: "e2e.container-based.schedule.main.registry-username"
env:
# TODO: Replace this token.
PAT_TOKEN: ${{ secrets.E2E_CONTAINER_TOKEN }}
GH_TOKEN: ${{ github.token }}
ISSUE_REPOSITORY: slsa-framework/slsa-github-generator
PROVENANCE_NAME: attestation.intoto
IMAGE_REGISTRY: ghcr.io
# NOTE: This pushes a container image to a "package" under the
# slsa-framework GitHub org.
# The image name should be of the form: slsa-framework/example-package.<test name>
IMAGE_NAME: slsa-framework/example-package.e2e.container-based.schedule.main.registry-username.slsa3
REGISTRY_USERNAME: asraa
REGISTRY_PASSWORD: ${{ secrets.E2E_DOCKER_TOKEN }}
jobs:
# Rebuild the base image
base-build:
runs-on: ubuntu-latest
if: inputs.trigger_build || (github.event_name == 'schedule' && github.event.schedule == '0 3 1,15 * *')
permissions:
contents: read # For reading repository contents.
packages: write # For writing container images.
steps:
- name: Checkout the repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6a58db7e0d21ca03e6c44877909e80e45217eed2 # v2.6.0
- name: Authenticate Docker
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@2c0bd771b40637d97bf205cbccdd294a32112176 # v4.5.0
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@44ea916f6c540f9302d50c2b1e5a8dc071f15cdf # v4.1.0
id: build
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
base:
runs-on: ubuntu-latest
if: ${{ !inputs.trigger_build }}
permissions:
contents: read # For reading repository contents.
packages: write # For writing container images.
outputs:
image: ${{ steps.image.outputs.image }}
digest: ${{ steps.image.outputs.digest }}
steps:
- name: Authenticate Docker
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Output image
id: image
run: |
# NOTE: We need to use the image and digest in order to make sure
# that the image we attest has not been modified.
full_image_name="${IMAGE_REGISTRY}/${IMAGE_NAME}"
docker pull "${full_image_name}:main"
repo_digest=$(docker inspect --format='{{index .RepoDigests 0}}' "${full_image_name}:main")
echo "${repo_digest}"
echo "image=${full_image_name}" >> "${GITHUB_OUTPUT}"
echo "digest=${repo_digest#*@}" >> "${GITHUB_OUTPUT}"
# try a docker pull
docker pull "${full_image_name}@${repo_digest#*@}"
build:
permissions:
id-token: write # For signing
actions: read
contents: write # For asset uploads
needs: [base]
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_container-based_slsa3.yml@main
with:
builder-image: ${{ needs.base.outputs.image }}
builder-digest: ${{ needs.base.outputs.digest }}
config-path: ".github/configs-docker/app-config.toml"
provenance-name: attestation.intoto
compile-builder: true
registry-username: ${REGISTRY_USERNAME}
secrets:
registry-password: ${{ secrets.E2E_DOCKER_TOKEN }}
verify:
runs-on: ubuntu-latest
needs: [base, build]
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: ${{ needs.build.outputs.build-outputs-name }}
path: outputs
- name: Get build artifact
id: build
run: |
name=$(find outputs/ -type f | head -1)
cp "${name}" .
echo "name=$(basename "${name}")" >> "${GITHUB_OUTPUT}"
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: ${{ needs.build.outputs.attestations-download-name }}
- name: Get attestation
id: att
env:
FOLDER: ${{ needs.build.outputs.attestations-download-name }}
run: |
name=$(find $FOLDER -type f | head -1)
cp "${name}" .
echo "name=$(basename "${name}")" >> "${GITHUB_OUTPUT}"
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: "1.18"
- env:
BINARY: ${{ steps.build.outputs.name }}
PROVENANCE: ${{ steps.att.outputs.name }}
run: ./.github/workflows/scripts/e2e.container-based.default.verify.sh
if-succeeded:
runs-on: ubuntu-latest
needs: [build, verify]
# NOTE: The workflow is allowed to run for other event types but don't post
# to issues unless it's a schedule event.
if: github.event_name == 'schedule' && needs.build.result == 'success' && needs.verify.result == 'success'
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: ./.github/workflows/scripts/e2e-report-success.sh
if-failed:
runs-on: ubuntu-latest
needs: [build, verify]
# NOTE: The workflow is allowed to run for other event types but don't post
# to issues unless it's a schedule event.
if: always() && github.event_name == 'schedule' && (needs.build.result == 'failure' || needs.verify.result == 'failure')
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: ./.github/workflows/scripts/e2e-report-failure.sh