Repository navigation
555 lines (484 loc) · 20.4 KB
/
Copy pathrelease.yml
File metadata and controls
555 lines (484 loc) · 20.4 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
name: release
# Tag a version to cut a release:
#
# git tag v0.x.0 && git push origin v0.x.0
#
# Builds the static `kr` binary natively for Linux x86_64 and aarch64, attaches
# the archives, checksums and distro packages to the GitHub release, and
# publishes the Homebrew formula and the apt and pacman repositories.
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to build (dry run: no release is published)"
required: false
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
# workflow_dispatch has no tag ref: fall back to the tag input, or v0.0.0.
TAG: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag || 'v0.0.0' }}
jobs:
# kr is no_std with no libc, so the glibc target only names the platform: the
# result is a static binary with no dynamic dependencies. It needs a nightly
# toolchain. Each architecture builds natively on its own runner.
binary:
name: ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Tool versions
run: |
uname -m
openssl version
kubectl version --client 2>&1 | head -3 || true
- name: Unit tests
run: tools/test/unit.sh
- name: Build
run: cargo build --release --locked -p kr
# `kr version` touches nothing but the binary: it proves it starts.
- name: Smoke test
run: |
target/release/kr version
file target/release/kr
ls -l target/release/kr
- name: Package
shell: bash
run: |
name="kr-rs-${TAG}-${{ matrix.target }}"
mkdir -p "$name/systemd"
cp target/release/kr README.md "$name/"
cp tools/systemd/*.service "$name/systemd/"
tar czf "$name.tar.gz" "$name"
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
- uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: |
kr-rs-*.tar.gz
kr-rs-*.tar.gz.sha256
if-no-files-found: error
# Repackaging, not building: the .deb and the pacman package are assembled
# from the archives the build jobs produced.
packages:
name: distro packages
needs: binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: dist
pattern: binary-*
merge-multiple: true
- name: Build the Debian packages
run: |
version="${TAG#v}"
mkdir -p debs
for pair in x86_64-unknown-linux-gnu:amd64 aarch64-unknown-linux-gnu:arm64; do
target="${pair%%:*}"; arch="${pair##*:}"
tar xzf "dist/kr-rs-${TAG}-${target}.tar.gz"
src="kr-rs-${TAG}-${target}"
root="stage/kr-rs-$arch"
install -Dm755 "$src/kr" "$root/usr/bin/kr"
for unit in kr-server kr-agent; do
install -Dm644 "$src/systemd/$unit.service" "$root/usr/lib/systemd/system/$unit.service"
# The archive's units name /usr/local/bin/kr; the package installs to /usr/bin.
sed -i 's#/usr/local/bin/kr#/usr/bin/kr#' "$root/usr/lib/systemd/system/$unit.service"
done
install -Dm644 "$src/README.md" "$root/usr/share/doc/kr-rs/README.md"
# dpkg reports installed size in KiB, and dpkg-deb does not work it
# out on its own.
size=$(du -ks "$root/usr" | cut -f1)
install -d "$root/DEBIAN"
sed -e "s/@VERSION@/$version/" -e "s/@ARCH@/$arch/" -e "s/@INSTALLED_SIZE@/$size/" \
packaging/debian/control > "$root/DEBIAN/control"
if grep -qE '@[A-Z_]+@' "$root/DEBIAN/control"; then
echo "::error::unsubstituted placeholder in packaging/debian/control" >&2
exit 1
fi
dpkg-deb --root-owner-group --build "$root" "debs/kr-rs_${version}-1_${arch}.deb"
done
cd debs && for deb in *.deb; do shasum -a 256 "$deb" > "$deb.sha256"; done
- name: Build the pacman package
run: |
version="${TAG#v}"
mkdir -p pkg
archive="dist/kr-rs-${TAG}-x86_64-unknown-linux-gnu.tar.gz"
dir=build-kr-rs
mkdir -p "$dir"
sed -e "s/@VERSION@/$version/g" \
-e "s/@SHA_LINUX_X86_64@/$(sha256sum "$archive" | cut -d' ' -f1)/" \
packaging/pacman/PKGBUILD > "$dir/PKGBUILD"
if grep -qE '@[A-Z_]+@' "$dir/PKGBUILD"; then
echo "::error::unsubstituted placeholder in PKGBUILD" >&2
exit 1
fi
# The release does not exist yet, so the archive is placed under the
# name the source line gives it: makepkg checksums it instead of
# fetching the URL.
cp "$archive" "$dir/kr-rs-$version-x86_64.tar.gz"
# makepkg refuses to run as root; the tree is handed back to the
# runner's uid afterwards.
docker run --rm -v "$PWD/$dir:/pkg" -e "OWNER=$(id -u):$(id -g)" \
archlinux:base-devel bash -c '
set -eu
useradd -m builder
chown -R builder /pkg
su builder -c "cd /pkg && makepkg --cleanbuild --force --nodeps -p PKGBUILD"
chown -R "$OWNER" /pkg
'
cp "$dir/kr-rs-$version-1-x86_64.pkg.tar.zst" pkg/
(cd pkg && shasum -a 256 "kr-rs-$version-1-x86_64.pkg.tar.zst" \
> "kr-rs-$version-1-x86_64.pkg.tar.zst.sha256")
- name: Check
run: |
version="${TAG#v}"
crate_version=$(awk '/^\[workspace.package\]/{f=1} f && /^version/{gsub(/"/,"",$3); print $3; exit}' Cargo.toml)
if [ "$GITHUB_REF_TYPE" = tag ] && [ "$version" != "$crate_version" ]; then
echo "::error::tag $TAG does not match Cargo.toml version $crate_version" >&2
exit 1
fi
for arch in amd64 arm64; do
deb="debs/kr-rs_${version}-1_${arch}.deb"
dpkg-deb --info "$deb"
dpkg-deb --contents "$deb" | grep -q "./usr/bin/kr"
dpkg-deb --contents "$deb" | grep -q "kr-server.service"
done
docker run --rm -v "$PWD/pkg:/pkg" archlinux:base-devel bash -c "
set -eu
pkg=/pkg/kr-rs-$version-1-x86_64.pkg.tar.zst
bsdtar -xOf \"\$pkg\" .PKGINFO | grep -qx 'pkgname = kr-rs'
bsdtar -xOf \"\$pkg\" .PKGINFO | grep -qx 'pkgver = $version-1'
bsdtar -tf \"\$pkg\" | grep -qx usr/bin/kr
"
- uses: actions/upload-artifact@v4
with:
name: debian-packages
path: |
debs/*.deb
debs/*.deb.sha256
if-no-files-found: error
- uses: actions/upload-artifact@v4
with:
name: pacman-package
path: |
pkg/*.pkg.tar.zst
pkg/*.pkg.tar.zst.sha256
if-no-files-found: error
release:
name: publish release
needs: [binary, packages]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: binary-*
merge-multiple: true
- uses: actions/download-artifact@v4
with:
path: dist
name: debian-packages
- uses: actions/download-artifact@v4
with:
path: dist
name: pacman-package
- id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: true
body: |
`kr` is a Kubernetes distribution in one static binary. It needs Linux 5.10 or newer
(5.9 for pods to survive restarts), cgroup v2 and overlayfs, and root for the full
feature set.
```
sudo kr server --data /var/lib/kr &
export KUBECONFIG=/var/lib/kr/admin.kubeconfig
kubectl get nodes
```
Documentation: https://kr-rs.apiplant.com
## Archives
`kr-rs-${{ github.ref_name }}-x86_64-unknown-linux-gnu.tar.gz` and
`kr-rs-${{ github.ref_name }}-aarch64-unknown-linux-gnu.tar.gz`: the `kr` binary, the
systemd units (`systemd/`, with `KillMode=process`, needed for pods to survive a restart)
and the README.
## Debian package
```
sudo dpkg -i kr-rs_${{ steps.version.outputs.version }}-1_amd64.deb # or _arm64.deb
```
Also in the signed apt repository at `apt.apiplant.com`:
```
curl -sSfL https://apt.apiplant.com/apiplant-archive-keyring.gpg | sudo tee /usr/share/keyrings/apiplant.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/apiplant.gpg] https://apt.apiplant.com stable main" | sudo tee /etc/apt/sources.list.d/apiplant.list > /dev/null
sudo apt update && sudo apt install kr-rs
```
## Arch package
```
sudo pacman -U kr-rs-${{ steps.version.outputs.version }}-1-x86_64.pkg.tar.zst
```
Also in the signed pacman repository at `apiplant.github.io/pacman` (one-time setup):
```
curl -sSfL https://apiplant.github.io/pacman/apiplant.gpg -o /tmp/apiplant.gpg
keyid=$(gpg --show-keys --with-colons /tmp/apiplant.gpg | awk -F: '/^pub:/ { print $5; exit }') && sudo pacman-key --add /tmp/apiplant.gpg && sudo pacman-key --finger "$keyid" && sudo pacman-key --lsign-key "$keyid"
printf '\n[apiplant]\nSigLevel = Required DatabaseOptional\nServer = https://apiplant.github.io/pacman/$arch\n' | sudo tee -a /etc/pacman.conf > /dev/null
sudo pacman -Sy kr-rs
```
## Homebrew (Linux x86_64 and arm64)
```
brew install apiplant/tap/kr-rs
```
Each archive and package has a matching `.sha256` file.
# The formula points at the release archive by URL, so it publishes after
# the release exists. Guarded on its credential: a fork, or this repository
# before the secret is set, skips it instead of failing the run.
homebrew:
name: homebrew tap
needs: release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: dist
pattern: binary-*
merge-multiple: true
- name: Render the formula
if: env.TAP_TOKEN != ''
run: |
version="${GITHUB_REF_NAME#v}"
x86=$(shasum -a 256 "dist/kr-rs-${GITHUB_REF_NAME}-x86_64-unknown-linux-gnu.tar.gz" | cut -d' ' -f1)
arm=$(shasum -a 256 "dist/kr-rs-${GITHUB_REF_NAME}-aarch64-unknown-linux-gnu.tar.gz" | cut -d' ' -f1)
sed -e "s/@VERSION@/$version/g" -e "s/@SHA_LINUX_X86_64@/$x86/" -e "s/@SHA_LINUX_AARCH64@/$arm/" \
packaging/homebrew/kr-rs.rb > /tmp/kr-rs.rb
if grep -qE '@[A-Z_]+@' /tmp/kr-rs.rb; then
echo "::error::unsubstituted placeholder in the formula" >&2
exit 1
fi
- name: Push to apiplant/homebrew-tap
if: env.TAP_TOKEN != ''
run: |
version="${GITHUB_REF_NAME#v}"
git clone --depth 1 \
"https://x-access-token:${TAP_TOKEN}@github.com/apiplant/homebrew-tap.git" tap
mkdir -p tap/Formula
cp /tmp/kr-rs.rb tap/Formula/kr-rs.rb
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/kr-rs.rb
git diff --cached --quiet && exit 0
git commit -m "kr-rs $version"
git push
# The apt repository is cumulative: the new .debs are copied into the pool
# alongside the packages from other apiplant releases, and the indices are
# regenerated over the whole pool.
apt:
name: apt repository
needs: [packages, release]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
# dpkg-scanpackages and apt-ftparchive are Debian's own tools; the runner
# has apt but not dpkg-dev, and a container is cheaper than installing it.
container: debian:bookworm
env:
APT_REPO_TOKEN: ${{ secrets.APT_REPO_TOKEN }}
steps:
- name: Install the archive tools
run: |
apt-get update
apt-get install -y --no-install-recommends dpkg-dev apt-utils gnupg git ca-certificates
- uses: actions/checkout@v4
with:
path: source
- uses: actions/download-artifact@v4
with:
path: debs
name: debian-packages
- name: Import the signing key
if: env.APT_REPO_TOKEN != ''
env:
GPG_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
run: |
if [ -z "$GPG_KEY" ]; then
echo "::error::APT_REPO_TOKEN is set but APT_GPG_PRIVATE_KEY is not" >&2
exit 1
fi
printf '%s\n' "$GPG_KEY" | gpg --batch --import
# The key id is needed explicitly: a CI keyring with one secret key
# still has no default, and an unsigned Release is one apt refuses.
gpg --list-secret-keys --with-colons \
| awk -F: '/^sec:/ { print $5; exit }' > /tmp/keyid
test -s /tmp/keyid
- name: Add the packages to the pool
if: env.APT_REPO_TOKEN != ''
run: |
git clone --depth 1 \
"https://x-access-token:${APT_REPO_TOKEN}@github.com/apiplant/apt.git" repo
# `pool/main/k/kr-rs/` is the layout apt expects: component,
# then the first letter of the source package, then the package.
mkdir -p repo/pool/main/k/kr-rs
cp debs/*.deb repo/pool/main/k/kr-rs/
size=$(du -sm repo/pool | cut -f1)
if [ "$size" -gt 700 ]; then
echo "::warning::the apt pool is ${size}MB; GitHub Pages stops at 1GB." \
"Prune old versions from apiplant/apt or move the pool elsewhere."
fi
- name: Generate the indices
if: env.APT_REPO_TOKEN != ''
working-directory: repo
run: |
for arch in amd64 arm64; do
dir="dists/stable/main/binary-$arch"
mkdir -p "$dir"
# /dev/null as the override file: there is no Debian override
# database here, and dpkg-scanpackages insists on the argument.
dpkg-scanpackages --arch "$arch" pool /dev/null > "$dir/Packages"
gzip -9kf "$dir/Packages"
test -s "$dir/Packages"
done
# Written outside the tree and moved in: apt-ftparchive checksums
# every file under dists/stable, and a Release file it is midway
# through writing is one of them.
apt-ftparchive -c ../source/packaging/apt/apt-ftparchive.conf \
release dists/stable > /tmp/Release
mv /tmp/Release dists/stable/Release
- name: Sign and publish
if: env.APT_REPO_TOKEN != ''
working-directory: repo
env:
GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: |
version="${GITHUB_REF_NAME#v}"
keyid=$(cat /tmp/keyid)
# A passphrase-less key needs no --passphrase, and passing an empty
# one to gpg is an error rather than a no-op. Held in the positional
# parameters rather than an array: this job runs in a container, where
# the step shell is plain sh and `pass=()` is a syntax error.
set --
if [ -n "$GPG_PASSPHRASE" ]; then
set -- --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE"
fi
# Both signatures: InRelease is what apt fetches, Release.gpg is what
# older clients and mirroring tools still look for.
gpg --batch --yes "$@" --local-user "$keyid" \
--clearsign -o dists/stable/InRelease dists/stable/Release
gpg --batch --yes "$@" --local-user "$keyid" \
--detach-sign --armor -o dists/stable/Release.gpg dists/stable/Release
# The keyring users install, dearmored so it can be dropped into
# /usr/share/keyrings and named by `signed-by` as-is.
rm -f apiplant.gpg
gpg --export "$keyid" > apiplant.gpg
# GitHub Pages runs Jekyll otherwise, which would rewrite parts of a
# tree that has to be served byte-for-byte.
touch .nojekyll
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --quiet && exit 0
git commit -m "kr-rs $version"
git push
# The pacman repository is cumulative: the new package files are copied into
# the architecture directory, signed, and added to the repository database
# alongside the packages from other apiplant releases. x86_64 only, matching
# what the `packages` job builds.
pacman:
name: pacman repository
needs: [release, packages]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
container: archlinux:base-devel
env:
PACMAN_REPO_TOKEN: ${{ secrets.PACMAN_REPO_TOKEN }}
steps:
- name: Install the archive tools
run: pacman -Sy --noconfirm --needed git gnupg ca-certificates
- uses: actions/download-artifact@v4
with:
path: dist
name: pacman-package
- name: Import the signing key
if: env.PACMAN_REPO_TOKEN != ''
env:
GPG_KEY: ${{ secrets.PACMAN_GPG_PRIVATE_KEY }}
run: |
if [ -z "$GPG_KEY" ]; then
echo "::error::PACMAN_REPO_TOKEN is set but PACMAN_GPG_PRIVATE_KEY is not" >&2
exit 1
fi
printf '%s\n' "$GPG_KEY" | gpg --batch --import
gpg --list-secret-keys --with-colons \
| awk -F: '/^sec:/ { print $5; exit }' > /tmp/keyid
test -s /tmp/keyid
- name: Add the packages to the pool
if: env.PACMAN_REPO_TOKEN != ''
run: |
git clone --depth 1 \
"https://x-access-token:${PACMAN_REPO_TOKEN}@github.com/apiplant/pacman.git" repo
mkdir -p repo/x86_64
cp dist/*.pkg.tar.zst repo/x86_64/
- name: Sign, index and publish
if: env.PACMAN_REPO_TOKEN != ''
working-directory: repo
env:
GPG_PASSPHRASE: ${{ secrets.PACMAN_GPG_PASSPHRASE }}
run: |
version="${GITHUB_REF_NAME#v}"
keyid=$(cat /tmp/keyid)
sign() {
rm -f "$1.sig"
if [ -n "$GPG_PASSPHRASE" ]; then
gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \
--local-user "$keyid" --detach-sign "$1"
else
gpg --batch --yes --local-user "$keyid" --detach-sign "$1"
fi
}
pkgs=$(printf '%s\n' "$PWD/x86_64"/*.pkg.tar.zst)
for pkg in $pkgs; do
sign "$pkg"
done
repo-add --include-sigs "x86_64/apiplant.db.tar.zst" $pkgs
# repo-add leaves apiplant.db and apiplant.files as symlinks to the
# .tar.zst files. git stores a symlink as its target path, and GitHub
# Pages serves that back as a plain text file — so `pacman -Sy` would
# download the string "apiplant.db.tar.zst" instead of a database.
# Real copies are what gets committed.
for name in apiplant.db apiplant.files; do
cp --remove-destination "x86_64/$name.tar.zst" "x86_64/$name"
done
sign "x86_64/apiplant.db"
sign "x86_64/apiplant.files"
rm -f apiplant.gpg
gpg --armor --export "$keyid" > apiplant.gpg
touch .nojekyll
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --quiet && exit 0
git commit -m "kr-rs $version"
git push