build: prepare the human-run CARLOS release
7 files changed,
+240
−64
Makefile+14 −60README.md+61 −0internal/equipo/app.go+2 −0internal/equipo/auth.go+2 −0internal/equipo/config.go+7 −0internal/equipo/store.go+9 −4internal/equipotest/release_test.go+145 −0
diff --git a/Makefile b/Makefile| index bfa616b2..33a9e9be 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -4,13 +4,13 @@ APP := equipo |
| # machine has. govulncheck judges the standard library of the Go doing the |
| # scan, and make release builds the binary you ship with it, so a patch |
| # release behind is both a red gate and an unpatched binary. go fetches |
| -# this release through the module proxy on first use. It is the Go |
| -# rastrillo's own gate runs; raise it with each Go security release. |
| +# this release through the module proxy on first use. Raise it with |
| +# each Go security release. |
| # |
| # A plain =, not ?=: Go's container images set GOTOOLCHAIN=local, and ?= |
| # would quietly keep whatever Go they ship. To override for one run: |
| # make ci GOTOOLCHAIN=local |
| -export GOTOOLCHAIN = go1.26.6 |
| +export GOTOOLCHAIN = go1.26.10 |
| # The deployment platform target for a release. Building for your own machine and shipping that is a |
| # silent architecture mismatch: the binary uploads fine and fails to exec |
| @@ -20,24 +20,11 @@ RELEASE_GOOS ?= linux |
| RELEASE_GOARCH ?= arm64 |
| RELEASE_BIN := releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH) |
| -# What the running binary reports from GET /api/version. The platform's |
| -# deploy verification polls that endpoint on every instance socket and |
| -# compares what it finds against the release it believes it adopted; an |
| -# unstamped binary answers "dev" from every build you have ever made, so |
| -# those two facts can never disagree and a process that was never |
| -# recycled onto the new release verifies green. Stamping this is what |
| -# gives that check the ability to fail. |
| -# |
| -# git describe, because the tag is what you ship against. Outside a |
| -# repository, or before the first commit, name it yourself: |
| -# make release VERSION=v0.1.0 |
| -VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null) |
| - |
| # One target at a time, even under make -j: the perf lane measures time, |
| # and a suite running beside it would be measured too. |
| .NOTPARALLEL: |
| -.PHONY: build release version-check test vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check ci |
| +.PHONY: build release test vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check ci |
| RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo |
| @@ -47,51 +34,18 @@ RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo |
| build: |
| CGO_ENABLED=0 go build ./... |
| -# release is what ships. -s -w drops the symbol table and DWARF, which on |
| -# this family's apps is 23-31% off the binary and 45-53% off the |
| -# compressed artifact — and compressed size is what actually gets |
| -# transferred. carlos is built the same way (see platform's Makefile). |
| -# |
| -# What survives: panic traces keep their function names AND line numbers |
| -# (Go's pclntab is untouched by these flags), debug.ReadBuildInfo works, |
| -# and go version -m still reports module metadata. What you lose is |
| -# source-level debugging with delve or gdb — build without the flags for |
| -# that. rastrillo dev never strips, for the same reason. |
| -release: version-check |
| +# Stamp the clean commit so /api/version identifies the running release. |
| +# Strip debug data to reduce the upload size; keep module build metadata. |
| +release: |
| + @git diff --quiet && git diff --cached --quiet || \ |
| + { echo "refusing to build a release from a dirty tree"; exit 1; } |
| @mkdir -p releases |
| - CGO_ENABLED=0 GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) \ |
| - go build -ldflags="-s -w -X 'amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)'" \ |
| + CGO_ENABLED=0 GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) go build -trimpath \ |
| + -ldflags "-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$$(git rev-parse --short HEAD)" \ |
| -o $(RELEASE_BIN) ./cmd/$(APP) |
| - @echo |
| - @echo "built $(RELEASE_BIN) reporting version $(VERSION)" |
| - |
| -# version-check refuses rather than letting release ship a binary whose |
| -# version is untrue. Both refusals are about the same thing: /api/version |
| -# is only evidence if the answer identifies one artifact. |
| -# |
| -# An empty stamp is worse than the "dev" default, because "dev" is |
| -# saying something true about itself and "" looks like a value that |
| -# arrived from somewhere. |
| -# |
| -# A dirty tree is refused rather than suffixed. A -dirty stamp names a |
| -# commit plus changes nobody can name, so two different binaries can |
| -# carry the identical string — which does not fix the check, it makes |
| -# it look reliable while it is not, and that is the more expensive |
| -# failure. Refusing costs one `git stash`; a wrong stamp ships. If you |
| -# mean to ship uncommitted work, say so out loud: |
| -# make release VERSION=v0.1.0-wip |
| -version-check: |
| - @if [ -z "$(VERSION)" ]; then \ |
| - echo "make release: no version to stamp."; \ |
| - echo " git describe found nothing here: no repository, or no commit yet."; \ |
| - echo " Commit, or name it: make release VERSION=v0.1.0"; \ |
| - exit 1; \ |
| - fi |
| - @case "$(VERSION)" in *-dirty) \ |
| - echo "make release: the tree is dirty, so $(VERSION) does not name what you are about to ship."; \ |
| - echo " Commit or stash first, or name it: make release VERSION=v0.1.0-wip"; \ |
| - exit 1;; \ |
| - esac |
| + @echo "built $(RELEASE_BIN) stamped $$(git rev-parse --short HEAD)" |
| + @echo "deploy it with:" |
| + @echo " carlos deploy --app $(APP) --account oficina --channel edge --timeout 5m ./$(RELEASE_BIN)" |
| # budget size holds each directory to 5,000 source and 8,000 test lines. |
| # Past that, split by feature (docs/site/testing.md); a record in |
diff --git a/README.md b/README.md| index f080f877..35405dba 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -25,3 +25,64 @@ For disposable sample data, run |
| The path must be unused. Open the printed sign-in link and confirm it in your |
| browser. The drive listens on `127.0.0.1:8824` and removes its database when you |
| stop it with Ctrl-C. |
| + |
| +<!-- COPY REVIEW REQUIRED: deployment section. Controller copy pass pending. --> |
| + |
| +## Deploying |
| + |
| +Paul or a human operator deploys Equipo. The target is account `oficina` on |
| +the flagship console: |
| +[https://console.carloku.com/a/oficina](https://console.carloku.com/a/oficina). |
| +Project account labels do not change this target. |
| + |
| +Before startup, use the supported account/app configuration surface to set: |
| + |
| +- `EQUIPO_ORIGIN` to the confirmed HTTPS origin people will use. |
| +- `EQUIPO_OWNERS` to the comma-separated owner addresses for the first boot. |
| + It seeds owners only when the database has no team. Use People to change |
| + the roster after that. |
| +- `EQUIPO_INSTANCE_KEY` to a secret generated once. Keep it stable across |
| + releases and restarts. |
| +- `CARLOS_SMTP_HOST` and `CARLOS_SMTP_FROM` for platform SMTP mail delivery. |
| + Provision any SMTP authentication the platform requires through its |
| + supported configuration surface. |
| + |
| +Leave `EQUIPO_ALLOW_LOGGED_MAIL` unset in production. It is for local use |
| +and prints sign-in links. Equipo needs no provider or CARLOS credentials. |
| +The human operator uses their own CARLOS CLI access to deploy. |
| + |
| +Confirm the target's architecture before building. From the clean, reviewed |
| +commit, run: |
| + |
| +```sh |
| +make release |
| +``` |
| + |
| +This builds `releases/equipo-linux-arm64` with CGO disabled and stamps |
| +`git rev-parse --short HEAD` into the binary. Tracked changes block the build. |
| +For an amd64 target, use `make release RELEASE_GOARCH=amd64` and deploy |
| +`releases/equipo-linux-amd64` instead. |
| + |
| +Confirm that your CLI targets the flagship console. For the default arm64 |
| +build, run this command yourself: |
| + |
| +```sh |
| +carlos deploy --app equipo --account oficina --channel edge --timeout 5m ./releases/equipo-linux-arm64 |
| +``` |
| + |
| +Keep the flags before the binary path. Poll `GET /api/version` on the actual |
| +deployed origin until the process reports the stamped commit. The router's |
| +`X-Carlos-Version` header does not confirm the running process version. |
| +A successful local build does not confirm deployment. |
| + |
| +After deployment, complete these checks: |
| + |
| +1. Sign in as a configured owner. Add a second roster member and an account |
| + label. Create app, website and repository projects, including one with |
| + only a repository. Refresh, then restart the app and check that the data |
| + persists. |
| +2. Sign in as the member. Check shared visibility and denied owner edits. |
| + Open every empty destination and the phone Work index. |
| +3. Confirm that no runner is enrolled, no execution job exists, and Equipo |
| + requested no provider or CARLOS credential. Record acceptance in the |
| + normal review record. |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 1e22335f..39c4373e 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -61,9 +61,11 @@ func Router(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logger) (chi. |
| return nil, err |
| } |
| if mailer == nil { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return nil, errors.New(copyMissingMailer) |
| } |
| if !mail.IsConfigured(mailer) && !cfg.AllowLoggedMail { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return nil, errors.New(copyUnconfiguredMailer) |
| } |
| if logger == nil { |
diff --git a/internal/equipo/auth.go b/internal/equipo/auth.go| index a25c2b5f..a7f1ef6b 100644 |
| --- a/internal/equipo/auth.go |
| +++ b/internal/equipo/auth.go |
| @@ -20,9 +20,11 @@ func NewAuth(d *db.DB, cfg Config, mailer mail.Sender, store *Store, logger *slo |
| return nil, ErrUnavailable |
| } |
| if mailer == nil { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return nil, errors.New(copyMissingMailer) |
| } |
| if !mail.IsConfigured(mailer) && !cfg.AllowLoggedMail { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return nil, errors.New(copyUnconfiguredMailer) |
| } |
| guard, err := pow.New(pow.Config{ |
diff --git a/internal/equipo/config.go b/internal/equipo/config.go| index 874b27f8..71d273fb 100644 |
| --- a/internal/equipo/config.go |
| +++ b/internal/equipo/config.go |
| @@ -32,6 +32,7 @@ func LoadConfig(getenv func(string) string) (Config, error) { |
| host := strings.TrimSpace(getenv("CARLOS_SMTP_HOST")) |
| from := strings.TrimSpace(getenv("CARLOS_SMTP_FROM")) |
| if (host == "" || from == "") && !cfg.AllowLoggedMail { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return Config{}, errors.New(copyMissingSMTP) |
| } |
| // Owners are enforced by Bootstrap when the database has no team. |
| @@ -40,29 +41,35 @@ func LoadConfig(getenv func(string) string) (Config, error) { |
| func (cfg Config) validate() error { |
| if strings.TrimSpace(cfg.InstanceKey) == "" { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyMissingKey) |
| } |
| u, err := url.Parse(cfg.Origin) |
| if err != nil || u.Hostname() == "" || u.User != nil || u.Opaque != "" || |
| u.Path != "" || u.RawQuery != "" || u.ForceQuery || u.Fragment != "" || strings.Contains(cfg.Origin, "#") { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyInvalidOrigin) |
| } |
| if port := u.Port(); port != "" { |
| n, err := strconv.Atoi(port) |
| if err != nil || n < 1 || n > 65535 { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyInvalidOrigin) |
| } |
| } |
| if strings.HasSuffix(u.Host, ":") { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyInvalidOrigin) |
| } |
| host := strings.ToLower(u.Hostname()) |
| ip := net.ParseIP(host) |
| local := host == "localhost" || (ip != nil && ip.IsLoopback()) |
| if u.Scheme != "https" && !(u.Scheme == "http" && local) { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyInvalidOrigin) |
| } |
| if cfg.AllowLoggedMail && !local { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return errors.New(copyLoggedMailPublic) |
| } |
| return nil |
diff --git a/internal/equipo/store.go b/internal/equipo/store.go| index fb694039..d6d63485 100644 |
| --- a/internal/equipo/store.go |
| +++ b/internal/equipo/store.go |
| @@ -13,10 +13,15 @@ import ( |
| ) |
| var ( |
| - ErrForbidden = errors.New(copyForbidden) |
| - ErrNotFound = errors.New(copyNotFound) |
| - ErrConflict = errors.New(copyConflict) |
| - ErrInvalid = errors.New(copyInvalid) |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| + ErrForbidden = errors.New(copyForbidden) |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| + ErrNotFound = errors.New(copyNotFound) |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| + ErrConflict = errors.New(copyConflict) |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| + ErrInvalid = errors.New(copyInvalid) |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| ErrUnavailable = errors.New(copyUnavailable) |
| ) |
diff --git a/internal/equipotest/release_test.go b/internal/equipotest/release_test.go| new file mode 100644 |
| index 00000000..d5742544 |
| --- /dev/null |
| +++ b/internal/equipotest/release_test.go |
| @@ -0,0 +1,145 @@ |
| +package equipotest |
| + |
| +import ( |
| + "fmt" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "reflect" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestReleaseStampContract(t *testing.T) { |
| + makefile, err := os.ReadFile("../../Makefile") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, tc := range []struct { |
| + name, arch, dirty string |
| + args []string |
| + }{ |
| + {name: "defaults", arch: "arm64"}, |
| + {name: "version override", arch: "arm64", args: []string{"VERSION=unrelated-version"}}, |
| + {name: "amd64 override", arch: "amd64", args: []string{"RELEASE_GOARCH=amd64"}}, |
| + {name: "unstaged", dirty: "unstaged"}, |
| + {name: "staged", dirty: "staged"}, |
| + {name: "unstaged with version", dirty: "unstaged", args: []string{"VERSION=unrelated-version"}}, |
| + {name: "staged with version", dirty: "staged", args: []string{"VERSION=unrelated-version"}}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + dir := t.TempDir() |
| + bin := filepath.Join(dir, "bin") |
| + if err := os.Mkdir(bin, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + write := func(name, contents string, mode os.FileMode) { |
| + t.Helper() |
| + if err := os.WriteFile(filepath.Join(dir, name), []byte(contents), mode); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + write("Makefile", string(makefile), 0600) |
| + write("tracked", "original\n", 0600) |
| + write("bin/go", `#!/bin/sh |
| +set -eu |
| +printf '%s\n' "CGO_ENABLED=$CGO_ENABLED" "GOOS=$GOOS" "GOARCH=$GOARCH" "$@" > "$RELEASE_CAPTURE" |
| +`, 0700) |
| + // Catch an accidental deployment without invoking the real CLI. |
| + write("bin/carlos", "#!/bin/sh\ntouch \"$RELEASE_DEPLOYED\"\nexit 1\n", 0700) |
| + capture := filepath.Join(dir, "go.args") |
| + deployed := filepath.Join(dir, "carlos.called") |
| + // Isolate Git and Make from the caller's repository and overrides. |
| + env := []string{ |
| + "PATH=" + bin + string(os.PathListSeparator) + os.Getenv("PATH"), |
| + "TMPDIR=" + dir, |
| + "GIT_CONFIG_NOSYSTEM=1", "GIT_CONFIG_GLOBAL=/dev/null", |
| + "RELEASE_CAPTURE=" + capture, "RELEASE_DEPLOYED=" + deployed, |
| + } |
| + run := func(name string, args ...string) ([]byte, error) { |
| + cmd := exec.Command(name, args...) |
| + cmd.Dir, cmd.Env = dir, env |
| + return cmd.CombinedOutput() |
| + } |
| + git := func(args ...string) string { |
| + t.Helper() |
| + out, err := run("git", args...) |
| + if err != nil { |
| + t.Fatalf("git %v: %v\n%s", args, err, out) |
| + } |
| + return strings.TrimSpace(string(out)) |
| + } |
| + git("init", "--quiet") |
| + git("config", "user.name", "Release test") |
| + git("config", "user.email", "release@example.invalid") |
| + git("add", "Makefile", "tracked") |
| + git("commit", "--quiet", "-m", "Release fixture") |
| + commit := git("rev-parse", "--short", "HEAD") |
| + if tc.dirty != "" { |
| + write("tracked", "changed\n", 0600) |
| + if tc.dirty == "staged" { |
| + git("add", "tracked") |
| + } |
| + } |
| + out, buildErr := run("make", append([]string{"--no-print-directory", "release"}, tc.args...)...) |
| + if _, err := os.Stat(deployed); !os.IsNotExist(err) { |
| + t.Fatalf("release invoked carlos: %v\n%s", err, out) |
| + } |
| + if tc.dirty != "" { |
| + if buildErr == nil { |
| + t.Errorf("release accepted %s tracked changes\n%s", tc.dirty, out) |
| + } |
| + if _, err := os.Stat(capture); !os.IsNotExist(err) { |
| + t.Errorf("release must reject dirty tracked files before invoking go: %v", err) |
| + } |
| + return |
| + } |
| + if buildErr != nil { |
| + t.Fatalf("make release: %v\n%s", buildErr, out) |
| + } |
| + captured, err := os.ReadFile(capture) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + args := strings.Split(strings.TrimSuffix(string(captured), "\n"), "\n") |
| + wantEnv := []string{"CGO_ENABLED=0", "GOOS=linux", "GOARCH=" + tc.arch, "build"} |
| + if len(args) < len(wantEnv) || !reflect.DeepEqual(args[:len(wantEnv)], wantEnv) { |
| + t.Fatalf("build environment and command = %q, want prefix %q", args, wantEnv) |
| + } |
| + var trimpath bool |
| + var ldflags, output, source string |
| + for i := len(wantEnv); i < len(args); i++ { |
| + switch arg := args[i]; { |
| + case arg == "-trimpath": |
| + trimpath = true |
| + case (arg == "-ldflags" || arg == "-o") && i+1 < len(args): |
| + i++ |
| + if arg == "-ldflags" { |
| + ldflags = args[i] |
| + } else { |
| + output = args[i] |
| + } |
| + case strings.HasPrefix(arg, "-ldflags="): |
| + ldflags = strings.TrimPrefix(arg, "-ldflags=") |
| + default: |
| + source = arg |
| + } |
| + } |
| + if !trimpath { |
| + t.Error("release is missing -trimpath") |
| + } |
| + wantFlags := []string{"-s", "-w", "-X", "amadan.net/rastrillo/rastrillo.BuildVersion=" + commit} |
| + if got := strings.Fields(strings.ReplaceAll(ldflags, "'", "")); !reflect.DeepEqual(got, wantFlags) { |
| + t.Errorf("linker flags = %q, want %q", got, wantFlags) |
| + } |
| + wantOutput := "releases/equipo-linux-" + tc.arch |
| + if output != wantOutput || source != "./cmd/equipo" { |
| + t.Errorf("output/source = %q/%q, want %q/./cmd/equipo", output, source, wantOutput) |
| + } |
| + deploy := fmt.Sprintf("carlos deploy --app equipo --account oficina --channel edge --timeout 5m ./%s", wantOutput) |
| + if !strings.Contains(string(out), deploy) || strings.Contains(string(out), "carlos ship") { |
| + t.Errorf("release must print %q and never carlos ship:\n%s", deploy, out) |
| + } |
| + }) |
| + } |
| +} |