Merge pull request #146 from vipyrsec/better-match-info #160
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: Container Build and Push | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge with sigstore/fulcio. | |
id-token: write | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-push: | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge with sigstore/fulcio. | |
id-token: write | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/amd64 | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Install cosign | |
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0 | |
- name: Setup Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 | |
with: | |
install: true | |
cleanup: false | |
platforms: ${{ matrix.platform }} | |
config-inline: | | |
[worker.oci] | |
gc = true | |
gckeepstorage = 10_000 # 10 GB | |
[[worker.oci.gcpolicy]] | |
all = true | |
keepBytes = 10_000_000_000 # 10 GB | |
keepDuration = 7_776_000 # 90 days | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: docker_meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=edge | |
# FIXME: Remove explicit `latest` tag once we start tagging releases | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=ref,event=tag | |
type=sha,format=long | |
- name: Inject Docker Build(x|Kit) cache mounts | |
uses: sid-maddy/buildkit-cache-dance/inject@b85212de35ab5f2a6f5cf0efcf9ffb3806dc56e7 # v1.0.0 | |
with: | |
cache-mounts: | | |
cargo-registry,/usr/local/cargo/registry | |
rust-target-release,/app/target | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
key: rust-buildkit-cache-${{ matrix.platform }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }} | |
restore-keys: | | |
rust-buildkit-cache-${{ matrix.platform }}- | |
- name: Build and push Docker image | |
id: docker_build_push | |
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 # v6.5.0 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
cache-from: type=gha,scope=${{ matrix.platform }} | |
cache-to: type=gha,mode=max,scope=${{ matrix.platform }} | |
file: Containerfile | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
platforms: ${{ matrix.platform }} | |
push: ${{ github.ref == 'refs/heads/main' || startswith(github.event.ref, 'refs/tags/v') }} | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
- name: Extract Docker Build(x|Kit) cache mounts | |
uses: sid-maddy/buildkit-cache-dance/extract@b85212de35ab5f2a6f5cf0efcf9ffb3806dc56e7 # v1.0.0 | |
with: | |
cache-mounts: | | |
cargo-registry,/usr/local/cargo/registry | |
rust-target-release,/app/target | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
key: rust-buildkit-cache-${{ matrix.platform }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }} | |
# Sign the resulting Docker image digest. | |
# This will only write to the public Rekor transparency log when the Docker repository is public to avoid leaking | |
# data. If you would like to publish transparency data even for private images, pass --force to cosign below. | |
# https://github.com/sigstore/cosign | |
- name: Sign the published Docker image | |
if: ${{ github.ref == 'refs/heads/main' || startswith(github.event.ref, 'refs/tags/v') }} | |
shell: bash | |
# This step uses the identity token to provision an ephemeral certificate against the sigstore community Fulcio | |
# instance. | |
run: cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.docker_build_push.outputs.digest }} | |
- name: Export digest | |
if: ${{ github.ref == 'refs/heads/main' || startswith(github.event.ref, 'refs/tags/v') }} | |
run: | | |
mkdir -p /tmp/digests | |
digest='${{ steps.docker_build_push.outputs.digest }}' | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
if: ${{ github.ref == 'refs/heads/main' || startswith(github.event.ref, 'refs/tags/v') }} | |
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 | |
with: | |
if-no-files-found: error | |
name: digests | |
path: /tmp/digests/* | |
retention-days: 1 | |
merge: | |
if: ${{ github.ref == 'refs/heads/main' || startswith(github.event.ref, 'refs/tags/v') }} | |
needs: | |
- build-push | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
with: | |
name: digests | |
path: /tmp/digests | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: docker_meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=edge | |
# FIXME: Remove explicit `latest` tag once we start tagging releases | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=ref,event=tag | |
type=sha,format=long | |
- name: Create manifest list and push | |
shell: bash | |
working-directory: /tmp/digests | |
run: > | |
docker buildx imagetools create \ | |
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}") \ | |
$(printf ' ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) | |
- name: Inspect image | |
shell: bash | |
run: >- | |
docker buildx imagetools inspect \ | |
'${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.docker_meta.outputs.version }}' |