Skip to content

Docker Image BuildX CI and Publish #293

Docker Image BuildX CI and Publish

Docker Image BuildX CI and Publish #293

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Docker Image BuildX CI and Publish
on:
schedule:
- cron: "19 16 * * *"
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]
with:
cosign-release: 'v2.4.2'
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 #v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ghcr.io
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata (isolated-vm)
id: meta-isolated-vm
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ghcr.io/smarter-project/hydra/isolated-vm
flavor: |
latest=auto
suffix=
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 #v2.2.1
with:
platforms: "linux/amd64,linux/arm64"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image (isolated-vm)
id: build-and-push-isolated-vm
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 #v3
with:
platforms: "linux/amd64,linux/arm64"
context: src/isolated-vm
build-args: ""
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-isolated-vm.outputs.tags }}
labels: ${{ steps.meta-isolated-vm.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# 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 (isolated-vm)
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta-isolated-vm.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push-isolated-vm.outputs.digest }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata (add-crismux)
id: meta-add-crismux
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ghcr.io/smarter-project/hydra/crismux
flavor: |
latest=auto
suffix=
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 #v2.2.1
with:
platforms: "linux/amd64,linux/arm64"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image (add-crismux)
id: build-and-push-add-crismux
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 #v3
with:
platforms: "linux/amd64,linux/arm64"
context: src/add-crismux
build-args: ""
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-add-crismux.outputs.tags }}
labels: ${{ steps.meta-add-crismux.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# 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 (add-crismux)
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta-add-xrismux.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push-add-xrismux.outputs.digest }}