Repository navigation
172 lines (154 loc) · 5.74 KB
/
Copy pathdocker.yml
File metadata and controls
172 lines (154 loc) · 5.74 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Docker
# Images are built only for published releases. The Release workflow calls
# this workflow directly because events created by GITHUB_TOKEN do not start
# another workflow. Manually published releases use the release event.
on:
release:
types: [published]
workflow_call:
inputs:
release_tag:
description: Published release tag to build
required: true
type: string
permissions:
contents: read
packages: write
env:
IMAGE_NAME: metribee
concurrency:
group: docker-release-${{ inputs.release_tag || github.event.release.tag_name }}
cancel-in-progress: false
jobs:
test:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.release.outputs.tag }}
steps:
- name: Verify published release
id: release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name }}
run: |
[[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || exit 1
gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json isDraft |
jq -e '.isDraft == false'
echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: refs/tags/${{ steps.release.outputs.tag }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm db:check-migrations
# Several route tests need the built UI in public/ui, which is not committed.
- run: pnpm build:ui
- run: pnpm test
image:
needs: test
# Build each architecture natively: QEMU can crash Node during pnpm installs.
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
with:
ref: refs/tags/${{ needs.test.outputs.tag }}
- name: Image name (lowercase owner)
id: img
run: echo "name=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/${{ matrix.arch }}
labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
outputs: type=image,name=${{ steps.img.outputs.name }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=metribee-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=metribee-${{ matrix.arch }}
- name: Export image digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
mkdir -p "$RUNNER_TEMP/digests"
touch "$RUNNER_TEMP/digests/${DIGEST#sha256:}"
- uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish:
needs: [test, image]
runs-on: ubuntu-24.04
steps:
- uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Image name (lowercase owner)
id: img
run: echo "name=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check latest stable release
id: latest
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.test.outputs.tag }}
run: |
prerelease="$(gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json isPrerelease --jq .isPrerelease)"
if [ "$prerelease" = true ]; then
echo "enabled=false" >> "$GITHUB_OUTPUT"
exit 0
fi
latest="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name)"
if [ "$latest" = "$RELEASE_TAG" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.img.outputs.name }}
flavor: latest=false
tags: |
type=raw,value=latest,enable=${{ steps.latest.outputs.enabled }}
type=semver,pattern={{version}},value=${{ needs.test.outputs.tag }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.test.outputs.tag }},enable=${{ steps.latest.outputs.enabled }}
- name: Publish and verify both architectures
working-directory: ${{ runner.temp }}/digests
env:
IMAGE: ${{ steps.img.outputs.name }}
METADATA: ${{ steps.meta.outputs.json }}
run: |
mapfile -t tags < <(jq -r '.tags[]' <<< "$METADATA")
args=()
for tag in "${tags[@]}"; do args+=(--tag "$tag"); done
sources=()
for digest in *; do sources+=("$IMAGE@sha256:$digest"); done
docker buildx imagetools create "${args[@]}" "${sources[@]}"
docker buildx imagetools inspect "${tags[0]}" --raw |
jq -e '[.manifests[].platform | select(.os == "linux") | .architecture] | contains(["amd64", "arm64"])'