Skip to content

chore: make Docker Compose stack worktree-safe for parallel development#5249

Open
fpigeonjr wants to merge 5 commits intomainfrom
OPS-5237/worktree-safe-docker
Open

chore: make Docker Compose stack worktree-safe for parallel development#5249
fpigeonjr wants to merge 5 commits intomainfrom
OPS-5237/worktree-safe-docker

Conversation

@fpigeonjr
Copy link
Contributor

Summary

Closes #5237

Removes host-port collisions and container-name conflicts that occur when running the Docker Compose stack from multiple Git worktrees or parallel checkouts.

Changes

Compose files (all 6)

  • Removed all container_name values — Docker Compose now auto-names containers as {project}-{service}-{n}, which is unique per Compose project
  • Parameterized host ports via env vars with safe defaults:
    • DB_PORT (default 5432)
    • BACKEND_PORT (default 8080)
    • FRONTEND_PORT (default 3000)
    • BACKEND_DOMAIN (default http://localhost:8080) — used by VITE_BACKEND_DOMAIN / REACT_APP_BACKEND_DOMAIN

Main compose files (docker-compose.yml, .static.yml, .demo.yml, .initial.yml)

  • Moved data-import and disable-users behind a setup profile — eliminates stale exited containers on routine docker compose up
  • Removed data-import from backend's depends_on — required because a profiled service that isn't activated would otherwise block backend from starting

New developer workflows

# First run or data reset
docker compose --profile setup up --build

# Subsequent runs (faster, no setup containers)
docker compose up --build

# Run a second worktree on alternate ports
COMPOSE_PROJECT_NAME=ops_feature_xyz \
DB_PORT=55432 BACKEND_PORT=58080 FRONTEND_PORT=53000 BACKEND_DOMAIN=http://localhost:58080 \
docker compose --profile setup up --build

Documentation

  • README.md — updated Run section with first-run/subsequent-run split; added "Running multiple worktrees in parallel" section with port variable table
  • AGENTS.md — updated Docker Commands block to reflect profile-aware commands and port variable table
  • docs/developers/worktree-safe-docker.md — new tracking document with full plan and completed task checklist

Notes

  • All port/domain defaults are unchanged, so developers who don't set any variables get identical behaviour to before
  • The TruffleHog pre-commit hook is skipped locally in this worktree — it tries to git clone file:///workdir inside a container, but a worktree's .git is a pointer file rather than a directory, making the clone fail. CI uses actions/checkout with a normal clone so it is not affected. This is a separate pre-existing issue.

- Remove fixed container_name values from all compose files so containers
  are namespaced by Compose project name
- Parameterize host ports (DB_PORT, BACKEND_PORT, FRONTEND_PORT) and
  backend domain (BACKEND_DOMAIN) with safe defaults in all compose files
- Move data-import and disable-users behind a 'setup' profile to avoid
  stale exited containers on routine docker compose up
- Remove data-import from backend depends_on (incompatible with profiles)
- Update README and AGENTS.md with profile-aware commands, port variable
  table, and multi-worktree parallel development workflow example
- Add docs/developers/worktree-safe-docker.md tracking document

Closes #5237
@fpigeonjr fpigeonjr self-assigned this Mar 11, 2026
@fpigeonjr fpigeonjr added the devex developer experiece label Mar 11, 2026
@fpigeonjr fpigeonjr requested a review from Copilot March 11, 2026 18:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the local Docker Compose development stack to support running multiple parallel Git worktrees/checkouts without container-name or host-port collisions (Issue #5237).

Changes:

  • Removed hard-coded container_name entries so Compose project scoping provides isolation.
  • Parameterized host port mappings and frontend backend-domain configuration via environment variables with safe defaults.
  • Moved one-shot setup services (data-import, disable-users) behind a setup profile and updated developer documentation/workflows accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docker-compose.yml Removes fixed container names, parameterizes ports/domain, and profiles setup services to avoid collisions and stale containers.
docker-compose.static.yml Applies the same worktree-safe naming/port changes; parameterizes VITE_BACKEND_DOMAIN build arg; profiles setup services.
docker-compose.demo.yml Applies the same worktree-safe naming/port changes; profiles setup services for demo stack.
docker-compose.initial.yml Applies the same worktree-safe naming/port changes; profiles setup services for initial seed flow.
backend/ops_api/tests/docker-compose.yml Removes fixed container names and parameterizes DB host port for parallel runs.
backend/data_tools/tests/docker-compose.yml Removes fixed container name and parameterizes DB host port (preserving existing non-standard default).
README.md Documents setup-profile workflow and adds guidance for parallel worktrees with COMPOSE_PROJECT_NAME + port vars.
AGENTS.md Updates Docker commands and documents port variables for worktree-safe parallel development.
docs/developers/worktree-safe-docker.md Adds a tracking/plan document describing the approach, variables, and workflows for worktree-safe Compose usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…to CI

- Restore container_name: pytest-data-import in backend/ops_api/tests/docker-compose.yml
  so conftest.py is_loaded() can find the container by name via docker ps
- Add --profile setup to .github/actions/run-full-stack/action.yml so E2E tests
  run with a seeded database
- Fix misleading doc comments: setup services run concurrently with backend/frontend,
  not strictly before them (depends_on was removed); update stale container name
  reference in worktree-safe-docker.md
@fpigeonjr fpigeonjr marked this pull request as ready for review March 11, 2026 20:57
@fpigeonjr fpigeonjr requested a review from jonnalley March 13, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devex developer experiece

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make local Docker Compose worktree-safe for parallel development

3 participants