# docker-compose.yml

###################
### DEV COMPOSE ###
###################
services:
  # ----- Backend API (Uvicorn/FastAPI/Django etc.) -----
  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: MAIA-API
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    depends_on:
      - db
      - redis
    networks:
      - maia_network
    env_file:
      - ./.env
    restart: unless-stopped

  # ----- Celery Worker -----
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: MAIA-Worker
    command: celery -A core.celery_app worker --loglevel=info
    volumes:
      - .:/app
    depends_on:
      - db
      - redis
    env_file:
      - ./.env
    networks:
      - maia_network
    restart: unless-stopped

  # ----- Database (PostgreSQL) -----
  db:
    image: postgres:15 # Use a specific version
    container_name: MAIA-DB
    volumes:
      - db:/var/lib/postgresql/data # Persist data using a named volume
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
    env_file:
      - ./.env
    networks:
      - maia_network
    restart: unless-stopped

  # ----- Cache (Redis) -----
  redis:
    image: redis:7 # Use a specific version
    container_name: MAIA-Redis
    volumes:
      - redis_data:/data
    networks:
      - maia_network
    restart: unless-stopped

volumes:
  db: # Named volume for PostgreSQL data
    driver: local
  redis_data: # Named volume for Redis data
    driver: local

# ----- Network Definition -----
networks:
  maia_network:   # Define a custom bridge network
    driver: bridge