Skip to content

chore(compose): make the stack's network, image and ports overridable - #295

Merged
artempartos merged 2 commits into
developfrom
artempartos/chore-review-app-default
Sep 18, 2026
Merged

artempartos merged 2 commits into
developfrom
artempartos/chore-review-app-default

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Why

Every checkout brings up the same stack: the Compose network is pinned to app_default, the image is tagged web, and Traefik, Temporal and the OTLP collector publish fixed host ports. Two checkouts started that way don't run side by side — they fight. The second one either fails to bind a port or, worse, silently resolves db, redis and web to the first stack's containers, so a branch appears to pass against the wrong database.

The obvious fix — drop the networks.default.name pin and let Compose name the network after the directory — is the wrong one:

  • agent containers are created outside Compose and join the network by name (ContainerStrategies::BaseStrategy → Settings.docker.network, default app_default); a directory-derived name is unknown to them, and docker create fails with network not found
  • .devcontainer/devcontainer.json attaches to it by name
  • Traefik resolves container addresses on it (--providers.docker.network)
  • and it fixes a tenth of the problem: 80/443/8090, 7233, 8080 and 4318 stay fixed, so the second stack still dies on a port bind

What changed

Every global is now a variable with its current value as the default, so nothing changes unless you opt in:

Variable Default What shares state without it
DOCKER_NETWORK app_default db/redis/web resolve to the other stack; also passed to web+worker so agent containers join their own stack's network
WEB_IMAGE web a build in the worktree overwrites the image the main stack runs
TEMPORAL_HOST_PORT, TEMPORAL_UI_HOST_PORT 7233, 8080 port bind conflict (in-network traffic still uses temporal:7233, hence the distinct name)
OTLP_HOST_PORT 4318 port bind conflict
HTTP_HOST_PORT, HTTPS_HOST_PORT, TRAEFIK_DASHBOARD_HOST_PORT 80, 443, 8090 port bind conflict

PORT / VITE_RUBY_PORT / MCP_PORT were already overridable and are unchanged.

The Traefik router for /api is keyed on the network (<network>-api) instead of being called web, so two stacks watching the same Docker socket don't both register a router named web. Agent routers are already unique (terminal-<route_token>).

Docs

  • docs/project/worktree-stack.md (new, indexed) — the procedure, the variable table, and the traps: Google sign-in is registered for :4000 only; both Traefiks watch the same socket and log about each other's containers; the worker doesn't autoreload; don't kill containers by ancestor=web.
  • CLAUDE.md — a short "Working in a git worktree" section pointing at it, since an agent starting Compose from a worktree is the case that silently corrupts the main checkout's database today.
  • .env.example — the block ready to uncomment, with a note that Compose reads .env only, never .env.development.

One payoff worth calling out: CLAUDE.md bans two concurrent backend test runs that share a Postgres. An isolated stack has its own db container and its own aixle_test-N databases, so a worktree suite no longer has to wait — and it never was serialized anyway, because the make flock at tmp/.rails-test.lock is repo-relative.

Verification

docker compose config renders byte-identical defaults to develop; with the worktree block set, every name and port moves as expected:

name: trevally
  - --providers.docker.network=trevally_net
  image: web-trevally
  traefik.http.routers.trevally_net-api.rule: PathPrefix(`/api`)
  published: "4010" "4011" "4012" "7333" "8180" "4418" "8081" "8444" "8091"
  DOCKER_NETWORK: trevally_net
  name: trevally_net

No Ruby or JS changed. CI is unaffected: code-check.yml sets COMPOSE_FILE: docker-compose.ci.yml and never reads this file.

🤖 Generated with Claude Code

artempartos and others added 2 commits September 18, 2026 05:28
Every checkout brought up the same stack: the Compose network pinned to
app_default, the image tagged `web`, and Traefik, Temporal and the OTLP
collector publishing fixed host ports. A second checkout — a worktree under
review — could not run beside the first. It either failed to bind a port or,
worse, resolved db/redis/web to the first stack's containers and quietly
tested a branch against the wrong database.

Removing the network pin was the obvious move and the wrong one: agent
containers are created outside Compose and join the network by name
(Settings.docker.network), .devcontainer attaches to it, and Traefik resolves
container addresses on it — a Compose-generated, directory-derived name is
known to none of them. And the network is only a tenth of the problem while
the host ports stay fixed.

So every global is now a variable with its current value as the default:
DOCKER_NETWORK (which web/worker also pass to Rails, so agent containers land
on their own stack's network), WEB_IMAGE, and one *_HOST_PORT per published
port. The Traefik router for /api is keyed on the network instead of being
called `web`, so two stacks watching the same Docker socket don't both
register the same router name. `docker compose config` renders byte-identical
defaults; isolation is opt-in through a .env in the worktree.

Documented for agents in docs/project/worktree-stack.md, which also covers
what isolation does not fix (Google's :4000-only redirect URI) and what it
does (a worktree suite gets its own Postgres, so it no longer has to wait on
the main checkout's — the make flock is repo-relative and never serialized
across checkouts anyway).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The previous commit explained each variable twice: once in
docs/project/worktree-stack.md and again beside the line it changed. The
comments restated the variable names and duplicated a document that will be
maintained, so they were the copy guaranteed to go stale. Removed from
docker-compose.yml, .env.example and .devcontainer/devcontainer.json; one
two-line note stays on the network pin, which is the thing a reader is most
likely to delete without knowing agent containers join it by name.

CLAUDE.md gains the rule this applies: default to no comment, and write one
only when a competent reader would get the code wrong without it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit ffc8a04 into develop Sep 18, 2026
7 checks passed
aixle-com Bot pushed a commit that referenced this pull request Nov 26, 2026
aixle-com Bot pushed a commit that referenced this pull request Nov 27, 2026
NOX73 added a commit that referenced this pull request Nov 27, 2026
…295) (#904)

* docs(integrations): tech design for integrations chosen per session (#295)

Signed-off-by: Alex <[email protected]>

* docs(integrations): update tech design for #295 after review round 1

Signed-off-by: Alex <[email protected]>

* Design: address review findings on session integrations (restore, Coder identity, tenant checks, backfill)

Signed-off-by: Alex <[email protected]>

* docs(integrations): design round 4 for #295: no Coder identity rules, #294 inside, #290 gates, suspended backfill

Signed-off-by: Alex <[email protected]>

* docs(integrations): fix models test line in session integrations design

Signed-off-by: Alex <[email protected]>

---------

Signed-off-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant