oficina / base Public

Add release, operator script and README

Add scripts/prepare-apps.sh (claim, deploy, enable for each catalogue app,
safe to re-run), the README, and docs/live-check.md for the by-hand check.
Make the gate pass: declare the rastrillo tool in go.mod so budget runs,
give each test package a budget TestMain, and silence ST1005 on two
user-facing install errors. Add BASE_INSTANCE_KEY to .env.local.example.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev a2c9ff213976c2e1bcac9a47e658ad1c8ad6fc07 parent 75b4495
16 files changed, +305 −2
  • .env.local.example +3 −0
  • README.md +113 −0
  • docs/copy-pending.md +1 −0
  • docs/live-check.md +37 −0
  • go.mod +8 −0
  • go.sum +4 −0
  • internal/appboot/main_test.go +10 −0
  • internal/catalog/main_test.go +10 −0
  • internal/config/main_test.go +10 −0
  • internal/install/install.go +3 −0
  • internal/install/install_test.go +2 −1
  • internal/look/main_test.go +10 −0
  • internal/platform/main_test.go +10 −0
  • internal/store/store_test.go +2 −1
  • internal/web/main_test.go +10 −0
  • scripts/prepare-apps.sh +72 −0
diff --git a/.env.local.example b/.env.local.example
index 56abd23..f41012d 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -5,6 +5,9 @@ BASE_ORIGIN=https://base.example.com
BASE_NAME=Acme
BASE_SLUG=acme
BASE_OWNER=owner@example.com
+# Required. A long random secret that seals sign-in state; keep it stable.
+# openssl rand -base64 32
+BASE_INSTANCE_KEY=
BASE_APPS_DOMAIN=apps.example.com
BASE_TIMEZONE=Europe/London
BASE_PLATFORM_CONSOLE=https://console.example.com
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8114016
--- /dev/null
+++ b/README.md
@@ -0,0 +1,113 @@
+# Base
+
+Base is the front door for a small business. Your team signs in with their
+work email, you invite the people you work with, and you install apps from a
+Store. Base runs on a CARLOS Platform account, and each app you install runs
+as its own instance on that account.
+
+Base only says who someone is. Each app decides what that person may do.
+
+## Run it on your machine
+
+Copy `.env.local.example` to `.env.local` and fill it in, then:
+
+ ./run.sh
+
+It builds Base and listens on `127.0.0.1:8830` (change it with `BASE_ADDR`,
+which must stay on `127.0.0.1`). The database is `base.db` next to the script.
+
+Sign-in assertions only work between `https://` hostnames, and the verifier
+rejects IP addresses, so `http://127.0.0.1:8830` is no good as `BASE_ORIGIN`
+once you install an app. Share the port and use the origin it prints:
+
+ carlos devbox share --port 8830
+
+Put that origin in `BASE_ORIGIN`, and set `BASE_ALLOW_LOGGED_MAIL=1` only if
+the origin is on loopback and you want sign-in links printed to the log
+instead of emailed.
+
+## Settings
+
+Everything is an environment variable. `BASE_ORIGIN`, `BASE_OWNER` and
+`BASE_INSTANCE_KEY` are required.
+
+- `BASE_ORIGIN` is Base's public address: `https://` and a hostname, no path.
+ (`http://localhost` is allowed for local runs.)
+- `BASE_OWNER` is the email address of the owner, who can invite everyone else.
+- `BASE_INSTANCE_KEY` is a long random secret that seals sign-in state.
+ Keep it and don't change it: changing it breaks sign-in links in flight.
+ `openssl rand -base64 32` makes a good one.
+- `BASE_NAME` is what your team calls Base, such as "Acme" (default `Base`).
+- `BASE_SLUG` names the apps' hostnames: `<slug>-<appid>.<BASE_APPS_DOMAIN>`.
+ Lowercase letters, digits and `-`, at most 19 characters (default `base`).
+- `BASE_TIMEZONE` is where dates are shown (default `Europe/London`).
+- `BASE_ASSERTION_KEY` is Base's signing key, base64 of rastrillo's
+ `crypto.MarshalKeypair`. Without it, no one can open an installed app.
+ Keep it stable across restarts.
+- `BASE_ALLOW_LOGGED_MAIL=1` prints sign-in links instead of sending them.
+ Local only; Base refuses it on a non-loopback origin.
+
+To install apps, Base also needs to reach the Platform. Without these five and
+`BASE_ASSERTION_KEY`, it still runs and logs that installs are off.
+
+- `BASE_PLATFORM_CONSOLE` is the console's address.
+- `BASE_PLATFORM_ACCOUNT` is the account Base runs on.
+- `BASE_PLATFORM_INSTANCE_TOKEN` is a service credential with the `instance`
+ role.
+- `BASE_PLATFORM_OPERATE_TOKEN` is a second one with the `operate` role.
+ A credential holds one role, so you need two. Both are account-wide:
+ create them without `--app`.
+- `BASE_APPS_DOMAIN` is the domain apps live under.
+
+Outside loopback, Base sends mail through `CARLOS_SMTP_HOST` and
+`CARLOS_SMTP_FROM`.
+
+## Deploy
+
+Build the binaries, then deploy Base to a channel:
+
+ make release
+ carlos deploy --app base --channel edge releases/base-linux-arm64-<version>
+
+`make release` refuses to build from a dirty tree. It builds `base`,
+`scratchpad` and `welcome` for linux/arm64 into `releases/`, named with the
+commit. Set the `BASE_*` settings with `carlos env set --app base KEY=value`.
+
+## Before anyone can install an app
+
+This is a one-time job for whoever runs the account, and you repeat it when
+you add an app to the catalogue. The Platform needs each app to exist, have a
+release, and have instances enabled before Base is allowed to create one for a
+team:
+
+ scripts/prepare-apps.sh <account> releases
+
+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
+fails halfway; steps already done are skipped. You need to be logged in with
+`carlos auth login` first.
+
+## Writing an app Base can install
+
+Base starts your app with four variables. Read them, and verify sign-ins
+against them:
+
+- `BASE_APP_ORIGIN` is your app's own address.
+- `BASE_APP_ISSUER` is Base's address. Accept assertions only from this issuer.
+- `BASE_APP_CONSUMER_ID` is the id of your app in the catalogue.
+- `BASE_APP_KEYS` is base64 of a JSON object that maps each key id (`kid`) to
+ the base64 of that key's 65-byte public key. Check each assertion's
+ signature against the key its `kid` names.
+
+Nothing in Base is specific to one app. `internal/scratchpad` is the small
+example to copy, and its README says who can use it: anyone the Base that
+installed it vouches for, with no roles of their own.
+
+## Checks
+
+`make ci` is the gate. `make browser` drives Chromium through Base and the
+apps it installs; set `RASTRILLO_CHROME` to a Chromium first. `make fonts`
+fetches Timeless Sans, which the licence keeps out of the repository. Without
+it Base falls back to DM Sans.
+
+`docs/live-check.md` is the by-hand check against a real account.
diff --git a/docs/copy-pending.md b/docs/copy-pending.md
index cc22877..26ad21c 100644
--- a/docs/copy-pending.md
+++ b/docs/copy-pending.md
@@ -147,3 +147,4 @@ Passkeys (sign-in page and Settings):
| internal/web/templates/settings.html | Adding a passkey: the person closed the prompt | No passkey was added. |
| internal/web/templates/settings.html | Adding a passkey failed | That didn't work. Try again. |
| internal/web/settings.go | Passkey list failed (503) | unavailable |
+| README.md | Whole file (what Base is, local run, settings, deploy, operator steps, app contract) | README.md — whole file |
diff --git a/docs/live-check.md b/docs/live-check.md
new file mode 100644
index 0000000..dc0572a
--- /dev/null
+++ b/docs/live-check.md
@@ -0,0 +1,37 @@
+# Live check
+
+Run by the controller with Paul, on a flagship account Paul names. Never on
+`main`'s behalf without asking. Fill in each result line as you go.
+
+Account: ______________________ Date: ______________ Commit: ______________
+
+1. Deploy Base to the `edge` channel.
+
+ Result:
+
+2. Run `scripts/prepare-apps.sh <account> releases`. Run it a second time and
+ confirm it finishes and skips what is done (this also checks the "already
+ exists" wording `apps create` and `instances enable` give, which the script
+ matches on).
+
+ Result:
+
+3. Sign in as the owner and invite a second address.
+
+ Result:
+
+4. Install Scratchpad, open it, and confirm it says "Signed in as" with the
+ right address.
+
+ Result:
+
+5. Write a note, uninstall Scratchpad, then install it again. Confirm the note
+ is back. This settles the spec 5.6 question about the parked database. If
+ the note is gone, file the Platform request from spec section 9; don't work
+ around it.
+
+ Result:
+
+6. Anything else seen (copy, timing, errors in the log).
+
+ Result:
diff --git a/go.mod b/go.mod
index 200a83f..9afcb53 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,7 @@ require (
require (
amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect
+ github.com/BurntSushi/toml v1.6.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 // indirect
github.com/google/uuid v1.6.0 // indirect
@@ -22,8 +23,11 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/tdewolff/minify/v2 v2.24.19 // indirect
github.com/tdewolff/parse/v2 v2.8.16 // indirect
+ golang.org/x/mod v0.37.0 // indirect
+ golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.39.0 // indirect
+ golang.org/x/tools v0.47.0 // indirect
gorm.io/gorm v1.31.2 // indirect
gorm.io/plugin/dbresolver v1.6.2 // indirect
modernc.org/libc v1.74.1 // indirect
@@ -31,3 +35,7 @@ require (
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.55.0 // indirect
)
+
+// The CLI the budget and test gates run. Declared as a tool so go mod tidy
+// keeps its build dependencies (the TOML parser behind manifest) in go.sum.
+tool amadan.net/rastrillo/rastrillo/cmd/rastrillo
diff --git a/go.sum b/go.sum
index 89dac51..f11ac52 100644
--- a/go.sum
+++ b/go.sum
@@ -2,6 +2,8 @@ amadan.net/rastrillo/rastrillo v0.33.0 h1:aYK33p7SIKOglr6rZM3EQLXdpz02Rnq9NB4Zhi
amadan.net/rastrillo/rastrillo v0.33.0/go.mod h1:IQnXick/ERWFvhqiQey87Zw1Td2aHlyloykFQB0g0pI=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U=
+github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
+github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/chromedp/cdproto v0.158.6 h1:jaKiXWuhcxbvKbSe8U6Dp5U4Hcj2w6lETYgZqBD5n34=
github.com/chromedp/cdproto v0.158.6/go.mod h1:h68JaIuFr9o3yiayxEYhBdvaxgYO3shDrPSYhNlyfu0=
github.com/chromedp/chromedp v0.21.0 h1:nVHgS2LHyhZJ1l3BWRbG2eFIFYiJMnvkJbELbd8WBoQ=
@@ -14,6 +16,8 @@ github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 h1:UADEEmD
github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
+github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
+github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
diff --git a/internal/appboot/main_test.go b/internal/appboot/main_test.go
new file mode 100644
index 0000000..beca371
--- /dev/null
+++ b/internal/appboot/main_test.go
@@ -0,0 +1,10 @@
+package appboot
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/catalog/main_test.go b/internal/catalog/main_test.go
new file mode 100644
index 0000000..533af13
--- /dev/null
+++ b/internal/catalog/main_test.go
@@ -0,0 +1,10 @@
+package catalog
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/config/main_test.go b/internal/config/main_test.go
new file mode 100644
index 0000000..c63fb67
--- /dev/null
+++ b/internal/config/main_test.go
@@ -0,0 +1,10 @@
+package config
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/install/install.go b/internal/install/install.go
index 0e78bf3..ff1e5ec 100644
--- a/internal/install/install.go
+++ b/internal/install/install.go
@@ -39,6 +39,8 @@ const (
)
// ErrBusy is returned by Uninstall while the app is still being installed.
+//
+//lint:ignore ST1005 the text is shown to people as written
var ErrBusy = errors.New("This app is still installing. Try again in a moment.")
// Installer installs and uninstalls apps. It satisfies web.Installer.
@@ -186,6 +188,7 @@ func (in *Installer) Uninstall(ctx context.Context, app string) error {
_, host := HostFor(in.cfg, app)
if err := in.pc.DeleteInstance(ctx, app, host); err != nil {
in.logger.Error("uninstall failed", "app", app, "err", err)
+ //lint:ignore ST1005 the text is shown to people as written
return errors.New(msgRemove)
}
// The store refuses an installing row too, as a second guard.
diff --git a/internal/install/install_test.go b/internal/install/install_test.go
index 485e9a1..590343c 100644
--- a/internal/install/install_test.go
+++ b/internal/install/install_test.go
@@ -18,6 +18,7 @@ import (
"testing"
"time"
+ "amadan.net/rastrillo/rastrillo/budget"
"amadan.net/rastrillo/rastrillo/crypto"
"amadan.net/rastrillo/rastrillo/dbtest"
@@ -29,7 +30,7 @@ import (
var template = dbtest.FromSet(store.BootSchema)
func TestMain(m *testing.M) {
- code := m.Run()
+ code := budget.Main(m)
template.Remove()
os.Exit(code)
}
diff --git a/internal/look/main_test.go b/internal/look/main_test.go
new file mode 100644
index 0000000..87a5d2a
--- /dev/null
+++ b/internal/look/main_test.go
@@ -0,0 +1,10 @@
+package look_test
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/platform/main_test.go b/internal/platform/main_test.go
new file mode 100644
index 0000000..cf8b50e
--- /dev/null
+++ b/internal/platform/main_test.go
@@ -0,0 +1,10 @@
+package platform
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/store/store_test.go b/internal/store/store_test.go
index c83f16f..40bc53a 100644
--- a/internal/store/store_test.go
+++ b/internal/store/store_test.go
@@ -7,13 +7,14 @@ import (
"os"
"testing"
+ "amadan.net/rastrillo/rastrillo/budget"
"amadan.net/rastrillo/rastrillo/dbtest"
)
var template = dbtest.FromSet(BootSchema)
func TestMain(m *testing.M) {
- code := m.Run()
+ code := budget.Main(m)
template.Remove()
os.Exit(code)
}
diff --git a/internal/web/main_test.go b/internal/web/main_test.go
new file mode 100644
index 0000000..f5e07b5
--- /dev/null
+++ b/internal/web/main_test.go
@@ -0,0 +1,10 @@
+package web
+
+import (
+ "os"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/budget"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/scripts/prepare-apps.sh b/scripts/prepare-apps.sh
new file mode 100755
index 0000000..14c419e
--- /dev/null
+++ b/scripts/prepare-apps.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# One-time operator setup: put every app in Base's catalogue on a CARLOS
+# account, so that Base can install it for a team later.
+#
+# scripts/prepare-apps.sh <account> <release-dir>
+#
+# <release-dir> holds the binaries `make release` built, named
+# <app>-<goos>-<goarch>-<version> (releases/ by default). For each app id in
+# internal/catalog/catalog.json this claims the app name, deploys the binary
+# to the stable channel, and enables instances. 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>.
+set -euo pipefail
+
+if [ $# -ne 2 ]; then
+ echo "usage: $0 <account> <release-dir>" >&2
+ exit 2
+fi
+account=$1
+releases=$2
+root=$(cd -- "$(dirname -- "$0")/.." && pwd)
+catalog=$root/internal/catalog/catalog.json
+
+[ -d "$releases" ] || { echo "release dir not found: $releases" >&2; exit 1; }
+command -v carlos >/dev/null || { echo "carlos is not on PATH" >&2; exit 1; }
+
+# App ids, read from the catalogue so this list can't drift from Base's.
+ids=$(grep -o '"id": *"[^"]*"' "$catalog" | sed 's/.*: *"\(.*\)"/\1/')
+[ -n "$ids" ] || { echo "no app ids found in $catalog" >&2; exit 1; }
+
+# run_tolerating_exists runs a command and treats "already ..." as done.
+run_tolerating_exists() {
+ local out
+ if out=$("$@" 2>&1); then
+ [ -z "$out" ] || printf '%s\n' "$out"
+ elif printf '%s' "$out" | grep -qiE 'already (exists|claimed|enabled|taken)|is taken'; then
+ echo " already done, skipping"
+ else
+ printf '%s\n' "$out" >&2
+ return 1
+ fi
+}
+
+for id in $ids; do
+ echo "== $id"
+
+ # Newest binary for this app: <id>-linux-arm64-<version>, not .COMMIT files.
+ bin=""
+ for f in "$releases/$id"-linux-arm64-*; do
+ case $f in *.COMMIT) continue ;; esac
+ [ -f "$f" ] && bin=$f
+ done
+ [ -n "$bin" ] || { echo "no $id-linux-arm64-* binary in $releases" >&2; exit 1; }
+ version=${bin##*-linux-arm64-}
+
+ echo "claim the app name"
+ run_tolerating_exists carlos apps create --app "$id" --account "$account"
+
+ if carlos releases --app "$id" --account "$account" 2>/dev/null | grep -qF -- "$version"; then
+ echo "promote $version to stable (already shipped)"
+ carlos promote --app "$id" --account "$account" "$version" stable
+ else
+ echo "deploy $version to stable"
+ carlos deploy --app "$id" --account "$account" --channel stable \
+ --version "$version" "$bin"
+ fi
+
+ echo "enable instances"
+ run_tolerating_exists carlos instances enable --app "$id" --account "$account"
+done
+echo "done: every catalogue app is ready for Base to install"