-
Notifications
You must be signed in to change notification settings - Fork 0
263 lines (240 loc) · 9.46 KB
/
Copy pathdocker.yml
File metadata and controls
263 lines (240 loc) · 9.46 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Docker
on:
push:
branches:
- main
- dev
tags:
- "v*"
workflow_dispatch:
env:
REGISTRY: ghcr.io
UPSTREAM_REPOSITORY: TypeType-Video/TypeType
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: read
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare:
runs-on: [self-hosted, Linux, X64, r730, typetype]
outputs:
build-time: ${{ steps.build-info.outputs.build-time }}
image: ${{ steps.build-info.outputs.image }}
labels: ${{ steps.meta.outputs.labels }}
metadata-json: ${{ steps.meta.outputs.json }}
version: ${{ steps.build-info.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Set up Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.3.14
- name: Resolve build metadata
id: build-info
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
base_version="${GITHUB_REF_NAME#v}"
if [[ ! "$base_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid component release tag: $GITHUB_REF_NAME"
exit 1
fi
gh api "repos/${UPSTREAM_REPOSITORY}/git/ref/tags/v${base_version}" >/dev/null
version="$base_version"
else
upstream_tag="$(gh api "repos/${UPSTREAM_REPOSITORY}/releases/latest" --jq '.tag_name')"
if [[ ! "$upstream_tag" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "Invalid upstream TypeType release tag: $upstream_tag"
exit 1
fi
base_version="${BASH_REMATCH[1]}"
fi
if [[ "$GITHUB_REF_NAME" == "main" ]]; then
version="$base_version"
elif [[ "$GITHUB_REF_NAME" == "dev" ]]; then
base_version="$(bun -e 'import packageJson from "./package.json"; console.log(packageJson.version)')"
if [[ ! "$base_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid development version: $base_version"
exit 1
fi
version="$base_version-dev.$GITHUB_RUN_NUMBER"
elif [[ "$GITHUB_REF" != refs/tags/v* ]]; then
channel="${GITHUB_REF_NAME//[^0-9A-Za-z-]/-}"
version="$base_version-$channel.$GITHUB_RUN_NUMBER"
fi
if [[ "$GITHUB_REF_NAME" == "dev" ]]; then
image="${REGISTRY}/${GITHUB_REPOSITORY,,}-beta"
else
image="${REGISTRY}/${GITHUB_REPOSITORY,,}"
fi
{
echo "image=$image"
echo "version=$version"
echo "build-time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
} >> "$GITHUB_OUTPUT"
- name: Extract metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302
with:
images: ${{ steps.build-info.outputs.image }}
tags: |
type=raw,value=${{ steps.build-info.outputs.version }}
type=sha,prefix=sha-,format=short
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
type=raw,value=latest,enable=${{ github.ref_name == 'dev' }}
type=raw,value=beta,enable=${{ github.ref_name == 'dev' }}
build-platform:
needs: prepare
runs-on: [self-hosted, Linux, X64, r730, typetype]
timeout-minutes: 45
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
arch: amd64
- platform: linux/arm64
arch: arm64
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Isolate Docker credentials
run: echo "DOCKER_CONFIG=$RUNNER_TEMP/docker-config" >> "$GITHUB_ENV"
- name: Log in to GitHub Container Registry
uses: docker/login-action@371161bbe7024a29a25c5e19bfcbc0804fe9ad2c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8
with:
platforms: arm64
cache-image: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c
- name: Build and push platform image
id: build
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a
with:
context: .
build-args: |
BUILD_VERSION=${{ needs.prepare.outputs.version }}
BUILD_REVISION=${{ github.sha }}
BUILD_TIME=${{ needs.prepare.outputs.build-time }}
platforms: ${{ matrix.platform }}
labels: ${{ needs.prepare.outputs.labels }}
outputs: type=image,name=${{ needs.prepare.outputs.image }},push-by-digest=true,name-canonical=true,push=true
provenance: mode=max
sbom: true
cache-from: type=gha,scope=token-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=token-${{ matrix.arch }}
- name: Export digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
digest_dir="$RUNNER_TEMP/token-digests"
rm -rf "$digest_dir"
mkdir -p "$digest_dir"
touch "$digest_dir/${DIGEST#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: token-digest-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/token-digests/*
if-no-files-found: error
retention-days: 1
publish:
needs: [prepare, build-platform]
runs-on: [self-hosted, Linux, X64, r730, typetype]
timeout-minutes: 10
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.manifest.outputs.digest }}
steps:
- name: Isolate Docker credentials
run: echo "DOCKER_CONFIG=$RUNNER_TEMP/docker-config" >> "$GITHUB_ENV"
- name: Prepare digest directory
run: rm -rf "$RUNNER_TEMP/token-digests"
- name: Download digests
uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/token-digests
pattern: token-digest-*-${{ github.run_id }}-${{ github.run_attempt }}
merge-multiple: true
- name: Log in to GitHub Container Registry
uses: docker/login-action@371161bbe7024a29a25c5e19bfcbc0804fe9ad2c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c
- name: Publish manifest list
id: manifest
env:
DIGEST_DIR: ${{ runner.temp }}/token-digests
IMAGE: ${{ needs.prepare.outputs.image }}
METADATA_JSON: ${{ needs.prepare.outputs.metadata-json }}
run: |
mapfile -t digests < <(find "$DIGEST_DIR" -maxdepth 1 -type f -printf '%f\n' | sort)
if [[ "${#digests[@]}" -ne 2 ]]; then
echo "Expected two platform digests, found ${#digests[@]}"
exit 1
fi
mapfile -t tags < <(jq -r '.tags[]' <<< "$METADATA_JSON")
tag_args=()
for tag in "${tags[@]}"; do tag_args+=(--tag "$tag"); done
source_args=()
for digest in "${digests[@]}"; do source_args+=("$IMAGE@sha256:$digest"); done
docker buildx imagetools create "${tag_args[@]}" "${source_args[@]}"
manifest_json="$(docker buildx imagetools inspect "${tags[0]}" --format '{{json .Manifest}}')"
digest="$(jq -r '.digest' <<< "$manifest_json")"
if [[ "$digest" != sha256:* ]]; then
echo "Published manifest has no valid digest"
exit 1
fi
echo "digest=$digest" >> "$GITHUB_OUTPUT"
notify-orchestrator:
needs: [prepare, publish]
if: github.ref_name == 'dev' || github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v')
runs-on: [self-hosted, Linux, X64, r730, typetype]
permissions:
contents: read
env:
GH_TOKEN: ${{ secrets.TYPETYPE_ORCHESTRATOR_TOKEN }}
steps:
- name: Send image digest
env:
DIGEST: ${{ needs.publish.outputs.digest }}
IMAGE: ${{ needs.prepare.outputs.image }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
if [[ "$GITHUB_REF_NAME" == "dev" ]]; then channel="beta"; else channel="stable"; fi
jq -n \
--arg channel "$channel" \
--arg component "token" \
--arg digest "$DIGEST" \
--arg image "$IMAGE" \
--arg revision "$GITHUB_SHA" \
--arg version "$VERSION" \
'{event_type:"component-image",client_payload:{channel:$channel,component:$component,digest:$digest,image:$image,revision:$revision,version:$version}}' \
| gh api --method POST repos/TypeType-Video/TypeType/dispatches --input -