# A self-contained way to try the published image's default deployment (Postgres + local-disk
# artifacts, password sign-in -- see dlboard/scripts/docker_deployment.py) locally: both volumes
# below genuinely persist across `docker compose down`/`up` (no `-v`) -- verified by restarting the
# stack and checking the data is still there, not assumed. The one thing this needs before `docker
# compose up` is a session secret in your shell (the server itself refuses to start without a real
# one -- a missing or placeholder DLBOARD_SECRET_KEY is exactly the kind of thing that's silently
# fine right up until it's a forgeable admin session on something real):
#
#   export DLBOARD_SECRET_KEY=$(openssl rand -hex 32)
#
# Swap `dlboard-postgres`/`dlboard-artifacts` for your own infrastructure before using this
# anywhere real. See docs/docker.md -- including "Using an S3 artifact store instead" if you want one.

services:
  dlboard:
    build: .
    # On `docker compose stop`/`down`, give the server time to write queued artifact blobs and
    # record them (DLBOARD_WORKERS_KILL_TIMEOUT_S, 30 by default) -- Docker's own 10s default would SIGKILL it first.
    stop_grace_period: 35s
    ports:
      - 8050:8050
    environment:
      DLBOARD_POSTGRES_HOST: postgres
      DLBOARD_POSTGRES_USER: dlboard
      DLBOARD_POSTGRES_PASSWORD: dlboard
      DLBOARD_POSTGRES_DATABASE: dlboard
      # Required -- see the top of this file. `:?` fails `docker compose up` immediately with a
      # clear message instead of starting the server with no key (or a placeholder it would refuse
      # to start with anyway).
      DLBOARD_SECRET_KEY: ${DLBOARD_SECRET_KEY:?see the export command at the 
        top of this file}
      # This stack is plain HTTP -- a `Secure` session cookie (the default) is dropped by most HTTP
      # clients on a non-HTTPS origin, which breaks sign-in outright. Never set this to false behind
      # real infrastructure; serve that over HTTPS instead (see docs/docker.md).
      DLBOARD_SECURE_COOKIES: 'false'
    volumes:
      - dlboard-artifacts:/data
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: dlboard
      POSTGRES_PASSWORD: dlboard
      POSTGRES_DB: dlboard
    volumes:
      - dlboard-postgres:/var/lib/postgresql/data
    healthcheck:
      test: [CMD-SHELL, pg_isready -U dlboard]
      interval: 2s
      timeout: 3s
      retries: 20

volumes:
  dlboard-postgres:
  dlboard-artifacts:
