2024-07-25 02:08:26 +02:00
|
|
|
name: Docker
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
schedule:
|
2024-07-25 21:07:10 +00:00
|
|
|
- cron: "25 0 * * *"
|
2024-07-25 02:08:26 +02:00
|
|
|
push:
|
2024-07-25 21:07:10 +00:00
|
|
|
branches: ["main"]
|
2024-07-25 02:08:26 +02:00
|
|
|
# Publish semver tags as releases.
|
2024-07-25 21:07:10 +00:00
|
|
|
tags: ["v*.*.*"]
|
2024-07-25 02:08:26 +02:00
|
|
|
pull_request:
|
2024-07-25 21:07:10 +00:00
|
|
|
branches: ["main"]
|
2024-11-26 18:18:02 +00:00
|
|
|
workflow_dispatch:
|
2024-07-25 02:08:26 +02:00
|
|
|
|
|
|
|
env:
|
|
|
|
# Use docker.io for Docker Hub if empty
|
|
|
|
REGISTRY: ghcr.io
|
|
|
|
# github.repository as <account>/<repo>
|
|
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
|
|
|
|
jobs:
|
2025-02-26 11:03:28 +01:00
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
id-token: write
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
|
|
|
- name: Test
|
|
|
|
id: test
|
|
|
|
uses: docker/build-push-action@v6
|
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
platforms: linux/amd64
|
2025-02-27 19:10:26 +00:00
|
|
|
cache-from: type=gha,scope=x64
|
2025-02-26 11:03:28 +01:00
|
|
|
pull: true
|
2025-02-27 19:10:26 +00:00
|
|
|
cache-to: type=gha,mode=max,scope=x64
|
2025-02-26 11:03:28 +01:00
|
|
|
target: test
|
|
|
|
|
2024-07-25 02:08:26 +02:00
|
|
|
build:
|
2025-02-26 11:03:28 +01:00
|
|
|
needs: test
|
2024-12-11 00:46:53 +00:00
|
|
|
runs-on: ubuntu-latest
|
2024-07-25 02:08:26 +02:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
id-token: write
|
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
platform: [linux/amd64, linux/arm64]
|
|
|
|
|
2024-07-25 02:08:26 +02:00
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
# Install the cosign tool except on PR
|
|
|
|
- name: Install cosign
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-11-30 12:43:56 +00:00
|
|
|
uses: sigstore/cosign-installer@v3
|
2024-07-25 02:08:26 +02:00
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
# Set up BuildKit Docker container builder
|
2024-07-25 02:08:26 +02:00
|
|
|
- name: Set up Docker Buildx
|
2024-11-30 12:43:56 +00:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2024-07-25 02:08:26 +02:00
|
|
|
|
|
|
|
# Login against a Docker registry except on PR
|
|
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-11-30 12:43:56 +00:00
|
|
|
uses: docker/login-action@v3
|
2024-07-25 02:08:26 +02:00
|
|
|
with:
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
# Extract metadata (tags, labels) for Docker
|
|
|
|
- name: Extract Docker metadata
|
|
|
|
id: meta
|
2024-11-30 12:43:56 +00:00
|
|
|
uses: docker/metadata-action@v5
|
2024-07-25 02:08:26 +02:00
|
|
|
with:
|
2024-07-25 21:07:10 +00:00
|
|
|
tags: |
|
|
|
|
type=ref,event=branch
|
|
|
|
type=ref,event=pr
|
2025-02-27 19:41:54 +00:00
|
|
|
type=semver,pattern={{version}}
|
|
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
|
|
type=semver,pattern={{major}}
|
|
|
|
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
|
2024-07-25 02:08:26 +02:00
|
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
# Build and push Docker image with platform-specific tag
|
|
|
|
- name: Build and push Docker image
|
|
|
|
id: build-and-push
|
2024-11-30 12:43:56 +00:00
|
|
|
uses: docker/build-push-action@v6
|
2024-07-25 02:08:26 +02:00
|
|
|
with:
|
|
|
|
context: .
|
2024-12-11 01:02:59 +00:00
|
|
|
pull: true
|
2024-07-25 02:08:26 +02:00
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
2025-02-27 19:41:54 +00:00
|
|
|
tags: ${{ steps.meta.outputs.tags }}-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
|
2024-07-25 02:08:26 +02:00
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
2025-02-26 11:03:28 +01:00
|
|
|
platforms: ${{ matrix.platform }}
|
2025-02-27 19:10:26 +00:00
|
|
|
cache-from: type=gha,scope=${{ matrix.platform }}
|
|
|
|
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
|
2025-02-27 19:41:54 +00:00
|
|
|
build-args: GITHUB_BUILD=true,VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
|
2025-02-20 20:50:11 +00:00
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
# Sign the platform specific image
|
|
|
|
- name: Sign the published Docker image
|
2025-02-20 20:50:11 +00:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
|
|
env:
|
2025-02-27 19:10:26 +00:00
|
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
2025-02-26 11:03:28 +01:00
|
|
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
2025-02-20 20:50:11 +00:00
|
|
|
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
merge:
|
|
|
|
needs: build
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event_name != 'pull_request'
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
id-token: write
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
|
|
uses: docker/login-action@v3
|
2025-02-20 20:50:11 +00:00
|
|
|
with:
|
2025-02-26 11:03:28 +01:00
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
2024-07-25 02:08:26 +02:00
|
|
|
|
2025-02-26 11:03:28 +01:00
|
|
|
- name: Extract Docker metadata
|
|
|
|
id: meta
|
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
with:
|
|
|
|
tags: |
|
|
|
|
type=ref,event=branch
|
|
|
|
type=ref,event=pr
|
|
|
|
type=semver,pattern={{version}}
|
|
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
|
|
type=semver,pattern={{major}}
|
|
|
|
type=raw,enable=${{ github.ref_type == 'tag' }}, value=latest
|
|
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
|
|
|
|
- name: Install cosign
|
|
|
|
uses: sigstore/cosign-installer@v3
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
|
|
|
- name: Create and push manifest
|
|
|
|
run: |
|
|
|
|
TAGS="${{ steps.meta.outputs.tags }}"
|
|
|
|
for TAG in $TAGS; do
|
|
|
|
# Create manifest list and push it
|
|
|
|
docker buildx imagetools create -t $TAG \
|
2025-02-27 19:10:26 +00:00
|
|
|
$TAG-amd64 \
|
|
|
|
$TAG-arm64
|
2025-02-26 11:03:28 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
- name: Install cosign
|
|
|
|
uses: sigstore/cosign-installer@v3
|
|
|
|
|
|
|
|
- name: Sign the manifest
|
2024-07-25 02:08:26 +02:00
|
|
|
env:
|
|
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
2025-02-26 11:03:28 +01:00
|
|
|
run: |
|
|
|
|
for TAG in $TAGS; do
|
|
|
|
cosign sign --yes $TAG
|
|
|
|
done
|