88 lines
3 KiB
YAML
88 lines
3 KiB
YAML
name: DockerBuild
|
|
# 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.
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [ "main" ]
|
|
# Publish semver tags as releases.
|
|
tags: [ 'v*.*.*' ]
|
|
paths-ignore:
|
|
- ".github/**"
|
|
- "README.md"
|
|
pull_request:
|
|
branches: [ "main" ]
|
|
|
|
env:
|
|
# Use docker.io for Docker Hub if empty
|
|
REGISTRY: ghcr.io
|
|
# github.repository as <account>/<repo>
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
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@v4
|
|
# Install the cosign tool except on PR https://github.com/sigstore/cosign-installer
|
|
- name: Install cosign
|
|
if: github.event_name != 'pull_request'
|
|
uses: sigstore/cosign-installer@v3.5.0
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
- name: Setup Docker buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
flavor: latest=true
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: type=sha,format=long
|
|
- name: Build and push Docker image
|
|
id: build-and-push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
# Sign the resulting Docker image digest except on PRs. https://github.com/sigstore/cosign
|
|
- name: Sign image with a key
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
run: |
|
|
images=""
|
|
for tag in ${TAGS}; do
|
|
images+="${tag}@${DIGEST} "
|
|
done
|
|
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images}
|
|
env:
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
|
- name: Sign the images with GitHub OIDC Token
|
|
env:
|
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
images=""
|
|
for tag in ${TAGS}; do
|
|
images+="${tag}@${DIGEST} "
|
|
done
|
|
cosign sign --yes ${images}
|