feat: declare stateless binary and rootfs releases
Preserve the additive storage declaration through direct and API ships, immutable re-ships, staged manifests and canonical identity verification. Pin the runtime and replicas floors and keep local stateless checks free of CARLOS_DB, database volumes and database preparation. Add compatibility, API, canonical-refusal and approved-copy coverage, plus the census proposal for controller-arranged independent review. CLI storage guidance uses approved SR-1 copy; repeat-safe migration guidance still needs an approved copy row from the controller.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 files changed,
+578
−32
apimode.go+7 −2apimode_rootfs.go+5 −1approved_stateless_replicas_copy_test.go+57 −0cli.go+7 −2docs/site/cli.md+2 −0docs/superpowers/notes/census-proposal-stateless-replicas-1.md+21 −0internal/console/apicli.go+18 −3internal/console/apiship_rootfs.go+16 −9internal/console/stateless_ship_test.go+70 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv+8 −0internal/release/layoutintent.go+4 −0internal/release/release.go+8 −1internal/release/rootfs_ship.go+3 −0internal/release/stateless.go+62 −0internal/release/stateless_test.go+158 −0ship_check.go+17 −4ship_rootfs.go+13 −10ship_stateless.go+27 −0ship_stateless_test.go+74 −0
diff --git a/apimode.go b/apimode.go| index 06cc24c33..f701dbe40 100644 |
| --- a/apimode.go |
| +++ b/apimode.go |
| @@ -85,7 +85,8 @@ type apiSession struct { |
| // shipSwap is the release's own swap demand for ship ("hold" or ""), |
| // set from --swap by runShip and runDeploy. A field for deferSaves' |
| // reason: ship has many callers and only those two take the flag. |
| - shipSwap string |
| + shipSwap string |
| + shipStateless bool |
| // shipAssets is the release's asset folders for ship (--assets), set by |
| // runShip, carried exactly as shipSwap is. nil sends no assets key. |
| shipAssets []string |
| @@ -4882,8 +4883,9 @@ func (s *apiSession) ship(ctx context.Context, a apiAcct, app, version, kind, la |
| Capabilities json.RawMessage `json:"capabilities,omitempty"` |
| ProgramChange bool `json:"program_change,omitempty"` |
| Swap string `json:"swap,omitempty"` |
| + Stateless bool `json:"stateless,omitempty"` |
| Assets *release.Assets `json:"assets,omitempty"` |
| - }{version, kind, label, notes, message, capsRaw, programChange, s.shipSwap, shipAssetsBlock(s.shipAssets)}) |
| + }{version, kind, label, notes, message, capsRaw, programChange, s.shipSwap, s.shipStateless, shipAssetsBlock(s.shipAssets)}) |
| if err != nil { |
| return err |
| } |
| @@ -4913,6 +4915,9 @@ func (s *apiSession) ship(ctx context.Context, a apiAcct, app, version, kind, la |
| if err := checkCapabilitiesEcho(capsSet, body); err != nil { |
| return apiShipResult{}, err |
| } |
| + if err := checkStatelessEcho(s.shipStateless, body); err != nil { |
| + return apiShipResult{}, err |
| + } |
| if err := checkSwapEcho(s.shipSwap, body); err != nil { |
| return apiShipResult{}, err |
| } |
diff --git a/apimode_rootfs.go b/apimode_rootfs.go| index 949ea90a0..d193f6a4e 100644 |
| --- a/apimode_rootfs.go |
| +++ b/apimode_rootfs.go |
| @@ -43,10 +43,11 @@ func (s *apiSession) shipRootfs(ctx context.Context, a apiAcct, app, version str |
| Swap string `json:"swap,omitempty"` |
| Processes map[string]release.Process `json:"processes"` |
| Hibernate bool `json:"hibernate,omitempty"` |
| + Stateless bool `json:"stateless,omitempty"` |
| JIT bool `json:"jit,omitempty"` |
| RootfsSize int64 `json:"rootfs_size"` |
| Assets *release.Assets `json:"assets,omitempty"` |
| - }{version, release.KindRootfs, label, notes, message, s.shipSwap, b.procs, hibernate, b.jit, b.size, shipAssetsBlock(s.shipAssets)}) |
| + }{version, release.KindRootfs, label, notes, message, s.shipSwap, b.procs, hibernate, b.stateless, b.jit, b.size, shipAssetsBlock(s.shipAssets)}) |
| if err != nil { |
| return err |
| } |
| @@ -64,6 +65,9 @@ func (s *apiSession) shipRootfs(ctx context.Context, a apiAcct, app, version str |
| } |
| switch status { |
| case http.StatusCreated, http.StatusOK: |
| + if err := checkStatelessEcho(b.stateless, body); err != nil { |
| + return apiShipResult{}, err |
| + } |
| if err := checkSwapEcho(s.shipSwap, body); err != nil { |
| return apiShipResult{}, err |
| } |
diff --git a/approved_stateless_replicas_copy_test.go b/approved_stateless_replicas_copy_test.go| new file mode 100644 |
| index 000000000..68425b9f7 |
| --- /dev/null |
| +++ b/approved_stateless_replicas_copy_test.go |
| @@ -0,0 +1,57 @@ |
| +package main |
| + |
| +import ( |
| + "os" |
| + "regexp" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +const statelessReplicaCopyDeck = "docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md" |
| + |
| +var statelessReplicaBuiltCopy = []string{"SR-1-C01", "SR-1-C02", "SR-1-C03", "SR-1-C09", "SR-1-C10"} |
| + |
| +func statelessReplicaCopyRows(t *testing.T) []copyRow { |
| + t.Helper() |
| + raw, err := os.ReadFile(statelessReplicaCopyDeck) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // Normalize only the status column. Approval notes are never applied text. |
| + lines := strings.Split(string(raw), "\n") |
| + for i, line := range lines { |
| + cells := strings.Split(line, "|") |
| + if len(cells) >= 6 && strings.HasPrefix(strings.TrimSpace(cells[len(cells)-2]), "approved") { |
| + cells[len(cells)-2] = " approved " |
| + lines[i] = strings.Join(cells, "|") |
| + } |
| + } |
| + // A blank line between tables ends the shared parser's table context. |
| + // The deck contains a continued table after a blank line (SR-2-C17). |
| + normalized := strings.Join(lines, "\n") |
| + normalized = strings.ReplaceAll(normalized, "\n\n| SR-", "\n| SR-") |
| + rows, err := parseCopyTableStatuses(normalized, statelessReplicaCopyDeck, regexp.MustCompile(`^SR-[1-4]-C[0-9]{2}$`), "an SR-<plan>-C<nn>", "pending", "approved") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return rows |
| +} |
| +func TestStatelessReplicaBuiltCopyIsApproved(t *testing.T) { |
| + reportAll(t, checkRunBuilt(statelessReplicaCopyRows(t), statelessReplicaBuiltCopy)) |
| +} |
| +func TestStatelessReplicaCopyIsApplied(t *testing.T) { |
| + rows := builtRows(statelessReplicaCopyRows(t), statelessReplicaBuiltCopy) |
| + for i := range rows { |
| + rows[i].Text = rootfsAppliedText(rows[i].Text) |
| + } |
| + reportAll(t, checkRunApplied(rows, ".")) |
| +} |
| +func TestStatelessReplicaCopyHasNoEmDash(t *testing.T) { |
| + raw, err := os.ReadFile(statelessReplicaCopyDeck) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if strings.Contains(string(raw), "—") { |
| + t.Fatal("copy deck contains an em dash") |
| + } |
| +} |
diff --git a/cli.go b/cli.go| index f2b804ac3..c2cf5d01a 100644 |
| --- a/cli.go |
| +++ b/cli.go |
| @@ -2484,6 +2484,7 @@ func runShip(args []string) { |
| label := fs.String("label", "", "one-line human label for this release (\"fixing modals\")") |
| notes := fs.String("notes", "", "changelog fragment for this release") |
| notesFile := fs.String("notes-file", "", "file holding the changelog fragment (mutually exclusive with --notes)") |
| + stateless := fs.Bool("stateless", false, shipStatelessNote) |
| swap := fs.String("swap", "", shipSwapFlagHelp) |
| var assets assetPathsFlag |
| fs.Var(&assets, "assets", shipAssetsFlagHelp) |
| @@ -2512,7 +2513,7 @@ func runShip(args []string) { |
| } else { |
| runShipRootfs(fs, rootfsShipOpts{ |
| src: *rootfs, processesFile: *processes, |
| - hibernate: *hibernate, jit: *jit, check: *check, checkEnv: checkEnv, |
| + stateless: *stateless, hibernate: *hibernate, jit: *jit, check: *check, checkEnv: checkEnv, |
| app: *app, ver: *ver, label: *label, notes: *notes, notesFile: *notesFile, swap: *swap, |
| assets: assets, |
| console: *consoleFlag, acctRaw: acctRaw, acctIDRaw: acctIDRaw, acctOf: acctOf, |
| @@ -2530,6 +2531,9 @@ func runShip(args []string) { |
| log.Fatal(usage) |
| } |
| + if err := shipStatelessRefusal(*kind, *stateless); err != nil { |
| + log.Fatal(err) |
| + } |
| noteText, err := shipNoteText(*notes, *notesFile) |
| if err != nil { |
| log.Fatal(err) |
| @@ -2599,6 +2603,7 @@ func runShip(args []string) { |
| log.Fatal(err) |
| } |
| } |
| + sess.shipStateless = *stateless |
| sess.shipSwap = *swap |
| sess.shipAssets = assets |
| if _, err := runShipAPI(sess, acct, fs, app2, *ver, *kind, *target, *label, noteText, capsSet, false, *programChange, message); err != nil { |
| @@ -2666,7 +2671,7 @@ func runShip(args []string) { |
| // manifest bytes byte-identical to what this verb wrote yesterday. |
| Capabilities: capsSet, |
| // "" when --swap was not given: omitempty keeps the bytes as before. |
| - Swap: *swap, |
| + Stateless: *stateless, Swap: *swap, |
| // nil when --assets was not given: omitempty keeps the bytes as before. |
| Assets: shipAssetsBlock(assets), |
| } |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 6cf69e8e0..cdfd15e3a 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -253,6 +253,8 @@ The console records a change, and the app's boxes apply it. A box that follows t |
| ### carlos ship |
| +Ship with --stateless when your app keeps its data outside its box. The release gets no local database, CARLOS_DB or Litestream. You provide and operate its database and other data services. |
| + |
| Publishes a release. The artifact is hashed, stored under its content |
| address, and recorded in a manifest that never changes afterwards. Shipping |
| does not change what anything serves — for that, see |
diff --git a/docs/superpowers/notes/census-proposal-stateless-replicas-1.md b/docs/superpowers/notes/census-proposal-stateless-replicas-1.md| new file mode 100644 |
| index 000000000..3a1417af6 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-stateless-replicas-1.md |
| @@ -0,0 +1,21 @@ |
| +# Census approval: stateless-replicas-1 |
| + |
| +Ruling `census-ruling-stateless-replicas-1`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `cli.go` `runShip` | body | unchanged (2) | Carry --stateless into binary/API and rootfs ship options; same two read sites, no new read. | |
| +| `ship_check.go` `rootfsCheck.runArgs` | body | unchanged (2) | Stateless local checks mount only the run volume and omit the database mount; same probe read, no new read. | |
| + |
| +Envelopes re-pinned: `.`, `internal/release`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `cli.go` `runShip`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-1;basis=rootfs Plan 1 Task 9: takes --rootfs, --processes, --hibernate, --jit and --check and hands a rootfs ship to runShipRootfs (ship_rootfs.go) before the binary path; the --notes-file ReadFile moved into shipNoteText (its own row, the same read of the file the person named) and the direct-mode version mint into mintDirectVersion; one read site fewer, none added; Task 12: the --hibernate flag help is RFS-1-C32's new text, the same reads;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets (repeatable), checks the folders with checkShipAssets (release.ValidAssetPaths; refused on a static site) before the mode split, carries them into the API meta (sess.shipAssets) and the direct-mode manifest (shipAssetsBlock), and passes them to runShipRootfs (rootfsShipOpts.assets), which runs the same check and carries them the same two ways; after a direct-mode ship has stored a release declaring folders, directShipAssetGens runs the console ship door's backfill (provision.MintMissingAssetGens: lists the app's record keys and gives each record without an asset generation one, a CAS write in the deployment bucket as the person running the CLI) and fails naming any record it could not mint; read sites unchanged (2), none added;rev3=census-ruling-rootfs-apps-4;basis=adds the repeatable --env flag and refuses it before anything else unless --check is given (shipEnvRefusal, parseShipCheckEnv); the parsed values go into rootfsShipOpts.checkEnv. --env values reach the check's local container runtime as -e argv only, never root, never a box. No read added; read sites unchanged (2). |
| +- `ship_check.go` `rootfsCheck.runArgs`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-1;basis=root-input (J4, as main's db.go units); the carlos CLI on a person's machine, as the person (no box unit): new (rootfs Plan 1), builds the docker or podman run argv for one check container; the scanner matches the word Command, here a field of release.Process (a process's argv), not os/exec; reads no file; decides nothing for root;rev3=census-ruling-rootfs-check-volumes;basis=R2 P1: the data and run volume mounts (-v) now carry :nocopy through rootfsCheck.volumeMount, so Docker and Podman never fill an empty check volume from the image directory at the mount point (which would reset the prepared owner and mode); same volumes, same paths, same probe mount, nothing else in the argv changed. Runs on the person's machine as the person; no box unit; no read added. |
| + |
| +Seal: `5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc` → `cb000550f056e23ae31351912eae687bd0d7f7beb9108657246faeb44626cfb7`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index 9f46c68e5..b97832e51 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -1969,7 +1969,8 @@ type shipMeta struct { |
| ProgramChange bool `json:"program_change,omitempty"` |
| // Swap is the release's own demand (zero-downtime spec §4.2): "hold" |
| // or absent. ADDITIVE: absent from every request without --swap. |
| - Swap string `json:"swap,omitempty"` |
| + Swap string `json:"swap,omitempty"` |
| + Stateless bool `json:"stateless,omitempty"` |
| // Processes, Hibernate, JIT and RootfsSize belong to a rootfs release |
| // (rootfs apps Plan 1) and to no other kind. Processes is held raw so |
| // a refusal is release.DecodeProcesses' own sentence; RootfsSize is the |
| @@ -2220,6 +2221,10 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| } |
| + if err := release.ValidateStateless(&release.Manifest{Kind: meta.Kind, Stateless: meta.Stateless}); err != nil { |
| + jsonError(w, http.StatusBadRequest, err.Error()) |
| + return |
| + } |
| if refuseBadSwap(w, meta.Swap) { |
| return |
| } |
| @@ -2426,8 +2431,8 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) { |
| Capabilities: declared, // nil when the meta part carried no key |
| Label: meta.Label, |
| Notes: meta.Notes, |
| - Swap: meta.Swap, |
| - Assets: meta.Assets, // nil when the meta part carried no key |
| + Stateless: meta.Stateless, Swap: meta.Swap, |
| + Assets: meta.Assets, // nil when the meta part carried no key |
| } |
| // Longer than the other CLI doors' 15-20s: this one moves real bytes — |
| // up to apiShipMaxBytes of them — into the bucket, not a handful of |
| @@ -2470,6 +2475,10 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) { |
| "version "+ver+" was already shipped with different capabilities — versions are immutable; ship under a new version") |
| return |
| } |
| + if existing.Stateless != meta.Stateless { |
| + jsonError(w, http.StatusConflict, release.ErrStorageDeclarationConflict.Error()) |
| + return |
| + } |
| if refuseSwapConflict(w, existing.Swap, meta.Swap, ver) { |
| return |
| } |
| @@ -2491,6 +2500,9 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) { |
| // above, and echoing what is ON RECORD is the honest answer to "what |
| // did this version end up declaring". |
| addCapabilitiesEcho(body, existing.Capabilities) |
| + if existing.Stateless { |
| + body["stateless"] = true |
| + } |
| addSwapEcho(body, existing.Swap) |
| addAssetsEcho(body, existing.Assets) |
| addBuildProbe(body, probe) |
| @@ -2554,6 +2566,9 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) { |
| } |
| body := map[string]any{"result": "shipped", "version": ver, "artifacts": out} |
| addCapabilitiesEcho(body, m.Capabilities) |
| + if m.Stateless { |
| + body["stateless"] = true |
| + } |
| addSwapEcho(body, m.Swap) |
| addAssetsEcho(body, m.Assets) |
| addBuildProbe(body, probe) |
diff --git a/internal/console/apiship_rootfs.go b/internal/console/apiship_rootfs.go| index 3d52c1008..fd8868bfa 100644 |
| --- a/internal/console/apiship_rootfs.go |
| +++ b/internal/console/apiship_rootfs.go |
| @@ -250,12 +250,12 @@ func (s *Server) shipRootfsParts(w http.ResponseWriter, r *http.Request, mr *mul |
| File: release.RootfsArtifactFile, SHA256: sum, Size: meta.RootfsSize, |
| }}, |
| Processes: req.procs, |
| - Hibernate: meta.Hibernate, |
| - JIT: meta.JIT, |
| - Label: meta.Label, |
| - Notes: meta.Notes, |
| - Swap: meta.Swap, |
| - Assets: meta.Assets, // nil when the meta part carried no key |
| + Stateless: meta.Stateless, Hibernate: meta.Hibernate, |
| + JIT: meta.JIT, |
| + Label: meta.Label, |
| + Notes: meta.Notes, |
| + Swap: meta.Swap, |
| + Assets: meta.Assets, // nil when the meta part carried no key |
| } |
| ctx, cancel := context.WithTimeout(r.Context(), apiShipRootfsStoreTimeout) |
| defer cancel() |
| @@ -273,6 +273,10 @@ func (s *Server) shipRootfsParts(w http.ResponseWriter, r *http.Request, mr *mul |
| jsonError(w, http.StatusConflict, fmt.Sprintf("version %s was already shipped with different processes, hibernation or jit. versions are immutable, so ship under a new version", ver)) |
| return |
| } |
| + if existing.Stateless != meta.Stateless { |
| + jsonError(w, http.StatusConflict, release.ErrStorageDeclarationConflict.Error()) |
| + return |
| + } |
| if refuseSwapConflict(w, existing.Swap, meta.Swap, ver) { |
| return |
| } |
| @@ -285,7 +289,7 @@ func (s *Server) shipRootfsParts(w http.ResponseWriter, r *http.Request, mr *mul |
| if !s.mintShippedAssets(ctx, w, acct.Sqid, app, existing.Assets) { |
| return |
| } |
| - writeJSON(w, http.StatusOK, rootfsShipAnswer(ver, existing.Artifacts, existing.Swap, existing.Assets, probe)) |
| + writeJSON(w, http.StatusOK, rootfsShipAnswer(ver, existing.Artifacts, existing.Swap, existing.Assets, probe, existing.Stateless)) |
| return |
| } |
| // The first-ship slot (Plan 4 Task 5): after the re-ship short circuit |
| @@ -315,7 +319,7 @@ func (s *Server) shipRootfsParts(w http.ResponseWriter, r *http.Request, mr *mul |
| if !s.mintShippedAssets(ctx, w, acct.Sqid, app, m.Assets) { |
| return |
| } |
| - writeJSON(w, http.StatusCreated, rootfsShipAnswer(ver, m.Artifacts, m.Swap, m.Assets, probe)) |
| + writeJSON(w, http.StatusCreated, rootfsShipAnswer(ver, m.Artifacts, m.Swap, m.Assets, probe, m.Stateless)) |
| } |
| // fixFirstRootfsKind is the ship side of the first-kind boundary (Astra R2 |
| @@ -429,12 +433,15 @@ func (s spoolFile) Write(p []byte) (int, error) { |
| // rootfsShipAnswer is a rootfs ship's answer, in the binary path's shape, |
| // echoing the stored asset folders as that path does. |
| -func rootfsShipAnswer(ver string, artifacts map[string]release.Artifact, swap string, assets *release.Assets, probe string) map[string]any { |
| +func rootfsShipAnswer(ver string, artifacts map[string]release.Artifact, swap string, assets *release.Assets, probe string, stateless ...bool) map[string]any { |
| out := make(map[string]any, len(artifacts)) |
| for name, a := range artifacts { |
| out[name] = map[string]any{"sha256": a.SHA256, "size": a.Size} |
| } |
| body := map[string]any{"result": "shipped", "version": ver, "artifacts": out} |
| + if len(stateless) > 0 && stateless[0] { |
| + body["stateless"] = true |
| + } |
| addSwapEcho(body, swap) |
| addAssetsEcho(body, assets) |
| addBuildProbe(body, probe) |
diff --git a/internal/console/stateless_ship_test.go b/internal/console/stateless_ship_test.go| new file mode 100644 |
| index 000000000..cf1ce0756 |
| --- /dev/null |
| +++ b/internal/console/stateless_ship_test.go |
| @@ -0,0 +1,70 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "github.com/carlosframework/platform/internal/release" |
| + "net/http" |
| + "testing" |
| +) |
| + |
| +func TestStatelessShipRootfs(t *testing.T) { |
| + for _, hibernate := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "resident", true: "hibernate"}[hibernate], func(t *testing.T) { |
| + f := rootfsShipFixture(t) |
| + img := randomBytes(t, 4096) |
| + fields := rootfsFields("0.1.0-1", len(img), hibernate) |
| + fields["stateless"] = true |
| + parts := []shipPart{metaOf(t, fields), {name: "rootfs-linux-arm64", body: img}} |
| + for i, want := range []int{http.StatusCreated, http.StatusOK} { |
| + status, out := postShip(t, f.url("shop"), f.token, parts) |
| + if status != want || out["stateless"] != true { |
| + t.Fatalf("ship %d: %d %v", i, status, out) |
| + } |
| + } |
| + m, err := release.GetManifest(context.Background(), f.fx.rel, "bab", "shop", "0.1.0-1") |
| + if err != nil || !m.Stateless { |
| + t.Fatalf("stored manifest: %v %v", m, err) |
| + } |
| + delete(fields, "stateless") |
| + parts[0] = metaOf(t, fields) |
| + if status, out := postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict { |
| + t.Fatalf("storage change: %d %v", status, out) |
| + } |
| + f.assertScratchEmpty(t) |
| + }) |
| + } |
| +} |
| + |
| +func TestStatelessShipBinaryAndStatic(t *testing.T) { |
| + for _, kind := range []string{"binary", "static"} { |
| + t.Run(kind, func(t *testing.T) { |
| + f := rootfsShipFixture(t) |
| + fields := map[string]any{"version": "v1", "kind": kind, "stateless": true} |
| + payload := randomBytes(t, 1024) |
| + part := "linux-arm64" |
| + if kind == "static" { |
| + part = "site.tar.gz" |
| + } |
| + parts := []shipPart{metaOf(t, fields), {name: part, body: payload}} |
| + status, out := postShip(t, f.url("shop"), f.token, parts) |
| + if kind == "static" { |
| + if status != http.StatusBadRequest { |
| + t.Fatalf("static: %d %v", status, out) |
| + } |
| + f.assertNothingWritten(t, "shop") |
| + return |
| + } |
| + if status != http.StatusCreated || out["stateless"] != true { |
| + t.Fatalf("binary: %d %v", status, out) |
| + } |
| + if status, out = postShip(t, f.url("shop"), f.token, parts); status != http.StatusOK || out["stateless"] != true { |
| + t.Fatalf("re-ship: %d %v", status, out) |
| + } |
| + delete(fields, "stateless") |
| + parts[0] = metaOf(t, fields) |
| + if status, out = postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict { |
| + t.Fatalf("storage change: %d %v", status, out) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index b14a7a4e3..570c73f7a 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -56,3 +56,4 @@ plan14-root-reads-fix-set-aside-exdev.tsv f9d3016cc6803338f9db19311f3f598e20c37c |
| plan14-root-reads-durability-3a-escrow.tsv 03a92257beb9b8aac421559e247d191bd69f28a0b26243397a1344a90d59fc2a |
| plan14-root-reads-rootfs-default-home.tsv 7a0a3da3d6fe7e3c77abb22676db000af2a276c3d13ccae0f038190f51287ed5 |
| plan14-root-reads-probe-burst-limit.tsv 5f805400717bad7726bd9d62744b8103a40eb5f5823b0ab7c960a5c0965cb3bc |
| +plan14-root-reads-stateless-replicas-1.tsv cb000550f056e23ae31351912eae687bd0d7f7beb9108657246faeb44626cfb7 |
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv| new file mode 100644 |
| index 000000000..78702770b |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv |
| @@ -0,0 +1,8 @@ |
| +# Census overlay stateless-replicas-1, written by census-propose (#369). census-ruling-stateless-replicas-1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-replicas-1.md. |
| +# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 8532ad0b6523e01bb6548e7a0ff565615b99e39a8921c338db522812368899a3 cli.go runShip legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-1;basis=rootfs Plan 1 Task 9: takes --rootfs, --processes, --hibernate, --jit and --check and hands a rootfs ship to runShipRootfs (ship_rootfs.go) before the binary path; the --notes-file ReadFile moved into shipNoteText (its own row, the same read of the file the person named) and the direct-mode version mint into mintDirectVersion; one read site fewer, none added; Task 12: the --hibernate flag help is RFS-1-C32's new text, the same reads;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets (repeatable), checks the folders with checkShipAssets (release.ValidAssetPaths; refused on a static site) before the mode split, carries them into the API meta (sess.shipAssets) and the direct-mode manifest (shipAssetsBlock), and passes them to runShipRootfs (rootfsShipOpts.assets), which runs the same check and carries them the same two ways; after a direct-mode ship has stored a release declaring folders, directShipAssetGens runs the console ship door's backfill (provision.MintMissingAssetGens: lists the app's record keys and gives each record without an asset generation one, a CAS write in the deployment bucket as the person running the CLI) and fails naming any record it could not mint; read sites unchanged (2), none added;rev3=census-ruling-rootfs-apps-4;basis=adds the repeatable --env flag and refuses it before anything else unless --check is given (shipEnvRefusal, parseShipCheckEnv); the parsed values go into rootfsShipOpts.checkEnv. --env values reach the check's local container runtime as -e argv only, never root, never a box. No read added; read sites unchanged (2).;rev3=census-ruling-stateless-replicas-1;basis=Carry --stateless into binary/API and rootfs ship options; same two read sites, no new read. file:ReadFile@7899,file:ReadFile@8123 d6f244d2c3bcae95eb8ec0fa7e57c52e9b50c7e9e2e00dda85f930b643731a51 |
| +@legacy 1e4efb560a06cb532c8d4caf719ff375c27a03a5651b26c59d81f271c70da628 ship_check.go rootfsCheck.runArgs legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-1;basis=root-input (J4, as main's db.go units); the carlos CLI on a person's machine, as the person (no box unit): new (rootfs Plan 1), builds the docker or podman run argv for one check container; the scanner matches the word Command, here a field of release.Process (a process's argv), not os/exec; reads no file; decides nothing for root;rev3=census-ruling-rootfs-check-volumes;basis=R2 P1: the data and run volume mounts (-v) now carry :nocopy through rootfsCheck.volumeMount, so Docker and Podman never fill an empty check volume from the image directory at the mount point (which would reset the prepared owner and mode); same volumes, same paths, same probe mount, nothing else in the argv changed. Runs on the person's machine as the person; no box unit; no read added.;rev3=census-ruling-stateless-replicas-1;basis=Stateless local checks mount only the run volume and omit the database mount; same probe read, no new read. file:Command@887,file:Command@971 e684fd3273527a209460ed81e5bcd472a4282f46830fe580e5f07f0b0d876684 |
| +cli.go runShip legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-1;basis=rootfs Plan 1 Task 9: takes --rootfs, --processes, --hibernate, --jit and --check and hands a rootfs ship to runShipRootfs (ship_rootfs.go) before the binary path; the --notes-file ReadFile moved into shipNoteText (its own row, the same read of the file the person named) and the direct-mode version mint into mintDirectVersion; one read site fewer, none added; Task 12: the --hibernate flag help is RFS-1-C32's new text, the same reads;rev3=census-ruling-edge-asset-cache-1;basis=takes --assets (repeatable), checks the folders with checkShipAssets (release.ValidAssetPaths; refused on a static site) before the mode split, carries them into the API meta (sess.shipAssets) and the direct-mode manifest (shipAssetsBlock), and passes them to runShipRootfs (rootfsShipOpts.assets), which runs the same check and carries them the same two ways; after a direct-mode ship has stored a release declaring folders, directShipAssetGens runs the console ship door's backfill (provision.MintMissingAssetGens: lists the app's record keys and gives each record without an asset generation one, a CAS write in the deployment bucket as the person running the CLI) and fails naming any record it could not mint; read sites unchanged (2), none added;rev3=census-ruling-rootfs-apps-4;basis=adds the repeatable --env flag and refuses it before anything else unless --check is given (shipEnvRefusal, parseShipCheckEnv); the parsed values go into rootfsShipOpts.checkEnv. --env values reach the check's local container runtime as -e argv only, never root, never a box. No read added; read sites unchanged (2).;rev3=census-ruling-stateless-replicas-1;basis=Carry --stateless into binary/API and rootfs ship options; same two read sites, no new read. file:ReadFile@7899,file:ReadFile@8123 d6f244d2c3bcae95eb8ec0fa7e57c52e9b50c7e9e2e00dda85f930b643731a51 |
| +ship_check.go rootfsCheck.runArgs legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-1;basis=root-input (J4, as main's db.go units); the carlos CLI on a person's machine, as the person (no box unit): new (rootfs Plan 1), builds the docker or podman run argv for one check container; the scanner matches the word Command, here a field of release.Process (a process's argv), not os/exec; reads no file; decides nothing for root;rev3=census-ruling-rootfs-check-volumes;basis=R2 P1: the data and run volume mounts (-v) now carry :nocopy through rootfsCheck.volumeMount, so Docker and Podman never fill an empty check volume from the image directory at the mount point (which would reset the prepared owner and mode); same volumes, same paths, same probe mount, nothing else in the argv changed. Runs on the person's machine as the person; no box unit; no read added.;rev3=census-ruling-stateless-replicas-1;basis=Stateless local checks mount only the run volume and omit the database mount; same probe read, no new read. file:Command@887,file:Command@971 e684fd3273527a209460ed81e5bcd472a4282f46830fe580e5f07f0b0d876684 |
| +@coverage . d8abf32baa39f05d1e9d4e9b8a24e7113c58f42f8735e7a62e217eb39e7a4bf7 |
| +@coverage internal/release 4f591204ea68e1c2f3c686ea07ace804bd91bbab7f6ca9942ff6ea6d88ff07d8 |
diff --git a/internal/release/layoutintent.go b/internal/release/layoutintent.go| index e7c4edce1..e4a4f0dd7 100644 |
| --- a/internal/release/layoutintent.go |
| +++ b/internal/release/layoutintent.go |
| @@ -398,3 +398,7 @@ func PreLayout(version string) bool { |
| func RecordLayoutIntent(ctx context.Context, s Store, mode, box string, force bool) (LayoutIntent, error) { |
| return AppendLayoutIntent(ctx, s, LayoutIntent{Mode: mode, Scope: LayoutScope{Box: box}, Force: force}) |
| } |
| + |
| +// Reserved first releases for stateless runtime and fleet replicas. |
| +const StatelessRuntimeFloor = "v0.34.0" |
| +const StatelessReplicasFloor = "v0.35.0" |
diff --git a/internal/release/release.go b/internal/release/release.go| index de213dcdf..8c9de4459 100644 |
| --- a/internal/release/release.go |
| +++ b/internal/release/release.go |
| @@ -76,7 +76,8 @@ type Manifest struct { |
| // old binaries. A box reads it from the CANONICAL manifest only |
| // (CanonicalDemand), never from its staged copy, because a root older |
| // than this field re-marshalled its copies without it. |
| - Swap string `json:"swap,omitempty"` |
| + Swap string `json:"swap,omitempty"` |
| + Stateless bool `json:"stateless,omitempty"` |
| // Artifacts is keyed "linux-arm64" etc for binaries, or "site" for a |
| // static tree tar. |
| Artifacts map[string]Artifact `json:"artifacts"` |
| @@ -422,6 +423,9 @@ func validateManifest(m *Manifest) error { |
| default: |
| return fmt.Errorf("invalid kind %q (binary | static | rootfs)", m.Kind) |
| } |
| + if err := ValidateStateless(m); err != nil { |
| + return err |
| + } |
| if err := validateRootfsShape(m); err != nil { |
| return err |
| } |
| @@ -770,6 +774,9 @@ func claimRawShip(ctx context.Context, s Store, acct string, m Manifest, files m |
| if err := validateManifest(&m); err != nil { |
| return fmt.Errorf("ship: %w", err) |
| } |
| + if err := checkStorageDeclaration(ctx, s, acct, &m); err != nil { |
| + return err |
| + } |
| // The kind is checked, and for the app's first ship fixed, before the |
| // first artifact byte, so a ship that loses the first-kind race writes |
| // nothing (rootfs_ship.go). |
diff --git a/internal/release/rootfs_ship.go b/internal/release/rootfs_ship.go| index 6c35bc9c9..592b26812 100644 |
| --- a/internal/release/rootfs_ship.go |
| +++ b/internal/release/rootfs_ship.go |
| @@ -403,6 +403,9 @@ func claimRawShipSpooled(ctx context.Context, s Store, acct string, m Manifest, |
| if err := validateManifest(&m); err != nil { |
| return fmt.Errorf("ship: %w", err) |
| } |
| + if err := checkStorageDeclaration(ctx, s, acct, &m); err != nil { |
| + return err |
| + } |
| if err := establishShipKind(ctx, s, acct, &m); err != nil { |
| return err |
| } |
diff --git a/internal/release/stateless.go b/internal/release/stateless.go| new file mode 100644 |
| index 000000000..6ee0264cb |
| --- /dev/null |
| +++ b/internal/release/stateless.go |
| @@ -0,0 +1,62 @@ |
| +package release |
| + |
| +import ( |
| + "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "errors" |
| + "os" |
| + "strings" |
| +) |
| + |
| +var ErrStatelessKind = errors.New("--stateless is available for binary and rootfs releases only") |
| +var ErrStorageDeclarationConflict = errors.New("this version was already shipped with a different storage declaration. ship a new version") |
| + |
| +// ValidateStateless accepts the additive declaration only on executable releases. |
| +func ValidateStateless(m *Manifest) error { |
| + if m.Stateless && m.Kind != "binary" && m.Kind != KindRootfs { |
| + return ErrStatelessKind |
| + } |
| + return nil |
| +} |
| + |
| +func checkStorageDeclaration(ctx context.Context, s Store, acct string, m *Manifest) error { |
| + old, _, err := GetManifestRaw(ctx, s, acct, m.App, m.Version) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return nil |
| + } |
| + if err != nil { |
| + return err |
| + } |
| + if old.Stateless != m.Stateless { |
| + return ErrStorageDeclarationConflict |
| + } |
| + return nil |
| +} |
| + |
| +// CanonicalManifestDigest hashes the exact validated canonical manifest bytes. |
| +func CanonicalManifestDigest(ctx context.Context, s Store, acct, app, version string) (string, error) { |
| + _, raw, err := GetManifestRaw(ctx, s, acct, app, version) |
| + if err != nil { |
| + return "", err |
| + } |
| + sum := sha256.Sum256(raw) |
| + return hex.EncodeToString(sum[:]), nil |
| +} |
| + |
| +// CanonicalStateless verifies both retained bytes and their canonical artifact |
| +// before returning the storage declaration. Missing evidence is an error. |
| +func CanonicalStateless(ctx context.Context, s Store, acct, app string, id StagedIdentity) (bool, error) { |
| + if err := VerifyStaged(id); err != nil { |
| + return false, err |
| + } |
| + m, _, err := GetManifestRaw(ctx, s, acct, app, id.Version) |
| + if err != nil { |
| + return false, err |
| + } |
| + a, ok := m.BoxArtifact(adoptPlatform) |
| + if !ok || !strings.EqualFold(a.SHA256, id.Digest) { |
| + return false, ErrStagedDigestMismatch |
| + } |
| + return m.Stateless, nil |
| +} |
diff --git a/internal/release/stateless_test.go b/internal/release/stateless_test.go| new file mode 100644 |
| index 000000000..b890ab64c |
| --- /dev/null |
| +++ b/internal/release/stateless_test.go |
| @@ -0,0 +1,158 @@ |
| +package release |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| + "os" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestStatelessManifestCompatibility(t *testing.T) { |
| + oldJSON := []byte(`{"schema":1,"app":"shop","version":"v1","kind":"binary","artifacts":{}}`) |
| + var legacy Manifest |
| + if err := json.Unmarshal(oldJSON, &legacy); err != nil { |
| + t.Fatal(err) |
| + } |
| + legacyJSON, _ := json.Marshal(legacy) |
| + if legacy.Stateless || !bytes.Equal(oldJSON, legacyJSON) { |
| + t.Fatal("legacy manifest changed") |
| + } |
| + ctx := context.Background() |
| + s := NewDirStore(t.TempDir()) |
| + m := Manifest{App: "shop", Version: "v1", Kind: "binary", Stateless: true, Artifacts: map[string]Artifact{adoptPlatform: {File: "shop"}}} |
| + files := map[string][]byte{adoptPlatform: []byte("binary")} |
| + if err := Ship(ctx, s, "bab", m, files); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, err := GetManifest(ctx, s, "bab", "shop", "v1") |
| + if err != nil || !got.Stateless { |
| + t.Fatalf("GetManifest = %v, %v", got, err) |
| + } |
| + if err := Ship(ctx, s, "bab", m, files); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + opt := t.TempDir() |
| + if staged, err := ensureStaged(ctx, s, opt, "bab", "shop", "v1", "shop.example.com"); err != nil || !staged.Stateless { |
| + t.Fatalf("stage: %v %v", staged, err) |
| + } |
| + staged, err := ReadStagedManifest(opt, "bab", "v1", "shop") |
| + if err != nil || !staged.Stateless { |
| + t.Fatalf("staged sibling: %v %v", staged, err) |
| + } |
| + id := StagedIdentity{Version: "v1", StagedPath: VersionPath(opt, "bab", "v1", "shop"), Digest: got.Artifacts[adoptPlatform].SHA256} |
| + if yes, err := CanonicalStateless(ctx, s, "bab", "shop", id); err != nil || !yes { |
| + t.Fatalf("canonical: %v %v", yes, err) |
| + } |
| + _, raw, err := GetManifestRaw(ctx, s, "bab", "shop", "v1") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + sum := sha256.Sum256(raw) |
| + if digest, err := CanonicalManifestDigest(ctx, s, "bab", "shop", "v1"); err != nil || digest != hex.EncodeToString(sum[:]) { |
| + t.Fatalf("manifest digest: %s %v", digest, err) |
| + } |
| + priv, pub := testKeys(t) |
| + if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + other := m |
| + other.Version = "v2" |
| + if err := Ship(ctx, s, "bab", other, files); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + markerOn(t, s, priv, "bab") |
| + signer := RootSigner(priv) |
| + plan, err := signer.PlanResign(ctx, s, "bab", "shop", "stable") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := signer.Resign(ctx, s, plan, "ops@example.com"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := Rollback(ctx, s, priv, "bab", "shop", "stable"); err != nil { |
| + t.Fatal(err) |
| + } |
| + ptr, err := Channel(ctx, s, pub, "bab", "shop", "stable") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rolled, err := GetManifest(ctx, s, "bab", "shop", ptr.Version) |
| + if err != nil || !rolled.Stateless || ptr.Version != "v1" { |
| + t.Fatalf("rollback: %v %v", rolled, err) |
| + } |
| + m.Stateless = false |
| + if err := Ship(ctx, s, "bab", m, files); err == nil { |
| + t.Fatal("storage declaration changed under immutable version") |
| + } |
| +} |
| +func TestStatelessFloorsArePinned(t *testing.T) { |
| + if StatelessRuntimeFloor != "v0.34.0" || StatelessReplicasFloor != "v0.35.0" { |
| + t.Fatal("stateless floors changed") |
| + } |
| +} |
| + |
| +func TestCanonicalStatelessRefusesUnverifiedEvidence(t *testing.T) { |
| + ctx := context.Background() |
| + s := NewDirStore(t.TempDir()) |
| + body := []byte("binary") |
| + m := Manifest{App: "shop", Version: "v1", Kind: "binary", Stateless: true, Artifacts: map[string]Artifact{adoptPlatform: {File: "shop"}}} |
| + if err := Ship(ctx, s, "bab", m, map[string][]byte{adoptPlatform: body}); err != nil { |
| + t.Fatal(err) |
| + } |
| + path := t.TempDir() + "/shop" |
| + if err := os.WriteFile(path, body, 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + id := StagedIdentity{Version: "v1", StagedPath: path, Digest: etagOf(body)} |
| + for _, tc := range []struct { |
| + name string |
| + store Store |
| + id StagedIdentity |
| + }{ |
| + {"missing canonical", NewDirStore(t.TempDir()), id}, |
| + {"unreadable canonical", unreadableStore{s}, id}, |
| + {"wrong retained digest", s, StagedIdentity{Version: "v1", StagedPath: path, Digest: strings.Repeat("0", 64)}}, |
| + {"missing path", s, StagedIdentity{Version: "v1", Digest: id.Digest}}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + if yes, err := CanonicalStateless(ctx, tc.store, "bab", "shop", tc.id); err == nil || yes { |
| + t.Fatalf("accepted unverifiable identity: %v %v", yes, err) |
| + } |
| + }) |
| + } |
| + // Matching retained bytes must also match the canonical artifact. |
| + alternate := []byte("other binary") |
| + if err := os.WriteFile(path, alternate, 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + id.Digest = etagOf(alternate) |
| + if yes, err := CanonicalStateless(ctx, s, "bab", "shop", id); err == nil || yes { |
| + t.Fatalf("accepted different canonical artifact: %v %v", yes, err) |
| + } |
| +} |
| +func TestStatelessRootfsCompatibility(t *testing.T) { |
| + onArm64(t) |
| + for _, hibernate := range []bool{false, true} { |
| + s := NewDirStore(t.TempDir()) |
| + m := rootfsManifest() |
| + m.Hibernate, m.Stateless = hibernate, true |
| + m.Artifacts = map[string]Artifact{RootfsArtifactKey: {File: RootfsArtifactFile}} |
| + files := map[string][]byte{RootfsArtifactKey: []byte("image")} |
| + if err := Ship(context.Background(), s, "bab", *m, files); err != nil { |
| + t.Fatal(err) |
| + } |
| + opt := t.TempDir() |
| + got, err := ensureStagedChecked(context.Background(), s, opt, "bab", "shop", m.Version, "shop.example.com", stageCheck{runtime: "rootfs-v1"}) |
| + if err != nil || !got.Stateless { |
| + t.Fatalf("rootfs stage: %v %v", got, err) |
| + } |
| + } |
| +} |
diff --git a/ship_check.go b/ship_check.go| index 2e3abe4fb..6c63232eb 100644 |
| --- a/ship_check.go |
| +++ b/ship_check.go |
| @@ -190,6 +190,9 @@ func (c *rootfsCheck) makeImageAndVolumes(ctx context.Context) bool { |
| {c.prefix + "-run", []string{"--opt", "type=tmpfs", "--opt", "device=tmpfs", |
| "--opt", fmt.Sprintf("o=uid=%d,gid=%d,mode=0700", checkUID, checkUID)}}, |
| } { |
| + if c.b.stateless && v.name == c.prefix+"-data" { |
| + continue |
| + } |
| c.volumes = append(c.volumes, v.name) |
| args := append([]string{"volume", "create", "--label", "carlos-check=" + c.id, "--driver", "local"}, v.opts...) |
| if _, err := c.rt.run(ctx, nil, append(args, v.name)...); err != nil { |
| @@ -207,6 +210,9 @@ func (c *rootfsCheck) makeImageAndVolumes(ctx context.Context) bool { |
| // waits for it to exit 0. It is recorded like every container, so the |
| // cleanup removes it. |
| func (c *rootfsCheck) prepareData(ctx context.Context) bool { |
| + if c.b.stateless { |
| + return true |
| + } |
| // A process's container is <prefix>-<name>, and a worker may be named |
| // prepare (release.ValidWorkerName). The helper's "_" is outside that |
| // grammar, and inside the runtimes' container names |
| @@ -268,7 +274,11 @@ func (c *rootfsCheck) processVars(name string) map[string]string { |
| // last keeps it so whatever reaches here. |
| maps.Copy(vars, c.b.checkEnv) |
| vars["CARLOS_SOCKET"] = checkSocket |
| - vars["CARLOS_DB"] = checkDB |
| + if c.b.stateless { |
| + delete(vars, "CARLOS_DB") |
| + } else { |
| + vars["CARLOS_DB"] = checkDB |
| + } |
| vars["CARLOS_HOST"] = checkHost |
| vars["CARLOS_REGION"] = "local" |
| return vars |
| @@ -295,10 +305,13 @@ func (c *rootfsCheck) runArgs(ctr, name string) []string { |
| "--memory", mem, "--memory-swap", mem, |
| "--cap-drop", "ALL", "--security-opt", "no-new-privileges", |
| "--platform", "linux/arm64", "--user", user, |
| - "-v", c.volumeMount(0, checkDataDir), |
| - "-v", c.volumeMount(1, checkRunDir), |
| - "-v", c.probe + ":" + checkProbeMount + ":ro", |
| } |
| + if c.b.stateless { |
| + args = append(args, "-v", c.volumeMount(0, checkRunDir)) |
| + } else { |
| + args = append(args, "-v", c.volumeMount(0, checkDataDir), "-v", c.volumeMount(1, checkRunDir)) |
| + } |
| + args = append(args, "-v", c.probe+":"+checkProbeMount+":ro") |
| vars := c.processVars(name) |
| for _, k := range slices.Sorted(maps.Keys(vars)) { |
| args = append(args, "-e", k+"="+vars[k]) |
diff --git a/ship_rootfs.go b/ship_rootfs.go| index 2a8ec71b6..b424420cb 100644 |
| --- a/ship_rootfs.go |
| +++ b/ship_rootfs.go |
| @@ -121,6 +121,7 @@ func shipRootfsOnlyRefusal(fs *flag.FlagSet) error { |
| type rootfsShipOpts struct { |
| src, processesFile string |
| hibernate, jit, check bool |
| + stateless bool |
| checkEnv map[string]string // --env, with --check |
| app, ver, label, notes, swap string |
| notesFile, console string |
| @@ -147,11 +148,12 @@ type rootfsShipOpts struct { |
| // filled, the squashfs file (empty for a --check build, which writes none) |
| // and its size, and --jit, carried for the manifest and --check's warning. |
| type builtRootfs struct { |
| - tree *rootfsimage.Tree |
| - procs map[string]release.Process |
| - image string |
| - size int64 |
| - jit bool |
| + tree *rootfsimage.Tree |
| + procs map[string]release.Process |
| + image string |
| + size int64 |
| + jit bool |
| + stateless bool |
| // checkEnv is --env: variables the check gives every process, after the |
| // process's own env and before the check's own four. |
| @@ -292,6 +294,7 @@ func shipRootfsRun(ctx context.Context, o rootfsShipOpts) error { |
| if err != nil { |
| return err |
| } |
| + b.stateless = o.stateless |
| b.jit = o.jit |
| b.checkEnv = o.checkEnv |
| if o.check { |
| @@ -330,11 +333,11 @@ func shipRootfsRun(ctx context.Context, o rootfsShipOpts) error { |
| BuiltBy: "carlos " + version.Build, BuiltAt: shipNow().UTC().Format(time.RFC3339), |
| Artifacts: map[string]release.Artifact{release.RootfsArtifactKey: {File: release.RootfsArtifactFile}}, |
| Processes: b.procs, |
| - Hibernate: o.hibernate, |
| - JIT: b.jit, |
| - Label: o.label, |
| - Notes: o.notes, |
| - Swap: o.swap, |
| + Stateless: o.stateless, Hibernate: o.hibernate, |
| + JIT: b.jit, |
| + Label: o.label, |
| + Notes: o.notes, |
| + Swap: o.swap, |
| // nil when --assets was not given: omitempty keeps the bytes as before. |
| Assets: shipAssetsBlock(o.assets), |
| } |
diff --git a/ship_stateless.go b/ship_stateless.go| new file mode 100644 |
| index 000000000..a767c399d |
| --- /dev/null |
| +++ b/ship_stateless.go |
| @@ -0,0 +1,27 @@ |
| +package main |
| + |
| +import ( |
| + "encoding/json" |
| + "errors" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +const shipStatelessNote = "this release keeps no local database. CARLOS_DB, SQLite, restore and Litestream are off" |
| +const shipStatelessNoEcho = "the console did not confirm the stateless declaration, so the ship could not be verified" |
| + |
| +func shipStatelessRefusal(kind string, stateless bool) error { |
| + return release.ValidateStateless(&release.Manifest{Kind: kind, Stateless: stateless}) |
| +} |
| + |
| +func checkStatelessEcho(sent bool, body []byte) error { |
| + if !sent { |
| + return nil |
| + } |
| + var echo struct { |
| + Stateless bool `json:"stateless"` |
| + } |
| + if err := json.Unmarshal(body, &echo); err != nil || !echo.Stateless { |
| + return errors.New(shipStatelessNoEcho) |
| + } |
| + return nil |
| +} |
diff --git a/ship_stateless_test.go b/ship_stateless_test.go| new file mode 100644 |
| index 000000000..aae4aa1b0 |
| --- /dev/null |
| +++ b/ship_stateless_test.go |
| @@ -0,0 +1,74 @@ |
| +package main |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "github.com/carlosframework/platform/internal/release" |
| + "net/http" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestShipStatelessKinds(t *testing.T) { |
| + for _, kind := range []string{"binary", "rootfs", "static"} { |
| + for _, stateless := range []bool{false, true} { |
| + err := shipStatelessRefusal(kind, stateless) |
| + if (err != nil) != (kind == "static" && stateless) { |
| + t.Fatalf("%s %v: %v", kind, stateless, err) |
| + } |
| + } |
| + } |
| +} |
| +func TestStatelessCheckEnvironment(t *testing.T) { |
| + b := &builtRootfs{stateless: true, procs: map[string]release.Process{}} |
| + for _, name := range []string{"web", "release", "worker"} { |
| + b.procs[name] = release.Process{Command: []string{"/app"}, Env: map[string]string{"CARLOS_DB": "/bad"}} |
| + } |
| + c := &rootfsCheck{b: b, volumes: []string{"run"}} |
| + for name := range b.procs { |
| + if _, ok := c.processVars(name)["CARLOS_DB"]; ok { |
| + t.Fatal("CARLOS_DB survives", name) |
| + } |
| + args := strings.Join(c.runArgs("ctr", name), " ") |
| + if strings.Contains(args, checkDataDir) || strings.Contains(args, checkDB) { |
| + t.Fatal("database mount survives", args) |
| + } |
| + } |
| +} |
| + |
| +func TestStatelessCheckCreatesNoDatabase(t *testing.T) { |
| + f := newFakeCheck(t) |
| + b := shopBuild(t, shopProcs()) |
| + b.stateless = true |
| + if r := runRootfsCheck(context.Background(), f.rt(), b, "/probe/carlos", f.out); r.failed { |
| + t.Fatal(r.lines) |
| + } |
| + for _, args := range f.calls { |
| + joined := strings.Join(args, " ") |
| + if strings.Contains(joined, "CARLOS_DB") || strings.Contains(joined, "-data") || strings.Contains(joined, "_prepare") || strings.Contains(joined, checkDB) { |
| + t.Fatal("database operation:", joined) |
| + } |
| + } |
| + f.checkLeftNothing(t) |
| +} |
| + |
| +func TestStatelessRootfsAPIWireAndEcho(t *testing.T) { |
| + for _, echo := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "missing", true: "confirmed"}[echo], func(t *testing.T) { |
| + ts, parts := rootfsTestConsole(t, http.StatusCreated, map[string]any{"version": "v1", "stateless": echo}) |
| + b := rootfsTestBuilt(t, []byte("image"), false) |
| + b.stateless = true |
| + _, err := newTestSession(ts.URL).shipRootfs(context.Background(), apiAcct{Seg: "bab"}, "shop", "v1", b, false, "", "") |
| + if (err != nil) != !echo { |
| + t.Fatalf("echo %v: %v", echo, err) |
| + } |
| + var meta map[string]any |
| + if err := json.Unmarshal((*parts)[0].body, &meta); err != nil { |
| + t.Fatal(err) |
| + } |
| + if meta["stateless"] != true { |
| + t.Fatalf("meta: %v", meta) |
| + } |
| + }) |
| + } |
| +} |