carlos / platform Public

ship --check takes --env KEY=VALUE placeholders for every process (rootfs Plan 4, Paul 2026-10-28)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev eda8f1583c3bd8464dcdc4f120cd2c67dd1dd273 parent f41b5d0
7 files changed, +388 −5
  • approved_rootfs_copy_test.go +6 −1
  • cli.go +8 −1
  • docs/site/cli.md +2 −0
  • docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md +12 −1
  • ship_check.go +4 −1
  • ship_check_test.go +293 −0
  • ship_rootfs.go +63 −1

Intent

Attributed to this commit: 20.3 g CO₂e (2,523,938 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-apps-4-console, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go
index 8e96d6ddd..228ce4787 100644
--- a/approved_rootfs_copy_test.go
+++ b/approved_rootfs_copy_test.go
@@ -21,7 +21,7 @@ import (
const rootfsCopyRecordPath = "docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md"
// Canonical ids only: two digits from C01 to C99, three digits from C100
-// (Plan 4 runs to RFS-4-C140). No leading zero on a three-digit id, no C00.
+// (Plan 4 runs to RFS-4-C146). No leading zero on a three-digit id, no C00.
var rootfsCopyIDPattern = regexp.MustCompile(`^RFS-[1-6]-C(0[1-9]|[1-9][0-9]{1,2})$`)
// rootfsCopyIDs is the deck's inventory, pinned as a literal list in the
@@ -106,6 +106,8 @@ var rootfsCopyIDs = []string{
"RFS-4-C137", "RFS-4-C138",
// Whole-branch review round 2: the mixed-version refusals
"RFS-4-C139", "RFS-4-C140",
+ // Task 8b: carlos ship --check --env
+ "RFS-4-C141", "RFS-4-C142", "RFS-4-C143", "RFS-4-C144", "RFS-4-C145", "RFS-4-C146",
// Plan 5
"RFS-5-C01", "RFS-5-C02", "RFS-5-C03", "RFS-5-C04",
"RFS-5-C05", "RFS-5-C06", "RFS-5-C07", "RFS-5-C08",
@@ -231,6 +233,9 @@ var rootfsCopyBuilt = []string{
// Whole-branch review round 2: a placement with a box below the
// rootfs floor (internal/console/rootfs.go)
"RFS-4-C139", "RFS-4-C140",
+ // Task 8b: carlos ship --check --env (ship_rootfs.go, docs/site/cli.md);
+ // C145 is Task 9's, in rails.md
+ "RFS-4-C141", "RFS-4-C142", "RFS-4-C143", "RFS-4-C144", "RFS-4-C146",
}
func mustParseRootfsRecord(t *testing.T) []copyRow {
diff --git a/cli.go b/cli.go
index dc5bfae46..c11772cd3 100644
--- a/cli.go
+++ b/cli.go
@@ -2280,8 +2280,15 @@ func runShip(args []string) {
hibernate := fs.Bool("hibernate", false, "let this rootfs app hibernate when idle. rootfs apps are always on unless their first release opts in")
jit := fs.Bool("jit", false, "let this rootfs release's processes run a JIT compiler, as Node, Bun, Deno, the JVM and Ruby's YJIT need. without it a box never lets memory be writable and executable at once")
check := fs.Bool("check", false, "run the rootfs image here with Docker or Podman, the way a box would, and ship nothing")
+ var envVars shipCheckEnvFlag
+ fs.Var(&envVars, "env", shipEnvFlagHelp)
fs.Usage = flagUsage(fs, "")
fs.Parse(args)
+ // --env is refused before anything else happens, on every ship.
+ checkEnv, err := shipEnvRefusal(fs, *check, envVars)
+ if err != nil {
+ log.Fatal(err)
+ }
// A rootfs release is its own body (ship_rootfs.go): its flags are
// refused anywhere else, and the binary and static path below never
// sees one.
@@ -2292,7 +2299,7 @@ func runShip(args []string) {
} else {
runShipRootfs(fs, rootfsShipOpts{
src: *rootfs, processesFile: *processes,
- hibernate: *hibernate, jit: *jit, check: *check,
+ 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,
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 096c47a56..64969da2a 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -266,6 +266,8 @@ Files under an asset folder are fetched without the visitor's cookies or login,
Servers keep a copy only when your app answers with status 200, a `Cache-Control` that allows it (for example `public, max-age=31536000, immutable`), a `Content-Type` that is not HTML, and no `Set-Cookie`. Each response says what happened in a `Carlos-Cache` header: `hit` came from a saved copy, `miss` had no saved copy yet, so the server fetched it and tried to keep one, and `bypass` was fetched without keeping a copy.
+--env KEY=VALUE gives every process in the check a variable, such as a placeholder secret or a store setting. The check never reads the app's real config or secrets. It sets CARLOS_SOCKET, CARLOS_DB, CARLOS_HOST and CARLOS_REGION itself, so --env cannot set those.
+
### carlos promote
Points a channel at a version you have already shipped.
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
index 3e107f7a1..8ec4c98bf 100644
--- a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
+++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
@@ -72,7 +72,7 @@ From the plan: Placeholders: `<app>` an app name; `<name>` a process name; `<var
| RFS-1-C31 | cli.go | JSON file holding the rootfs release's processes: web, any workers, release and console | approved |
| RFS-1-C32 | cli.go | let this rootfs app hibernate when idle. rootfs apps are always on unless their first release opts in | approved |
| RFS-1-C33 | cli.go | run the rootfs image here with Docker or Podman, the way a box would, and ship nothing | approved |
-| RFS-1-C34 | ship_rootfs.go | usage: carlos ship --app <a> --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] [--version <sha>] [--label <one line>] [--notes <text> \| --notes-file <file>] [--swap hold] [--account <sqid-or-name>] [--account-id <sqid>] [--console <origin>]\n carlos ship --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] --check | approved |
+| RFS-1-C34 | ship_rootfs.go | usage: carlos ship --app <a> --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] [--version <sha>] [--label <one line>] [--notes <text> \| --notes-file <file>] [--swap hold] [--account <sqid-or-name>] [--account-id <sqid>] [--console <origin>]\n carlos ship --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] --check [--env KEY=VALUE ...] | approved |
| RFS-1-C35 | ship_rootfs.go | --rootfs cannot be combined with --<flag> | approved |
| RFS-1-C36 | ship_rootfs.go | --rootfs takes the image or directory as its value, so leave the other arguments off | approved |
| RFS-1-C37 | ship_rootfs.go | --rootfs needs --processes, a JSON file holding the release's processes | approved |
@@ -396,6 +396,17 @@ From the plan: Placeholders: `<app>` an app; `<fleet>` a fleet name; `<region>`
| RFS-4-C139 | internal/console/rootfs.go | fleet <fleet> has a box on a platform release older than v0.29.0 (<box> runs <release>). every box of the fleet needs v0.29.0 or later before it can run a rootfs app | approved |
| RFS-4-C140 | internal/console/rootfs.go | <region> has a box on a platform release older than v0.29.0 (<box> runs <release>). every box in <region> needs v0.29.0 or later before it can run a rootfs app | approved |
+### carlos ship --check --env (Task 8b, Paul 2026-10-28)
+
+| id | file | text | status |
+|---|---|---|---|
+| RFS-4-C141 | ship_rootfs.go | with --check, give every process a variable as KEY=VALUE, such as a placeholder secret. repeat it for more than one | approved |
+| RFS-4-C142 | ship_rootfs.go | --env takes KEY=VALUE, and <arg> has no = | approved |
+| RFS-4-C143 | ship_rootfs.go | --env cannot set <name>: the check sets it, as a box would | approved |
+| RFS-4-C144 | ship_rootfs.go | --env works only with --check | approved |
+| RFS-4-C145 | docs/site/rails.md | The check runs without your app's config and secrets, so give it placeholders for anything the app reads at boot. The sample needs a secret key and its store's coordinates: | approved |
+| RFS-4-C146 | docs/site/cli.md | --env KEY=VALUE gives every process in the check a variable, such as a placeholder secret or a store setting. The check never reads the app's real config or secrets. It sets CARLOS_SOCKET, CARLOS_DB, CARLOS_HOST and CARLOS_REGION itself, so --env cannot set those. | approved |
+
From the plan: (The WORKERS count `<running>/<total>` alone is a number, not copy, so it has no row. RFS-4-C20, unused in the first draft, is the sample page's database line.)
## Plan 5: egress allow (`2026-10-24-rootfs-apps-5-egress-allow.md`)
diff --git a/ship_check.go b/ship_check.go
index 35c678ab1..0cec4f41f 100644
--- a/ship_check.go
+++ b/ship_check.go
@@ -186,7 +186,7 @@ func (c *rootfsCheck) makeImageAndVolumes(ctx context.Context) bool {
}
// processVars is process name's environment in the check: its own env,
-// then the instance's CARLOS_* values (validation keeps CARLOS_ names out of
+// then --env's values, then the instance's CARLOS_* values (validation keeps CARLOS_ names out of
// a process's env). There is no CARLOS_CONTROL_SOCKET or CARLOS_PURGE:
// nothing serves them here.
func (c *rootfsCheck) processVars(name string) map[string]string {
@@ -194,6 +194,9 @@ func (c *rootfsCheck) processVars(name string) map[string]string {
if vars == nil {
vars = map[string]string{}
}
+ // --env refuses the four names below, so none can clash; setting them
+ // last keeps it so whatever reaches here.
+ maps.Copy(vars, c.b.checkEnv)
vars["CARLOS_SOCKET"] = checkSocket
vars["CARLOS_DB"] = checkDB
vars["CARLOS_HOST"] = checkHost
diff --git a/ship_check_test.go b/ship_check_test.go
index fc338d4ba..95cf367a0 100644
--- a/ship_check_test.go
+++ b/ship_check_test.go
@@ -901,3 +901,296 @@ exit 0
t.Errorf("--check stored %v", files)
}
}
+
+// runOf is the run argv the check gave process name, from f's recorded
+// calls; nil when it never ran.
+func (f *fakeCheck) runOf(name string) []string {
+ for _, c := range f.calls {
+ if c[0] == "run" && procOf(flagValue(c, "--name")) == name {
+ return c
+ }
+ }
+ return nil
+}
+
+// envArgs is the -e arguments of one run argv, in order.
+func envArgs(argv []string) []string {
+ var vars []string
+ for i, a := range argv {
+ if a == "-e" {
+ vars = append(vars, argv[i+1])
+ }
+ }
+ return vars
+}
+
+// A check without --env runs exactly the argv it always did: every flag, in
+// order, and no variable beyond the process's own and the check's four.
+func TestShipCheckWithoutEnvUnchanged(t *testing.T) {
+ noSettle(t)
+ for _, env := range []map[string]string{nil, {}} {
+ f := newFakeCheck(t)
+ b := shopBuild(t, shopProcs())
+ b.checkEnv = env
+ if r := runRootfsCheck(context.Background(), f.rt(), b, "/probe/carlos", f.out); r.failed {
+ t.Fatalf("report = %q", r.lines)
+ }
+ web := f.runOf("web")
+ if web == nil {
+ t.Fatal("web was never run")
+ }
+ name := flagValue(web, "--name")
+ prefix := strings.TrimSuffix(name, "-web")
+ id := strings.TrimPrefix(prefix, "carlos-check-")
+ want := []string{"run", "-d", "--name", name,
+ "--read-only", "--tmpfs", "/tmp",
+ "--memory", "1073741824", "--memory-swap", "1073741824",
+ "--cap-drop", "ALL", "--security-opt", "no-new-privileges",
+ "--platform", "linux/arm64", "--user", "65534:65534",
+ "-v", prefix + "-data:/data/instances/check",
+ "-v", prefix + "-run:/run/carlos/instances/check",
+ "-v", "/probe/carlos:/opt/carlos/carlos:ro",
+ "-e", "A_FIRST=1",
+ "-e", "CARLOS_DB=/data/instances/check/shop.example.com.db",
+ "-e", "CARLOS_HOST=shop.example.com",
+ "-e", "CARLOS_REGION=local",
+ "-e", "CARLOS_SOCKET=/run/carlos/instances/check/app.sock",
+ "-e", "PATH=/srv/bin:/usr/bin",
+ "-e", "SHOP_CERT=" + shopCert,
+ "-e", "SHOP_MODE=production",
+ "-w", "/srv",
+ "--entrypoint", "/srv/server",
+ "--label", "carlos-check=" + id,
+ prefix + ":latest", "--port", "x",
+ }
+ if !slices.Equal(web, want) {
+ t.Errorf("env %#v: web's argv\n got %q\nwant %q", env, web, want)
+ }
+ jobs := f.runOf("jobs")
+ wantJobs := []string{
+ "CARLOS_DB=/data/instances/check/shop.example.com.db", "CARLOS_HOST=shop.example.com",
+ "CARLOS_REGION=local", "CARLOS_SOCKET=/run/carlos/instances/check/app.sock",
+ }
+ if got := envArgs(jobs); !slices.Equal(got, wantJobs) {
+ t.Errorf("env %#v: jobs' variables %q, want %q", env, got, wantJobs)
+ }
+ }
+}
+
+// --env reaches every process of the check, as one -e argument each.
+func TestShipCheckEnvReachesEveryProcess(t *testing.T) {
+ noSettle(t)
+ env, err := parseShipCheckEnv([]string{
+ "SECRET_KEY_BASE=x", "CARLOS_STORE_REGION=eu-west-1", "A=b=c",
+ "REPEATED=first", "EMPTY=", "SHOP_MODE=staging", "REPEATED=last",
+ "MULTI=line one\nline two",
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ f := newFakeCheck(t)
+ b := shopBuild(t, shopProcs())
+ b.checkEnv = env
+ if r := runRootfsCheck(context.Background(), f.rt(), b, "/probe/carlos", f.out); r.failed {
+ t.Fatalf("report = %q", r.lines)
+ }
+ given := []string{
+ "A=b=c", "CARLOS_STORE_REGION=eu-west-1", "EMPTY=", "MULTI=line one\nline two",
+ "REPEATED=last", "SECRET_KEY_BASE=x",
+ }
+ checks := []string{
+ "CARLOS_DB=/data/instances/check/shop.example.com.db", "CARLOS_HOST=shop.example.com",
+ "CARLOS_REGION=local", "CARLOS_SOCKET=/run/carlos/instances/check/app.sock",
+ }
+ for _, name := range []string{release.ProcessRelease, release.ProcessWeb, "jobs"} {
+ argv := f.runOf(name)
+ if argv == nil {
+ t.Fatalf("%s was never run", name)
+ }
+ vars := envArgs(argv)
+ for _, want := range append(slices.Clone(given), checks...) {
+ if !slices.Contains(vars, want) {
+ t.Errorf("%s: no -e %q in %q", name, want, vars)
+ }
+ }
+ if slices.Contains(vars, "REPEATED=first") {
+ t.Errorf("%s: a repeated KEY kept its first value: %q", name, vars)
+ }
+ // One argument per variable, never a file.
+ if slices.Contains(argv, "--env-file") {
+ t.Errorf("%s takes an env file", name)
+ }
+ }
+ // A process's own value gives way to --env, for web only: the others
+ // declare no SHOP_MODE.
+ if vars := envArgs(f.runOf(release.ProcessWeb)); !slices.Contains(vars, "SHOP_MODE=staging") || slices.Contains(vars, "SHOP_MODE=production") {
+ t.Errorf("web's SHOP_MODE: %q", vars)
+ }
+
+ // Even a clash the flag rules refuse could not win: the check's four
+ // are set after everything else.
+ f = newFakeCheck(t)
+ b = shopBuild(t, shopProcs())
+ b.checkEnv = map[string]string{"CARLOS_SOCKET": "/elsewhere.sock", "CARLOS_DB": "x", "CARLOS_HOST": "y", "CARLOS_REGION": "z"}
+ if r := runRootfsCheck(context.Background(), f.rt(), b, "/probe/carlos", f.out); r.failed {
+ t.Fatalf("report = %q", r.lines)
+ }
+ for _, name := range []string{release.ProcessRelease, release.ProcessWeb, "jobs"} {
+ if vars := envArgs(f.runOf(name)); !containsAll(vars, checks) {
+ t.Errorf("%s: the check's four lost to --env: %q", name, vars)
+ }
+ for _, v := range envArgs(f.runOf(name)) {
+ if strings.HasPrefix(v, "CARLOS_") && !slices.Contains(checks, v) {
+ t.Errorf("%s: %q beat the check's value", name, v)
+ }
+ }
+ }
+}
+
+func containsAll(have, want []string) bool {
+ for _, w := range want {
+ if !slices.Contains(have, w) {
+ return false
+ }
+ }
+ return true
+}
+
+// Every refusal comes at the flag, before the runtime is asked for anything:
+// through the binary, with a runtime stub that records each call it gets.
+func TestShipCheckEnvRefusals(t *testing.T) {
+ if testing.Short() {
+ t.Skip("runs the carlos binary")
+ }
+ run, bucket := versioningCLI(t)
+ dir, _ := rootfsRailsDir(t)
+ bin, work := t.TempDir(), t.TempDir()
+ logPath := filepath.Join(work, "log")
+ stubRuntime(t, bin, "docker", fmt.Sprintf("echo \"$@\" >> '%s'\nexit 0\n", logPath))
+ procs := filepath.Join(work, "processes.json")
+ if err := os.WriteFile(procs, []byte(`{"web": {"command": ["bin/rails", "server"]}}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ tmp := t.TempDir()
+ t.Setenv("PATH", bin)
+ t.Setenv("CARLOS_CONTAINER_RUNTIME", "")
+ t.Setenv("TMPDIR", tmp)
+
+ check := []string{"ship", "--rootfs", dir, "--processes", procs, "--check"}
+ cases := []struct {
+ name string
+ args []string
+ want string
+ }{
+ {"no equals sign", append(slices.Clone(check), "--env", "SECRET_KEY_BASE"), "--env takes KEY=VALUE, and SECRET_KEY_BASE has no ="},
+ {"empty argument", append(slices.Clone(check), "--env", ""), "--env takes KEY=VALUE, and has no ="},
+ {"empty KEY", append(slices.Clone(check), "--env", "=v"), "--env takes KEY=VALUE, and =v has no ="},
+ {"bad one after a good one", append(slices.Clone(check), "--env", "A=b", "--env", "oops"), "--env takes KEY=VALUE, and oops has no ="},
+ {"CARLOS_SOCKET", append(slices.Clone(check), "--env", "CARLOS_SOCKET=/x"), "--env cannot set CARLOS_SOCKET: the check sets it, as a box would"},
+ {"CARLOS_DB", append(slices.Clone(check), "--env", "CARLOS_DB="), "--env cannot set CARLOS_DB: the check sets it, as a box would"},
+ {"CARLOS_HOST", append(slices.Clone(check), "--env", "CARLOS_HOST=x=y"), "--env cannot set CARLOS_HOST: the check sets it, as a box would"},
+ {"CARLOS_REGION", append(slices.Clone(check), "--env", "CARLOS_REGION=eu"), "--env cannot set CARLOS_REGION: the check sets it, as a box would"},
+ {"without check, rootfs", []string{"ship", "--app", "shop", "--rootfs", dir, "--processes", procs, "--env", "A=b"}, "--env works only with --check"},
+ {"without check, binary", []string{"ship", "--app", "shop", "--env", "A=b", "x"}, "--env works only with --check"},
+ {"without check, a bad value too", []string{"ship", "--app", "shop", "--rootfs", dir, "--processes", procs, "--env", "oops"}, "--env works only with --check"},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ out, err := run(c.args...)
+ if err == nil {
+ t.Fatalf("ship %q succeeded:\n%s", c.args, out)
+ }
+ if !strings.Contains(out, c.want+"\n") {
+ t.Fatalf("ship %q does not say %q:\n%s", c.args, c.want, out)
+ }
+ if log, err := os.ReadFile(logPath); err == nil {
+ t.Fatalf("the runtime was called:\n%s", log)
+ }
+ })
+ }
+ if files := rootfsStoredFiles(t, bucket); len(files) != 0 {
+ t.Errorf("refused ships stored %v", files)
+ }
+ if left := rootfsScratchLeft(t, tmp); len(left) != 0 {
+ t.Errorf("a refusal left scratch: %v", left)
+ }
+ out, _ := run("ship", "-h")
+ if want := "with --check, give every process a variable as KEY=VALUE, such as a placeholder secret. repeat it for more than one"; !strings.Contains(out, want) {
+ t.Errorf("ship -h does not give --env's help:\n%s", out)
+ }
+ if want := "--check [--env KEY=VALUE ...]"; !strings.Contains(out+shipRootfsUsage, want) {
+ t.Errorf("the usage does not end %q", want)
+ }
+}
+
+// --env through the binary: the values reach the runtime as -e arguments
+// of every process, and nowhere else.
+func TestShipCheckEnvThroughTheBinary(t *testing.T) {
+ if testing.Short() {
+ t.Skip("runs the carlos binary")
+ }
+ run, _ := versioningCLI(t)
+ dir, _ := rootfsRailsDir(t)
+ bin, work := t.TempDir(), t.TempDir()
+ logPath := filepath.Join(work, "log")
+ stubRuntime(t, bin, "docker", fmt.Sprintf(`log='%s'
+work='%s'
+echo "$@" >> "$log"
+case "$1" in
+info) env | LC_ALL=C sort > "$work/env-info"; echo aarch64 ;;
+import) cat > /dev/null ;;
+run) env | LC_ALL=C sort > "$work/env-run"
+ prev=
+ for a in "$@"; do
+ if [ "$prev" = -e ]; then
+ case "$a" in MULTI=*) printf '%%s' "${a#MULTI=}" > "$work/multi" ;; esac
+ fi
+ prev=$a
+ done ;;
+exec) echo '{"status":200,"after_ms":7}' ;;
+inspect) echo '{"Running":true}' ;;
+esac
+exit 0
+`, logPath, work))
+ procs := filepath.Join(work, "processes.json")
+ if err := os.WriteFile(procs, []byte(`{"web": {"command": ["bin/rails", "server"], "working_dir": "/rails"}}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ probe := filepath.Join(work, "probe")
+ if err := os.WriteFile(probe, []byte("x"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("PATH", bin)
+ t.Setenv("CARLOS_CONTAINER_RUNTIME", "")
+ t.Setenv("CARLOS_CHECK_PROBE", probe)
+ t.Setenv("TMPDIR", t.TempDir())
+
+ out, err := run("ship", "--rootfs", dir, "--processes", procs, "--check",
+ "--env", "SECRET_KEY_BASE=x", "--env", "CARLOS_STORE_REGION=eu-west-1", "--env", "A=b=c",
+ "--env", "REPEATED=first", "--env", "REPEATED=last", "--env", "MULTI=one\ntwo")
+ if err != nil {
+ t.Fatalf("ship --check --env: %v\n%s", err, out)
+ }
+ log, _ := os.ReadFile(logPath)
+ for _, want := range []string{" -e SECRET_KEY_BASE=x ", " -e CARLOS_STORE_REGION=eu-west-1 ", " -e A=b=c ", " -e REPEATED=last "} {
+ if !strings.Contains(string(log), want) {
+ t.Errorf("the runtime never saw %q:\n%s", want, log)
+ }
+ }
+ if strings.Contains(string(log), "REPEATED=first") {
+ t.Errorf("a repeated KEY kept its first value:\n%s", log)
+ }
+ if multi, err := os.ReadFile(filepath.Join(work, "multi")); err != nil || string(multi) != "one\ntwo" {
+ t.Errorf("MULTI reached the runtime as %q (%v), want one argument with its newline", multi, err)
+ }
+ info, _ := os.ReadFile(filepath.Join(work, "env-info"))
+ runEnv, _ := os.ReadFile(filepath.Join(work, "env-run"))
+ if !bytes.Equal(info, runEnv) {
+ t.Errorf("the runtime ran web in another environment:\ninfo:\n%s\nrun:\n%s", info, runEnv)
+ }
+ for _, name := range []string{"SECRET_KEY_BASE", "CARLOS_STORE_REGION"} {
+ if bytes.Contains(runEnv, []byte(name+"=")) {
+ t.Errorf("the runtime's own environment has %s", name)
+ }
+ }
+}
diff --git a/ship_rootfs.go b/ship_rootfs.go
index 7be24daea..2a8ec71b6 100644
--- a/ship_rootfs.go
+++ b/ship_rootfs.go
@@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
+ "slices"
"strings"
"syscall"
"time"
@@ -22,7 +23,62 @@ import (
// through the console (API mode) or straight to the bucket (direct mode).
// shipRootfsUsage is the rootfs form of ship's usage (RFS-1-C34).
-const shipRootfsUsage = "usage: carlos ship --app <a> --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] [--version <sha>] [--label <one line>] [--notes <text> | --notes-file <file>] [--swap hold] [--account <sqid-or-name>] [--account-id <sqid>] [--console <origin>]\n carlos ship --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] --check"
+const shipRootfsUsage = "usage: carlos ship --app <a> --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] [--version <sha>] [--label <one line>] [--notes <text> | --notes-file <file>] [--swap hold] [--account <sqid-or-name>] [--account-id <sqid>] [--console <origin>]\n carlos ship --rootfs <image-or-dir> --processes <file.json> [--hibernate] [--jit] --check [--env KEY=VALUE ...]"
+
+// shipEnvFlagHelp is --env's help (RFS-4-C141).
+const shipEnvFlagHelp = "with --check, give every process a variable as KEY=VALUE, such as a placeholder secret. repeat it for more than one"
+
+// shipCheckEnvFlag is --env: repeatable, kept in the order given. Set does
+// not validate; parseShipCheckEnv runs the rules once over the whole list.
+// nil when the flag was never given.
+type shipCheckEnvFlag []string
+
+func (f *shipCheckEnvFlag) String() string { return strings.Join(*f, ",") }
+
+func (f *shipCheckEnvFlag) Set(v string) error {
+ *f = append(*f, v)
+ return nil
+}
+
+// shipCheckOwnVars are the variables the check sets itself, as a box would,
+// which --env cannot set (RFS-4-C143).
+var shipCheckOwnVars = []string{"CARLOS_SOCKET", "CARLOS_DB", "CARLOS_HOST", "CARLOS_REGION"}
+
+// parseShipCheckEnv is --env's whole rule set, run at the flag before the
+// runtime is asked for anything. Each argument is split at its first =: KEY
+// before it, VALUE after it, which may be empty or hold more = and newlines.
+// A later argument with the same KEY replaces an earlier one. nil when none
+// were given.
+func parseShipCheckEnv(args []string) (map[string]string, error) {
+ var env map[string]string
+ for _, a := range args {
+ k, v, ok := strings.Cut(a, "=")
+ if !ok || k == "" {
+ return nil, fmt.Errorf("--env takes KEY=VALUE, and %s has no =", a)
+ }
+ if slices.Contains(shipCheckOwnVars, k) {
+ return nil, fmt.Errorf("--env cannot set %s: the check sets it, as a box would", k)
+ }
+ if env == nil {
+ env = map[string]string{}
+ }
+ env[k] = v
+ }
+ return env, nil
+}
+
+// shipEnvRefusal is --env's refusal, before anything else happens: with
+// anything but --check it is refused (RFS-4-C144), and its values meet
+// parseShipCheckEnv.
+func shipEnvRefusal(fs *flag.FlagSet, check bool, args []string) (map[string]string, error) {
+ if !flagWasSet(fs, "env") {
+ return nil, nil
+ }
+ if !check {
+ return nil, errors.New("--env works only with --check")
+ }
+ return parseShipCheckEnv(args)
+}
// shipRootfsOnlyFlags are the flags that mean something only with --rootfs,
// in the order their refusal names them (RFS-1-C38).
@@ -65,6 +121,7 @@ func shipRootfsOnlyRefusal(fs *flag.FlagSet) error {
type rootfsShipOpts struct {
src, processesFile string
hibernate, jit, check bool
+ checkEnv map[string]string // --env, with --check
app, ver, label, notes, swap string
notesFile, console string
assets []string // --assets; nil when not given
@@ -95,6 +152,10 @@ type builtRootfs struct {
image string
size int64
jit bool
+
+ // checkEnv is --env: variables the check gives every process, after the
+ // process's own env and before the check's own four.
+ checkEnv map[string]string
}
var (
@@ -232,6 +293,7 @@ func shipRootfsRun(ctx context.Context, o rootfsShipOpts) error {
return err
}
b.jit = o.jit
+ b.checkEnv = o.checkEnv
if o.check {
// From here a stop signal cancels the check, which removes its
// containers, volumes and image before it returns; the defer above