-
Notifications
You must be signed in to change notification settings - Fork 12
115 lines (102 loc) · 4.45 KB
/
docker-publish.yml
File metadata and controls
115 lines (102 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Publish Docker Image
on:
push:
branches: [main]
tags: ["v*"]
permissions:
contents: read
packages: write
# id-token: needed by cosign for keyless OIDC signing.
# attestations: needed to publish build attestations to GHCR.
id-token: write
attestations: write
concurrency:
group: docker-publish-${{ github.ref }}
cancel-in-progress: true
jobs:
docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
# ── 1. Checkout (needed for path context so .dockerignore is respected) ──
- name: Checkout
uses: actions/checkout@v6
# ── 2. Multi-platform support ───────────────────────────────────────────
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
# ── 3. Registry authentication ─────────────────────────────────────────
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
if: vars.DOCKERHUB_USERNAME != ''
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# ── 4. Tag & label generation ──────────────────────────────────────────
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
ghcr.io/${{ github.repository }}
name=reqcore/reqcore,enable=${{ vars.DOCKERHUB_USERNAME != '' }}
tags: |
type=edge,branch=main
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
# ── 5. Build & push ────────────────────────────────────────────────────
- name: Build and push
id: build
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: mode=max
sbom: true
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
# ── 6. Keyless cosign signature (Sigstore OIDC) ────────────────────────
# Self-hosters can verify the image they pulled was actually built by
# this workflow with:
# cosign verify ghcr.io/reqcore-inc/reqcore@<digest> \
# --certificate-identity-regexp 'https://github.com/reqcore-inc/reqcore/.github/workflows/docker-publish.yml@.*' \
# --certificate-oidc-issuer 'https://token.actions.githubusercontent.com'
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Sign published images by digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
set -euo pipefail
# cosign signs by immutable digest; the tags only resolve the digest.
# We sign each unique image reference so verification works against
# any tag the user pulled (latest, semver, edge, sha-…).
# `${tag%:*}` (single %) strips only the trailing :tag so registries
# with ports (e.g. registry.local:5000/repo:tag) survive intact.
# Pipe through `sort -u` so the same image+digest is signed once
# even when the tag list contains many aliases.
printf '%s\n' $TAGS \
| awk 'NF' \
| sed -E 's#:[^:/]+$##' \
| sort -u \
| while IFS= read -r image; do
echo "Signing ${image}@${DIGEST}"
cosign sign --yes "${image}@${DIGEST}"
done