services:
  postgres:
    image: postgres:16-alpine
    container_name: excalidraw-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: excalidraw
      POSTGRES_PASSWORD: excalidraw
      POSTGRES_DB: excalidraw
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U excalidraw -d excalidraw"]
      interval: 5s
      timeout: 5s
      retries: 5

  excalidraw:
    build:
      context: .
      dockerfile: excalidraw-full.Dockerfile
    ports:
      - "3002:3002"
    volumes:
      # NOTE: Using a named Docker volume instead of a host bind mount.
      # Host bind mounts (./data:/root/data) persist on your filesystem
      # even after `docker compose down` or `docker system prune -a`.
      # A named volume is managed by Docker and can be removed with:
      # `docker compose down -v` or `docker system prune -a --volumes`.
      - excalidraw_data:/root/data
      - ./.env:/root/.env
    environment:
      - LISTEN_ADDR=:3002
      - STORAGE_TYPE=${STORAGE_TYPE:-postgres}
      - DATABASE_URL=${DATABASE_URL:-postgres://excalidraw:excalidraw@postgres:5432/excalidraw?sslmode=disable}
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:
  excalidraw_data:
