Test recipes locally with Docker Compose (#1)

scripts/local-test.sh starts a recipe the way Cottage runs it (parameters filled in, owned
volumes without copy-up, default limits, no-new-privileges, localhost only), waits for its
health path to answer 200 and cleans up. CI runs it on every pull request, forks included,
alongside Cottage's own checks, which now live under .github/.

The README explains the recipe format and rules for contributors.
This commit is contained in:
michael authored and GitHub committed 2026-11-21 14:03:35 -05:00
1 parent a0d992022d
commit 193936ab2e
9 files changed
+215 -64

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# Smoke test one recipe against a harbord: upload → deploy → wait for running →
# HTTP check of health_path through the node's router (real runtime only) → delete.
#
# HARBOR_URL=http://127.0.0.1:7700 HARBOR_TOKEN=hbr_... .github/platform-check.sh apps/vaultwarden
#
# HEALTH_BASE (optional) is how this machine reaches pod hostnames, e.g. https://%s
# where %s is replaced with the pod's domain. Without it the HTTP check is skipped,
# which is what the fake runtime needs.
set -eu
dir=$(cd "${1:?recipe directory}" && pwd)
: "${HARBOR_URL:?}" "${HARBOR_TOKEN:?}"
api() { curl -fsS -H "Authorization: Bearer $HARBOR_TOKEN" "$@"; }
json() { python3 -c "import sys,json; d=json.load(sys.stdin); print($1)"; }
slug=$(basename "$dir")
api -X POST -H 'Content-Type: application/yaml' --data-binary @"$dir/template.yml" "$HARBOR_URL/v1/templates" >/dev/null
version=$(api "$HARBOR_URL/v1/templates?slug=$slug" | json "sorted(d['data'], key=lambda t: t['created_at'])[-1]['version']")
health=$(api "$HARBOR_URL/v1/templates/$slug?version=$version" | json "d.get('health_path','/')")
ref="smoke-$slug-$$"
pod=$(api -X POST -H "Idempotency-Key: $ref" -d "{\"slug\":\"smoke-$$\",\"external_ref\":\"$ref\",\"template\":\"$slug\",\"template_version\":\"$version\"}" \
"$HARBOR_URL/v1/pods" | json "d['pod']['id']")
trap 'api -X DELETE "$HARBOR_URL/v1/pods/$pod?purge=true" >/dev/null || true' EXIT
for _ in $(seq 1 60); do
status=$(api "$HARBOR_URL/v1/pods/$pod" | json "d['status']")
[ "$status" = running ] && break
[ "$status" = failed ] && { echo "$slug: pod failed"; exit 1; }
sleep 2
done
[ "$status" = running ] || { echo "$slug: not running after 120 s (status $status)"; exit 1; }
if [ -n "${HEALTH_BASE:-}" ]; then
domain=$(api "$HARBOR_URL/v1/pods/$pod" | json "d['domain']")
# shellcheck disable=SC2059
url="$(printf "$HEALTH_BASE" "$domain")$health"
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 120 --retry 20 --retry-delay 3 --retry-all-errors "$url")
[ "$code" = 200 ] || { echo "$slug: $url returned $code"; exit 1; }
fi
echo "$slug@$version: ok"
+1
View File
@@ -0,0 +1 @@
e6c8b85797a9068c211702afa30a9b8bba082f66
+34 -24
View File
@@ -1,42 +1,52 @@
name: validate
name: Check recipes
on: [push, pull_request]
permissions: { contents: read }
jobs:
fake-runtime:
# The same test contributors run locally: every recipe with Docker Compose, until its
# health path answers 200. Runs on every pull request, forks included.
compose:
name: Docker Compose test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test every recipe
run: |
for app in apps/*/; do scripts/local-test.sh "$app"; done
# Cottage's own checks: the recipe is accepted by the platform and runs its full lifecycle.
# The platform isn't public, so this needs the PLATFORM_KEY secret (a read-only deploy key)
# and is skipped for pull requests from forks; a maintainer runs it before merging.
platform:
name: Cottage checks
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: "1.26" }
# Harbor is private: a read-only deploy key is needed (secret HARBOR_DEPLOY_KEY).
- name: Build harbord at the pinned commit
env: { HARBOR_DEPLOY_KEY: "${{ secrets.HARBOR_DEPLOY_KEY }}" }
- name: Build the platform at the pinned commit
env: { PLATFORM_KEY: "${{ secrets.HARBOR_DEPLOY_KEY }}" }
run: |
if [ -z "$HARBOR_DEPLOY_KEY" ]; then
if [ "${{ github.event.pull_request.head.repo.full_name || github.repository }}" != "${{ github.repository }}" ]; then
echo "::notice::Pull requests from forks can't build private Harbor, so the recipe tests are skipped. A maintainer runs them before merging."
echo "skip=true" >> "$GITHUB_ENV"
exit 0
fi
echo "::error::Add the HARBOR_DEPLOY_KEY secret (a read-only deploy key on cottage-host/harbor) to run the recipe smoke tests."
if [ -z "$PLATFORM_KEY" ]; then
echo "::error::The HARBOR_DEPLOY_KEY secret is missing."
exit 1
fi
mkdir -p ~/.ssh && printf '%s\n' "$HARBOR_DEPLOY_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts
git clone -q [email protected]:cottage-host/harbor.git /tmp/harbor
git -C /tmp/harbor checkout -q "$(cat harbor.ref)"
(cd /tmp/harbor && go build -o /tmp/harbord ./cmd/harbord)
# harbord runs as root, as on a node: it hands volume directories to the containers'
# non-root users (x-harbor.volumes uid/gid), which needs root or CAP_CHOWN.
# Capacity is fixed so the runner's disk size can't refuse a pod.
- name: Smoke test every recipe
if: env.skip != 'true'
mkdir -p ~/.ssh && printf '%s\n' "$PLATFORM_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
git clone -q [email protected]:cottage-host/harbor.git /tmp/platform
git -C /tmp/platform checkout -q "$(cat .github/platform.ref)"
(cd /tmp/platform && go build -o /tmp/harbord ./cmd/harbord)
rm -f ~/.ssh/id_ed25519
# Runs as root, as on a server: it hands volume directories to the containers'
# non-root users, which needs root or CAP_CHOWN. Capacity is fixed so the runner's
# disk size can't refuse a recipe.
- name: Check every recipe
run: |
export HARBOR_DATA_DIR=$RUNNER_TEMP/h HARBOR_RUNTIME=fake HARBOR_BASE_DOMAIN=pods.test
export HARBOR_CAPACITY_CPU_MILLIS=8000 HARBOR_CAPACITY_MEMORY_MB=8192 HARBOR_CAPACITY_STORAGE_MB=65536
# The runner's sudo ignores -E, so pass Harbor's settings explicitly.
# the runner's sudo ignores -E, so pass the settings explicitly
H="HARBOR_DATA_DIR=$HARBOR_DATA_DIR HARBOR_RUNTIME=$HARBOR_RUNTIME HARBOR_BASE_DOMAIN=$HARBOR_BASE_DOMAIN HARBOR_CAPACITY_CPU_MILLIS=$HARBOR_CAPACITY_CPU_MILLIS HARBOR_CAPACITY_MEMORY_MB=$HARBOR_CAPACITY_MEMORY_MB HARBOR_CAPACITY_STORAGE_MB=$HARBOR_CAPACITY_STORAGE_MB"
export HARBOR_TOKEN=$(sudo env $H /tmp/harbord token create ci | grep -o 'hbr_[A-Za-z0-9_-]*')
sudo env $H /tmp/harbord serve & sleep 2
export HARBOR_URL=http://127.0.0.1:7700
for t in apps/*/tests/smoke.sh; do sh "$t"; done
for app in apps/*/; do sh .github/platform-check.sh "$app"; done