services:
  db:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: squishybackup
      POSTGRES_USER: squishybackup
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
    volumes: ["database:/var/lib/postgresql/data"]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U squishybackup"]
      interval: 5s
      timeout: 5s
      retries: 12
    restart: unless-stopped
  web:
    image: docker.malyon.co.uk/squishybackup:latest
    environment:
      DATABASE_URL: postgresql+psycopg://squishybackup:${POSTGRES_PASSWORD}@db/squishybackup
      PUBLIC_URL: ${PUBLIC_URL:-http://localhost:8000}
      TZ: ${TZ:-UTC}
    ports: ["${HTTP_PORT:-8000}:8000"]
    volumes: ["state:/var/lib/squishybackup", "local-backups:/var/lib/proxmox-backup/local"]
    depends_on:
      db: {condition: service_healthy}
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz')"]
      interval: 10s
      timeout: 5s
      retries: 12
    restart: unless-stopped
  worker:
    image: docker.malyon.co.uk/squishybackup:latest
    command: ["python", "-m", "app.worker"]
    environment:
      DATABASE_URL: postgresql+psycopg://squishybackup:${POSTGRES_PASSWORD}@db/squishybackup
      PUBLIC_URL: ${PUBLIC_URL:-http://localhost:8000}
      TZ: ${TZ:-UTC}
    volumes: ["state:/var/lib/squishybackup", "local-backups:/var/lib/proxmox-backup/local"]
    depends_on:
      web: {condition: service_healthy}
    restart: unless-stopped
volumes:
  database:
  state:
  local-backups:
