Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
docs(self-host): fix secret command form + postgres exec, sync swarm rule
Sidwebworksc270817bea9d
diff --git a/.claude/rules/contrib-deploying-swarm.md b/.claude/rules/contrib-deploying-swarm.mdindex 4686fecbb8..38dbf53953 100644--- a/.claude/rules/contrib-deploying-swarm.md+++ b/.claude/rules/contrib-deploying-swarm.md@@ -48,12 +48,20 @@ This **replaced** the old `docker-compose.prod.yml` + `deploy/prod/` compose sta- `.env.example` — NON-secret config only (hosts/urls, `CARBON_REPO`, image tags,pg tuning, toggles). Secrets are never here.-## Secrets (9, all `external: true` — created by `deploy.sh init`)-`postgres_password`, `session_secret`, `inngest_signing_key` (plain hex — self-host-Inngest rejects the `signkey-` prefix), `inngest_event_key`, the trio `jwt_secret`/-`anon_key`/`service_role_key` (minted together), and operator-supplied-`resend_api_key` + `smtp_password` (seeded with placeholders so the stack deploys;-ERP crashes on boot with an empty RESEND key).+## Secrets (10, all `external: true` — created by `deploy.sh init`)+`postgres_password`, `postgrest_db_uri`, `session_secret`, `inngest_signing_key`+(plain hex — self-host Inngest rejects the `signkey-` prefix), `inngest_event_key`,+the trio `jwt_secret`/`anon_key`/`service_role_key` (minted together), and+operator-supplied `resend_api_key` + `smtp_password` (seeded with placeholders so+the stack deploys; ERP crashes on boot with an empty RESEND key).+- **`postgres_password` + `postgrest_db_uri` are a pair** — both written ONLY via+ `set_postgres_password()` in deploy.sh (init, `init --force`, and+ `secret postgres_password` all cascade), so the password can't drift between them.+ PostgREST's image is FROM scratch (no shell → can't run the secrets-entrypoint+ shim), so it reads its full connection URI from the `postgrest_db_uri` file via+ PostgREST's native `@file` syntax (`PGRST_DB_URI: "@/run/secrets/postgrest_db_uri"`,+ `PGRST_JWT_SECRET: "@/run/secrets/jwt_secret"`). Drift here = "password+ authentication failed for user authenticator".## Key facts / gotchas- **Single-node only.** Config files + edge functions are bind-mounted from@@ -64,13 +72,27 @@ ERP crashes on boot with an empty RESEND key).- **Image launch argv is preserved** when overriding `entrypoint` to the shim — eachservice's `command:` is the image's real ENTRYPOINT+CMD (captured via`docker image inspect`), e.g. realtime = `/usr/bin/tini -s -g -- /app/run.sh /app/bin/server`,- storage/meta/studio = `docker-entrypoint.sh node …`, postgres adds the tuning flags.+ storage/meta/studio = `docker-entrypoint.sh node …`. **postgres does NOT override+ shared_preload_libraries** (the image default already preloads pg_net, pg_cron,+ pgsodium, supabase_vault, … — overriding it dropped pg_net and broke the webhooks+ migration's `CREATE EXTENSION pg_net`). **postgrest does NOT use the shim** (scratch+ image, no shell) — it uses `@file` secrets instead.+- **Healthchecks use `127.0.0.1`, never `localhost`** — `/etc/hosts` resolves+ localhost to `::1` (IPv6) but services bind IPv4, and busybox `wget` (caddy) won't+ fall back, so a localhost check flaps the service. **studio** also needs+ `HOSTNAME=0.0.0.0` (Next.js standalone binds `$HOSTNAME`, which Docker sets to the+ container id → overlay IP only) and a healthcheck override (its built-in demands+ HTTP 200 with no start_period).- **Ordering** isn't via `depends_on` (Swarm ignores it). `deploy.sh up` deploys all,waits for postgres+storage healthy, runs `migrate` as an ephemeral`--mode replicated-job` service on `${STACK_NAME}_internal` (reads the passwordfrom `/run/secrets/postgres_password`, `PGSSLMODE=disable`), then `--force` rolls erp/mes.- **Postgres has no TLS** → `SUPABASE_DB_URL` keeps `?sslmode=disable`; migrate sets `PGSSLMODE=disable`.-- **Only caddy publishes** (80/443 + 443/udp for HTTP/3). Studio unpublished.+- **Only caddy publishes** (80/443 + 443/udp for HTTP/3), in **`mode: host`** (NOT+ ingress) with `update_config.order: stop-first`. ingress-mesh (IPVS) convergence+ lags caddy's immediate ACME attempt, so HTTP-01 validators hit `:80` before it+ routes and get connection-refused, failing every cert. host mode binds the NIC+ the instant caddy starts. Studio unpublished.- **Registry mode**: set `CARBON_REGISTRY` + image tags; `build` no-ops, `deploy`resolves images from the registry.diff --git a/docs/content/docs/platform/self-hosting/docker-caddy.mdx b/docs/content/docs/platform/self-hosting/docker-caddy.mdxindex a66a99053c..494f0b67bb 100644--- a/docs/content/docs/platform/self-hosting/docker-caddy.mdx+++ b/docs/content/docs/platform/self-hosting/docker-caddy.mdx@@ -71,8 +71,8 @@ Everything for this recipe lives in [`contrib/deploying/simple-docker-caddy`](ht`init` seeds placeholders so the stack deploys; replace them with real values. ERP **fails to boot** with an empty Resend key.```bash- printf '%s' 're_xxxxxxxx' | ./deploy.sh secret resend_api_key- printf '%s' 'your-smtp-password' | ./deploy.sh secret smtp_password+ ./deploy.sh secret resend_api_key re_xxxxxxxx+ ./deploy.sh secret smtp_password 'your-smtp-password'```</Step><Step>@@ -124,13 +124,13 @@ GOTRUE_JWT_SECRET: __JWT_SECRET__| Back up | `./scripts/backup.sh` (Postgres dump + storage archive) || Stop | `./deploy.sh down` (add `--volumes` to also wipe data) |-**Database admin.** Studio is internal-only by default. Reach the database over SSH with `docker exec -it $(docker ps -qf name=carbon_postgres) psql -U postgres`, or expose Studio behind HTTP basic-auth by setting `STUDIO_HOST` and uncommenting the studio block in the `Caddyfile`.+**Database admin.** Studio is internal-only by default. Reach the database over SSH with `docker exec -it $(docker ps -qf name=carbon_postgres.1) psql -U postgres` (the `.1` avoids also matching `carbon_postgrest`), or expose Studio behind HTTP basic-auth by setting `STUDIO_HOST` and uncommenting the studio block in the `Caddyfile`.**Rotate a secret.** Swarm secrets are immutable while in use, so bring the stack down first:```bash./deploy.sh down-printf '%s' 'new-value' | ./deploy.sh secret <name>+./deploy.sh secret <name> 'new-value'./deploy.sh up```