version: "3.8"

services:
  fastapi:
    build: .
    container_name: fastapi_app
    restart: "no"
    depends_on:
      - db
      - mailpit
    env_file:
      - .env
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    networks:
      - mynetwork
    # command: ["fastapi", "dev", "--app", "app.main:app"]  # Se asegura de que se use fastapi dev
    command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

  scheduler_worker:
    build: .
    container_name: scheduler_worker
    restart: "no"
    depends_on:
      - db
      - mailpit
    env_file:
      - .env
    environment:
      - WORKER_TYPE=scheduler
    volumes:
      - .:/app
    networks:
      - mynetwork
    command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
    # command: ["python", "-m", "app.core.scheduler_worker"]

  db:
    image: postgres:17.2
    container_name: postgres_db
    restart: "no"
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin
      POSTGRES_DB: postgres
    ports:
      - "5434:5432"
    networks:
      - mynetwork
    volumes:
      - postgres_data:/var/lib/postgresql/data

  mailpit:
    image: axllent/mailpit
    container_name: mailpit_service
    restart: "no"
    ports:
      - "8030:8025"
      - "1030:1025"
    networks:
      - mynetwork
  
  redis:
    image: redis:7
    container_name: redis
    ports:
      - "6379:6379"
    networks:
      - mynetwork

networks:
  mynetwork:
    driver: bridge

volumes:
  postgres_data: