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

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  web:
    build: .
    env_file: .env
    environment:
      RUN_MIGRATIONS: "1"
    command: gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 3 --reload
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

  worker:
    build: .
    env_file: .env
    command: celery -A config worker -l info
    volumes:
      - .:/app
    depends_on:
      - db
      - redis

  beat:
    build: .
    env_file: .env
    command: celery -A config beat -l info
    volumes:
      - .:/app
    depends_on:
      - db
      - redis

volumes:
  pgdata:
