services:
  termfleet:
    build:
      context: .
      # Dev checkout builds from source (the multi-stage Dockerfile); a packed
      # npm install has no source to build and uses the runtime-only
      # docker/Dockerfile.packed instead. Set by
      # src/server/docker-worker-assets.ts (resolveDockerWorkerAssets) via
      # TERMFLEET_DOCKER_DOCKERFILE; defaults to the dev Dockerfile for a
      # manual `docker compose up` run from a checkout.
      dockerfile: ${TERMFLEET_DOCKER_DOCKERFILE:-Dockerfile}
    image: termfleet:local
    ports:
      # ${VAR:-default} so an unset TERMFLEET_WORKER_PORT stays 7374 (never an
      # empty-string publish spec — see TERMFLEET_REGISTRY_URL's empty-string
      # crash for why that pattern is banned). Derived from the worker spec's
      # baseUrl by dockerWorkerPublishPort (src/server/provider-controllers.ts),
      # the one named seam beside dockerComposeProjectName, so N workers on
      # distinct baseUrls each get their own publish port, compose project, and
      # (project-namespaced) volumes.
      - "127.0.0.1:${TERMFLEET_WORKER_PORT:-7374}:7373"
    user: "1001:1001"
    working_dir: /app
    environment:
      HOME: /home/termfleet
      NODE_ENV: production
      TERMFLEET_TERMINAL_THEME_PROFILE: ${TERMFLEET_TERMINAL_THEME_PROFILE:-termfleet-dark}
      # The port is loopback-published (127.0.0.1 below), so the only reachable peer
      # is the host/console — which the in-container gate would otherwise see as a
      # remote and refuse. Trust local requests so the console can probe + proxy it.
      TERMFLEET_TRUST_LOCAL_NETWORK: "1"
    command:
      - node
      - /app/dist/cli.js
      - provider
      - serve
      - --kind
      - virtual-tmux
      - --host
      - 0.0.0.0
      - --port
      - "7373"
      - --prefix
      - termfleet-docker
      - --count
      - "0"
      - --cwd
      - /workspace
      - --reap-ended-after
      - "300"
      - --max-windows
      - "32"
    volumes:
      - termfleet-home:/home/termfleet
      - termfleet-workspace:/workspace

volumes:
  termfleet-home:
  termfleet-workspace:
