# MAIN_CHECKOUT, WORKTREES_DIR, CLAUDE_SHARED, REPO_NAME and WORKTREE_NAME come from `.devcontainer/.env`, written by `initialize.sh` # (the devcontainer `initializeCommand`). So does TUNNEL_HOST, when you add it there (it's kept across rewrites). services: leyman: build: context: . dockerfile: Dockerfile entrypoint: - /usr/local/share/docker-init.sh volumes: # Mounted at the identical host paths so git worktree links work on both sides - ${MAIN_CHECKOUT:?run .devcontainer/initialize.sh}:${MAIN_CHECKOUT}:delegated - ${WORKTREES_DIR:?run .devcontainer/initialize.sh}:${WORKTREES_DIR}:delegated # Claude settings.json and CLAUDE.md shared with other repos, which claude-config links into - ${CLAUDE_SHARED:?run .devcontainer/initialize.sh}:${CLAUDE_SHARED}:delegated environment: CLAUDE_CONFIG_DIR: ${WORKTREES_DIR}/.shared/claude-config # `gh auth login` once, in any worktree, logs in every one GH_CONFIG_DIR: ${WORKTREES_DIR}/.shared/gh-config # Every worktree installs from one shared store pnpm_config_store_dir: ${WORKTREES_DIR}/.shared/pnpm-store # Caches that grow live in `.shared/`, not the container's own filesystem: they survive rebuilds, and a rebuild # has less to delete before VS Code starts the new container (the devcontainer skill's "Rebuilding"). # pnpm's registry metadata, shared like the store pnpm_config_cache_dir: ${WORKTREES_DIR}/.shared/pnpm-cache # fork-manifest:when go # Go's build and module caches, both safe for several `go` commands at once GOCACHE: ${WORKTREES_DIR}/.shared/go-build GOMODCACHE: ${WORKTREES_DIR}/.shared/go-mod # fork-manifest:end # fork-manifest:when playwright # Browsers for Playwright tests, downloaded once and kept across rebuilds PLAYWRIGHT_BROWSERS_PATH: ${WORKTREES_DIR}/.shared/playwright-browsers # fork-manifest:end NX_SELF_HOSTED_REMOTE_CACHE_SERVER: http://nx-cache:3000 # fork-manifest:when postgres # The `postgres` sidecar. A fixed dev password: local-only, not a secret DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres # fork-manifest:end # This worktree's URL is https://${WORKTREE_NAME}.${REPO_NAME}.localhost REPO_NAME: ${REPO_NAME:?run .devcontainer/initialize.sh} WORKTREE_NAME: ${WORKTREE_NAME:?run .devcontainer/initialize.sh} # A tunnel's public host name, served as well (tools/local-ingress/README.md#tunnels). Empty for none TUNNEL_HOST: ${TUNNEL_HOST:-} # Scratch files, in memory: nothing there outlives the container, and a tmpfs costs nothing to delete. # `exec`, since Docker mounts a tmpfs `noexec` by default, and tools run binaries from /tmp: Nx loads its native # binding from a copy there (falling back to WASM, which fails with "WorkspaceContext is not a constructor"), and # `go test` and `go run` build and run there tmpfs: - /tmp:exec # Only this container joins the machine's shared ingress (`tools/local-ingress`). The sidecars stay off it, so # `postgres` and `valkey` resolve to this worktree's own, while every worktree's are named the same. networks: - default - local-ingress # Serves https://..localhost from port 5173: one web port per container, so worktrees never clash. # Also serves TUNNEL_HOST, if set: a tunnel connects as the `.localhost` name and keeps its own `Host`. # `upstreams` is this container's address on the ingress network, since every worktree's service is `leyman`. labels: caddy: ${WORKTREE_NAME}.${REPO_NAME}.localhost ${TUNNEL_HOST:-} caddy.reverse_proxy: '{{upstreams 5173}}' caddy.tls: internal depends_on: - nx-cache # fork-manifest:when dagger - dagger-nx-cache # fork-manifest:end # fork-manifest:when valkey - valkey # fork-manifest:end # fork-manifest:when postgres - postgres # fork-manifest:end # Overrides default command so things don't shut down after the process ends. command: - sleep - infinity # Shares Nx task outputs across worktrees (Nx's local cache is per-worktree) nx-cache: image: node:26.13.0-trixie-slim@sha256:e4db4c914bf8ad241bd24804fc25d272d89bad97e68cdc8a1414862790a02c39 command: - node - /server/nx-cache-server.mjs volumes: - ./nx-cache-server.mjs:/server/nx-cache-server.mjs:ro - ${WORKTREES_DIR}/.shared/nx-cache:/cache environment: # Reads results it doesn't have from the hosted cache that CI on main writes to (`infra/nx-cache`), never # writes there. Set NX_CACHE_SERVER_UPSTREAM empty (e.g. in `.devcontainer/.env`) to work offline NX_CACHE_SERVER_UPSTREAM: ${NX_CACHE_SERVER_UPSTREAM-https://leyman-nx-cache.leyman.workers.dev} # A full cold `verify` stores about 700 MB. Change it in `.devcontainer/.env` NX_CACHE_SERVER_MAX_SIZE_GB: ${NX_CACHE_SERVER_MAX_SIZE_GB-5} restart: unless-stopped # fork-manifest:when dagger # The Nx cache for `dagger-test`. Separate from `nx-cache`, whose results were built in a different environment, and # with no upstream, so what it serves was only ever built by Dagger on this machine. Every worktree's shares a directory. # Listens on port 3000, where `Test` in `dagger/main.go` expects it. dagger-nx-cache: image: node:26.13.0-trixie-slim@sha256:e4db4c914bf8ad241bd24804fc25d272d89bad97e68cdc8a1414862790a02c39 command: - node - /server/nx-cache-server.mjs volumes: - ./nx-cache-server.mjs:/server/nx-cache-server.mjs:ro - ${WORKTREES_DIR}/.shared/nx-cache-dagger:/cache environment: NX_CACHE_SERVER_MAX_SIZE_GB: ${NX_CACHE_SERVER_MAX_SIZE_GB-5} restart: unless-stopped # fork-manifest:end # fork-manifest:when valkey # For tests that run against Valkey, at `valkey:6379`. One per worktree (unlike the shared caches), so concurrent # test runs never see each other's keys. # fork-manifest:when dagger # Dagger binds its service under the same hostname: keep the image in sync with `valkeyImage` in `dagger/main.go`. # fork-manifest:end valkey: image: valkey/valkey:9.1.2-trixie@sha256:418652cfb58ef879d4978c33553735d7147016032d5aefaa14c828e611eb9dfd # Data only lives as long as the container: tests never rely on it surviving command: - valkey-server - --save - '' - --appendonly - 'no' restart: unless-stopped # fork-manifest:end # fork-manifest:when postgres # For tests that run against Postgres, at `postgres:5432` (`DATABASE_URL` above). One per worktree, so concurrent # test runs never see each other's data. # fork-manifest:when dagger # Dagger binds its service under the same hostname: keep the image and settings in sync with `postgresImage` and # `postgresService` in `dagger/main.go`. # fork-manifest:end postgres: image: postgres:18.6-trixie@sha256:74935e72241653ca55e0414067e6d8763aceb8a810eb51b452253ec3dcfc4336 environment: POSTGRES_PASSWORD: postgres # Nothing is persisted (in memory, not even an anonymous volume), so a restart starts from empty. # Dev data comes from scripts, never from what a database happens to hold. tmpfs: - /var/lib/postgresql # Durability off for speed: only a crash of the machine or VM can corrupt the data, and none of it is kept anyway. # More connections, since tests across parallel Nx tasks share the one server. command: - postgres - -c - fsync=off - -c - synchronous_commit=off - -c - full_page_writes=off - -c - max_connections=500 restart: unless-stopped # fork-manifest:end networks: # Created by `initialize.sh`, shared by every repo's devcontainers local-ingress: external: true