version: "3.8"

services:
  db:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h db"]
      retries: 5
      start_period: 10s
      interval: 5s
      timeout: 5s

  web:
    image: bugsink/bugsink:latest
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    expose:
      - 8000
    environment:
      SECRET_KEY: ${SECRET_KEY}
      CREATE_SUPERUSER: ${CREATE_SUPERUSER}
      PORT: 8000
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
      BEHIND_HTTPS_PROXY: ${BEHIND_HTTPS_PROXY}
      BASE_URL: ${BASE_URL}
    healthcheck:
      test:
        [
          "CMD-SHELL",
          'python -c ''import requests; requests.get("http://localhost:8000/").raise_for_status()''',
        ]
      interval: 5s
      timeout: 20s
      retries: 10

volumes:
  db-data:
