feat(scripts): publish every package to GHCR with a signed catalogue; reproducible package layers

This commit is contained in:
sam committed 2026-10-06 01:21:15 +11:00
1 parent ee9271e7cf
commit 1fa1b2583c
4 files changed
+122 -2

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
name: publish
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
packages: write
concurrency:
group: publish
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install skopeo
run: sudo apt-get update && sudo apt-get install -y skopeo
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | skopeo login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Publish packages and the signed catalogue
env:
ARCHIPELAGO_CATALOGUE_KEY: ${{ secrets.ARCHIPELAGO_CATALOGUE_KEY }}
run: scripts/publish.sh ghcr.io/${{ github.repository_owner }}/archipelago
+33
View File
@@ -0,0 +1,33 @@
// Command catalogue signs a catalogue layer for archie-core: it reads the
// catalogue JSON on stdin and prints the base64 ed25519 signature over those
// exact bytes. ARCHIPELAGO_CATALOGUE_KEY holds the base64 private key seed.
package main
import (
"crypto/ed25519"
"encoding/base64"
"fmt"
"io"
"os"
"strings"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, "catalogue:", err)
os.Exit(1)
}
}
func run() error {
seed, err := base64.StdEncoding.DecodeString(strings.TrimSpace(os.Getenv("ARCHIPELAGO_CATALOGUE_KEY")))
if err != nil || len(seed) != ed25519.SeedSize {
return fmt.Errorf("ARCHIPELAGO_CATALOGUE_KEY must be a base64 ed25519 seed")
}
layer, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
fmt.Println(base64.StdEncoding.EncodeToString(ed25519.Sign(ed25519.NewKeyFromSeed(seed), layer)))
return nil
}
+6 -2
View File
@@ -25,7 +25,8 @@ fi
# Regular files only: the store refuses directory entries in a layer.
(cd "$work/stage" && find . -type f -printf '%P\n' | LC_ALL=C sort >"$work/files.txt" \
&& tar --owner=0 --group=0 --numeric-owner --no-recursion -czf "$work/layer.tgz" -T "$work/files.txt")
&& tar --format=gnu --owner=0 --group=0 --numeric-owner --mtime=@0 --no-recursion -cf - -T "$work/files.txt" \
| gzip -n >"$work/layer.tgz")
blob() { local d; d=$(sha256sum "$1" | cut -d' ' -f1); cp "$1" "$work/oci/blobs/sha256/$d"; echo "sha256:$d"; }
printf '{}' >"$work/config.json"
@@ -48,5 +49,8 @@ jq -n --arg d "$manifest" --argjson s "$(stat -c %s "$work/manifest.json")" \
'{schemaVersion: 2, manifests: [{mediaType: "application/vnd.oci.image.manifest.v1+json", digest: $d, size: $s}]}' \
>"$work/oci/index.json"
skopeo copy --preserve-digests --dest-tls-verify=false "oci:$work/oci" "docker://$ref" >&2
# Plain HTTP only for a registry on this host, as archie-core fetches it.
tls=true
case "$ref" in localhost[:/]* | 127.0.0.1[:/]* | "[::1]"*) tls=false ;; esac
skopeo copy --preserve-digests --dest-tls-verify=$tls "oci:$work/oci" "docker://$ref" >&2
echo "$manifest"
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Pack every package to REGISTRY and publish the signed catalogue that lists
# them, the one archie-core's Extensions page installs from.
# ARCHIPELAGO_CATALOGUE_KEY=... scripts/publish.sh ghcr.io/samcharles93/archipelago
# Each package is <surface>-<name>:<version>; the catalogue is catalogue:latest.
set -euo pipefail
registry=${1:?registry prefix, e.g. ghcr.io/samcharles93/archipelago}
root=$(cd "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
entries=()
while IFS= read -r descriptor; do
dir=$(dirname "${descriptor#"$root"/}")
surface=$(dirname "$dir")
name=$(basename "$dir")
version=$(yq -r .version "$descriptor")
reference="$registry/$surface-$name"
digest=$("$root/scripts/pack.sh" "$dir" "$reference:$version")
entries+=("$(jq -cn --arg name "$name" --arg surface "$surface" --arg version "$version" \
--arg description "$(yq -r '.description // ""' "$descriptor")" \
--arg reference "$reference" --arg digest "$digest" \
'{name: $name, surface: $surface, version: $version, description: $description, reference: $reference, digest: $digest}')")
done < <(find "$root" -mindepth 3 -maxdepth 3 -name package.yaml -not -path '*/sdk/*' | LC_ALL=C sort)
printf '%s\n' "${entries[@]}" | jq -cs '{packages: .}' | tr -d '\n' >"$work/catalogue.json"
signature=$(go -C "$root" run ./scripts/catalogue <"$work/catalogue.json")
mkdir -p "$work/oci/blobs/sha256"
blob() { local d; d=$(sha256sum "$1" | cut -d' ' -f1); cp "$1" "$work/oci/blobs/sha256/$d"; echo "sha256:$d"; }
printf '{}' >"$work/config.json"
config=$(blob "$work/config.json")
layer=$(blob "$work/catalogue.json")
jq -n --arg config "$config" --arg layer "$layer" --arg signature "$signature" \
--argjson size "$(stat -c %s "$work/catalogue.json")" '{
schemaVersion: 2,
mediaType: "application/vnd.oci.image.manifest.v1+json",
artifactType: "application/vnd.archie.catalogue.v1+json",
config: {mediaType: "application/vnd.oci.empty.v1+json", digest: $config, size: 2},
layers: [{mediaType: "application/vnd.archie.catalogue.v1+json", digest: $layer, size: $size}],
annotations: {"dev.archie.catalogue.signature.v1": $signature}
}' | tr -d '\n' >"$work/manifest.json"
manifest=$(blob "$work/manifest.json")
printf '{"imageLayoutVersion":"1.0.0"}' >"$work/oci/oci-layout"
jq -n --arg d "$manifest" --argjson s "$(stat -c %s "$work/manifest.json")" \
'{schemaVersion: 2, manifests: [{mediaType: "application/vnd.oci.image.manifest.v1+json", digest: $d, size: $s}]}' \
>"$work/oci/index.json"
tls=true
case "$registry" in localhost[:/]* | 127.0.0.1[:/]* | "[::1]"*) tls=false ;; esac
skopeo copy --preserve-digests --dest-tls-verify=$tls "oci:$work/oci" "docker://$registry/catalogue:latest" >&2
echo "published $(jq '.packages | length' "$work/catalogue.json") packages"