oficina / base Public

Run every installed app on the edge channel

Base's instance create now sends channel "edge", so Platform no longer
defaults to stable, which has no release and needs a passkey to promote.
prepare-apps.sh ships the binary (retrying while uploads are rate
limited), promotes it to edge and enables instances. It no longer runs
carlos deploy, which creates a stray instance at the app's own host.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 24d16adb717238358cddb48bd2dc2122c6ec54ef parent c62ee90
5 files changed, +67 −22
  • README.md +2 −2
  • internal/platform/http.go +6 −1
  • internal/platform/http_test.go +1 −1
  • scripts/prepare-apps.sh +22 −8
  • scripts/prepare-apps_test.sh +36 −10
diff --git a/README.md b/README.md
index e1b89c9..8c04c4e 100644
--- a/README.md
+++ b/README.md
@@ -92,8 +92,8 @@ team:
scripts/prepare-apps.sh <account> releases [<version>]
Pass the version (the commit in the binary names) if `releases/` holds more
-than one build; the script refuses to guess. For every app in `internal/catalog/catalog.json` it claims the name, deploys
-the binary to `stable`, and enables instances. Run it again if something
+than one build; the script refuses to guess. For every app in `internal/catalog/catalog.json` it claims the name, ships
+the binary and promotes it to `edge`, and enables instances. Run it again if something
fails halfway; steps already done are skipped. It stops if the account
doesn't list an app but the name can't be claimed, because someone else owns it. You need to be logged in with
`carlos auth login` first.
diff --git a/internal/platform/http.go b/internal/platform/http.go
index ce4a539..b532eef 100644
--- a/internal/platform/http.go
+++ b/internal/platform/http.go
@@ -98,6 +98,10 @@ func (c *httpClient) SetEnv(ctx context.Context, app, environment string, vars m
return err
}
+// Channel is the release channel every instance Base creates follows. Everything
+// runs on edge: there is no stable release, and promoting to it needs a passkey.
+const Channel = "edge"
+
// CreateInstance treats 409 as success only when the record already at host
// is this app's, bound to environment: Platform also answers 409 when host
// collides with another app's reserved name, and that is not an install.
@@ -105,8 +109,9 @@ func (c *httpClient) CreateInstance(ctx context.Context, app, host, environment
body := struct {
Host string `json:"host"`
Environment string `json:"environment"`
+ Channel string `json:"channel"`
Message string `json:"message"`
- }{host, environment, "Base: install"}
+ }{host, environment, Channel, "Base: install"}
status, err := c.do(ctx, "CreateInstance", http.MethodPost, c.appURL(app, "/instances"), c.instanceToken, "", body, nil)
if status != http.StatusConflict {
return err
diff --git a/internal/platform/http_test.go b/internal/platform/http_test.go
index a889a5b..0246e47 100644
--- a/internal/platform/http_test.go
+++ b/internal/platform/http_test.go
@@ -66,7 +66,7 @@ func TestCreateInstanceShape(t *testing.T) {
t.Fatalf("auth %q", s.auth)
}
got, _ := json.Marshal(s.body)
- want := `{"environment":"b-scratchpad","host":"b-scratchpad.example.com","message":"Base: install"}`
+ want := `{"channel":"edge","environment":"b-scratchpad","host":"b-scratchpad.example.com","message":"Base: install"}`
if string(got) != want {
t.Fatalf("body %s", got)
}
diff --git a/scripts/prepare-apps.sh b/scripts/prepare-apps.sh
index bd08b3c..e25610e 100755
--- a/scripts/prepare-apps.sh
+++ b/scripts/prepare-apps.sh
@@ -10,9 +10,10 @@
# app, so an old build can't be promoted by accident.
#
# For each app id in internal/catalog/catalog.json this claims the app name
-# (unless the account already has it), deploys the binary to the stable
-# channel (promotes it if that version is already shipped), and enables
-# instances. It stops at the first failure. Run it again after a failure:
+# (unless the account already has it), ships the binary (unless that version
+# is already shipped), promotes it to the edge channel, and enables
+# instances. It never runs `carlos deploy`, which would also create an
+# instance at the app's own host that Base doesn't use. It stops at the first failure. Run it again after a failure:
# finished steps are skipped.
#
# You need `carlos auth login` first, against the console that hosts <account>.
@@ -79,14 +80,27 @@ for id in $ids; do
# Is this version already shipped? A failed lookup is not "no".
rel_out=$(carlos releases --app "$id" --account "$account")
if printf '%s\n' "$rel_out" | awk -v v="$version" '$1 == v { found = 1 } END { exit !found }'; then
- echo "promote $version to stable (already shipped)"
- carlos promote --app "$id" --account "$account" "$version" stable
+ echo "$version is already shipped"
else
- echo "deploy $version to stable"
- carlos deploy --app "$id" --account "$account" --channel stable \
- --version "$version" "$bin"
+ echo "ship $version"
+ # Uploads are rate limited: wait and retry while the console says so.
+ while :; do
+ if ship_out=$(carlos ship --app "$id" --account "$account" --no-prompt \
+ --version "$version" "$bin" 2>&1); then
+ printf '%s\n' "$ship_out"
+ break
+ fi
+ printf '%s\n' "$ship_out" >&2
+ case $ship_out in
+ *"too many uploads"*) sleep "${PREPARE_APPS_RETRY_SLEEP:-10}" ;;
+ *) exit 1 ;;
+ esac
+ done
fi
+ echo "promote $version to edge"
+ carlos promote --app "$id" --account "$account" --no-prompt "$version" edge
+
echo "enable instances"
carlos instances enable --app "$id" --account "$account"
done
diff --git a/scripts/prepare-apps_test.sh b/scripts/prepare-apps_test.sh
index 329dad7..e3c6a38 100755
--- a/scripts/prepare-apps_test.sh
+++ b/scripts/prepare-apps_test.sh
@@ -15,6 +15,8 @@ fails=0
# FAKE_CREATE_FAIL 1: `apps create` fails
# FAKE_RELEASES what `releases` prints
# FAKE_RELEASES_FAIL 1: `releases` fails
+# FAKE_PROMOTE_FAIL 1: `promote` fails
+# FAKE_SHIP_BUSY n: `ship` says "too many uploads" n times, then works
mkdir "$work/bin"
cat >"$work/bin/carlos" <<'FAKE'
#!/usr/bin/env bash
@@ -30,6 +32,16 @@ case "$1" in
releases)
[ "${FAKE_RELEASES_FAIL:-}" = 1 ] && { echo "console unreachable" >&2; exit 1; }
printf 'VERSION LABEL KIND BUILT TAG\n%s\n' "${FAKE_RELEASES:-}" ;;
+ship)
+ if [ "${FAKE_SHIP_BUSY:-0}" -gt 0 ]; then
+ n=$(cat "$CALLS.busy" 2>/dev/null || echo 0)
+ if [ "$n" -lt "$FAKE_SHIP_BUSY" ]; then
+ echo $((n + 1)) >"$CALLS.busy"
+ echo "too many uploads — try again in 1s" >&2; exit 1
+ fi
+ fi ;;
+promote)
+ [ "${FAKE_PROMOTE_FAIL:-}" = 1 ] && { echo "promote refused" >&2; exit 1; } ;;
esac
exit 0
FAKE
@@ -66,18 +78,20 @@ check() {
}
d=$(newdir)
+export PREPARE_APPS_RETRY_SLEEP=0
-# A failed releases lookup must stop the script before it deploys.
+# Deploy creates a stray instance, so it must never be called, in any case below.
+# A failed releases lookup must stop the script before it ships.
FAKE_APPS=$'welcome x\nscratchpad x' FAKE_RELEASES_FAIL=1 \
- check "releases lookup failure stops before deploy" nonzero '^releases ' '^deploy ' -- acme "$d"
+ check "releases lookup failure stops before ship" nonzero '^releases ' '^(deploy|ship|promote) ' -- acme "$d"
# An app that is not in this account's listing, and cannot be created, stops it.
FAKE_APPS='' FAKE_CREATE_FAIL=1 \
- check "app owned elsewhere stops the script" nonzero '^apps create ' '^(deploy|instances) ' -- acme "$d"
+ check "app owned elsewhere stops the script" nonzero '^apps create ' '^(deploy|ship|instances) ' -- acme "$d"
# A failed apps listing stops it too, without trying to create.
FAKE_LIST_FAIL=1 \
- check "apps listing failure stops before create" nonzero '^apps list ' '^(apps create|deploy) ' -- acme "$d"
+ check "apps listing failure stops before create" nonzero '^apps list ' '^(apps create|deploy|ship) ' -- acme "$d"
# Several builds of one app and no explicit version is ambiguous.
d2=$(newdir)
@@ -88,17 +102,29 @@ grep -qi 'version' "$work/out" || { echo "FAIL ambiguity message should mention
# An explicit version picks the right build out of several.
FAKE_APPS=$'welcome x\nscratchpad x' \
- check "explicit version resolves the ambiguity" zero 'deploy .*--version bbb222 .*welcome-linux-arm64-bbb222' '' -- acme "$d2" bbb222
+ check "explicit version resolves the ambiguity" zero 'ship .*--version bbb222 .*welcome-linux-arm64-bbb222' '^deploy ' -- acme "$d2" bbb222
# Version match is exact: aaa111 listed as a prefix of the shipped version is not shipped.
FAKE_APPS=$'welcome x\nscratchpad x' FAKE_RELEASES='aaa1112 - binary now -' \
- check "releases match is exact, not substring" zero '^deploy ' '^promote ' -- acme "$d"
+ check "releases match is exact, not substring" zero '^ship ' '^deploy ' -- acme "$d"
-# Already shipped: promote, don't deploy. Existing apps: no create.
+# Already shipped: promote to edge, don't ship or deploy. Existing apps: no create.
FAKE_APPS=$'welcome x\nscratchpad x' FAKE_RELEASES='aaa111 - binary now -' \
- check "shipped version is promoted, existing app not created" zero '^promote ' '^(deploy|apps create) ' -- acme "$d"
+ check "shipped version is only promoted, existing app not created" zero '^promote .* aaa111 edge$' '^(deploy|ship|apps create) ' -- acme "$d"
-# Fresh account: create, deploy, enable, for each app.
-check "fresh account creates, deploys, enables" zero 'apps create .*scratchpad' '' -- acme "$d"
+# Fresh account: create, ship, promote to edge, enable, and never deploy or touch stable.
+check "fresh account creates, ships, promotes to edge, enables" zero 'apps create .*scratchpad' '^deploy |stable' -- acme "$d"
+grep -qE '^promote --app scratchpad --account acme --no-prompt aaa111 edge$' "$work/calls" || { echo "FAIL promote should target edge"; fails=$((fails + 1)); }
+grep -qE '^instances enable --app scratchpad' "$work/calls" || { echo "FAIL instances should be enabled"; fails=$((fails + 1)); }
+
+# A failing promote stops the script before instances are enabled.
+FAKE_APPS=$'welcome x\nscratchpad x' FAKE_PROMOTE_FAIL=1 \
+ check "failing promote stops the script" nonzero '^promote ' '^(deploy|instances) ' -- acme "$d"
+
+# "too many uploads" is retried until ship works.
+rm -f "$work/calls.busy"
+FAKE_APPS=$'welcome x\nscratchpad x' FAKE_SHIP_BUSY=2 \
+ check "ship is retried while uploads are rate limited" zero '^promote ' '^deploy ' -- acme "$d"
+[ "$(grep -c '^ship .*welcome' "$work/calls")" -eq 3 ] || { echo "FAIL ship should be tried 3 times"; fails=$((fails + 1)); }
[ $fails -eq 0 ] && echo "all passed" || { echo "$fails failed"; exit 1; }