-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (106 loc) · 3.89 KB
/
Copy pathrelease-container.yml
File metadata and controls
118 lines (106 loc) · 3.89 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
116
117
118
name: Release Container
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Manual tag to publish (e.g. v1.2.3). Leave blank to use the commit SHA only."
required: false
type: string
permissions:
contents: read
packages: write
id-token: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.event.release.tag_name, 'v0.') }}
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }}
type=sha,format=long
labels: |
org.opencontainers.image.title=SampleDB
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.licenses=MIT
- name: Build and push (multi-arch)
id: build
uses: docker/build-push-action@v7
with:
build-args: |
APP_BUILD_ID=${{ github.sha }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=sampledb
cache-to: type=gha,mode=max,scope=sampledb
provenance: mode=max
sbom: true
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Sign image with cosign (keyless / OIDC)
env:
DIGEST: ${{ steps.build.outputs.digest }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
# Sign by digest so every tag for this build inherits a single signature.
# Keyless signing uses the GitHub OIDC token (id-token: write above) and
# records the signature in the public Rekor transparency log.
while IFS= read -r tag; do
[ -z "$tag" ] && continue
cosign sign --yes "${tag}@${DIGEST}"
done <<< "${TAGS}"
- name: Summary
run: |
{
echo "### Image published"
echo ""
echo "**Digest:** \`${{ steps.build.outputs.digest }}\`"
echo ""
echo "**Platforms:** linux/amd64, linux/arm64"
echo ""
echo "**Signed:** keyless (Sigstore / Rekor)"
echo ""
echo "**Tags:**"
echo '```'
echo "${{ steps.meta.outputs.tags }}"
echo '```'
echo ""
echo "Verify locally with:"
echo '```bash'
echo "cosign verify \\"
echo " --certificate-identity-regexp 'https://github.com/${{ github.repository }}/.github/workflows/release-container.yml@.*' \\"
echo " --certificate-oidc-issuer https://token.actions.githubusercontent.com \\"
echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"