name: drivoly

services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: drivoly
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:?set a strong database password}"
      POSTGRES_DB: drivoly
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U drivoly -d drivoly"]
      interval: 5s
      timeout: 5s
      retries: 10

  drivoly:
    image: drivoly/server
    build:
      context: .
      dockerfile: server/Dockerfile
    restart: unless-stopped
    ports:
      - "8443:8443"
    environment:
      # Must bind 0.0.0.0 inside the container so host port mapping works (not only loopback in the container).
      LISTEN_ADDR: "0.0.0.0:8443"
      DATA_DIR: "/data"
      PUBLIC_BASE_URL: "${PUBLIC_BASE_URL:-http://localhost:8443}"
      ALLOWED_ORIGINS: "${ALLOWED_ORIGINS:-http://localhost:8443}"
      DATABASE_URL: "postgres://drivoly:${POSTGRES_PASSWORD:?set a strong database password}@db:5432/drivoly?sslmode=disable"
      JWT_SECRET: "${JWT_SECRET:?set a random secret of at least 32 characters}"
      ALLOW_REGISTER: "${ALLOW_REGISTER:-false}"
      BOOTSTRAP_ADMIN_EMAIL: "${BOOTSTRAP_ADMIN_EMAIL:?set the initial admin email}"
      BOOTSTRAP_ADMIN_PASSWORD: "${BOOTSTRAP_ADMIN_PASSWORD:?set a strong initial admin password}"
    volumes:
      - blobdata:/data
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8443/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s

volumes:
  pgdata: {}
  blobdata: {}
