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

  redis:
    image: redis:7-alpine

  web:
    build: ./app
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    env_file: .env
    ports:
      - "8081:8000"
    volumes:
      - ./app:/app
    command: ["gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3"]

  worker:
    build: ./app
    env_file: .env
    depends_on:
      - redis
      - db
    command: ["celery", "-A", "core", "worker", "-l", "info"]

  beat:
    build: ./app
    env_file: .env
    depends_on:
      - redis
      - db
    command: ["celery", "-A", "core", "beat", "-l", "info"]

  grampsweb:
    image: ghcr.io/gramps-project/grampsweb:latest
    ports:
      - "8090:80"
    environment:
      - GRAMPSWEB_SECRET_KEY=${GRAMPSWEB_SECRET_KEY}
      - GRAMPSWEB_ADMIN_EMAIL=${GRAMPSWEB_ADMIN_EMAIL}
      - GRAMPSWEB_ADMIN_PASSWORD=${GRAMPSWEB_ADMIN_PASSWORD}
    volumes:
      - gramps_data:/app/data

volumes:
  dbdata:
  gramps_data:
