version: '3.8'
name : apo_campania_backend_python
services:
  db:
    image: postgres:15
    container_name: apo_campania_postgres_db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: apo_campania_db
    volumes:
      - apo_postgres_data:/var/lib/postgresql/data
    restart: always
    networks:
      - APO-Campania-Backend-Network

  app:
    container_name : apo_campania_backend_app
    build: .
    ports:
      - "8003:8003"
    depends_on:
      - db
      - redis
    env_file:
      - .env
    # volumes:
    #   - ./app:/code/app
    #   - ./scripts:/code/scripts
    #   - ./alembic.ini:/code/alembic.ini
    #   - ./migrations:/code/migrations
    #   - ./entrypoint.sh:/code/entrypoint.sh
    #   - ./static/logs:/code/static/logs
    # command: uvicorn app.main:app --host 0.0.0.0 --port 8003 --reload
    restart: always
    networks:
      - APO-Campania-Backend-Network

  redis:
    container_name: apo_campania_redis
    image: redis:7-alpine
    # ports:
      # - "6389:6379"
      # - "6379:6379"
    volumes:
      - apo_redis_data:/data
    command: redis-server --appendonly yes --appendfsync everysec
    restart: always
    networks:
      - APO-Campania-Backend-Network

  celery:
    build: .
    container_name: apo_campania_celery_worker
    # command: celery -A app.tasks.celery_app worker --loglevel=INFO --concurrency=4 --max-tasks-per-child=1000
    # OLD: --logfile=/dev/stdout (only console output)
    # NEW: Logs to both file and console
    command: celery -A app.tasks.celery_app worker --loglevel=INFO --concurrency=12 --logfile=/code/static/logs/celery_worker.log
    depends_on:
      - redis
      - db
    env_file:
      - .env
    volumes:
      - ./app:/code/app
      - ./static/logs:/code/static/logs
    restart: always
    networks:
      - APO-Campania-Backend-Network
    # healthcheck:
    #   test: ["CMD-SHELL", "celery -A app.tasks.celery_app inspect ping"]
    #   interval: 30s
    #   timeout: 10s
    #   retries: 3

  celery-beat:
    build: .
    container_name: apo_campania_celery_beat
    # Added logfile parameter to write logs to file
    command: celery -A app.tasks.celery_app beat --loglevel=info --logfile=/code/static/logs/celery_beat.log
    depends_on:
      - redis
      - db
      - celery
    env_file:
      - .env
    volumes:
      - ./app:/code/app
      - ./static/logs:/code/static/logs
    restart: always
    networks:
      - APO-Campania-Backend-Network

volumes:
  apo_postgres_data:
  apo_redis_data:

networks:
  APO-Campania-Backend-Network:
    driver: bridge








# version: '3.8'
# name : apo_campania_backend_python
# services:
#   db:
#     image: postgres:15
#     container_name: apo_campania_postgres_db
#     environment:
#       POSTGRES_USER: postgres
#       POSTGRES_PASSWORD: postgres
#       POSTGRES_DB: apo_campania_db
#     volumes:
#       - apo_postgres_data:/var/lib/postgresql/data

#   redis:
#     container_name: apo_campania_redis
#     image: redis:7-alpine
#     ports:
#       - "6389:6379"
#     volumes:
#       - apo_redis_data:/data

#   app:
#     container_name : apo_campania_backend_app
#     build: .
#     ports:
#       - "8003:8003"
#     depends_on:
#       - db
#       - redis
#     env_file:
#       - .env
#     volumes:
#       - ./app:/code/app
#       - ./scripts:/code/scripts
#       - ./alembic.ini:/code/alembic.ini
#       - ./migrations:/code/migrations
#       - ./entrypoint.sh:/code/entrypoint.sh
#     command: uvicorn app.main:app --host 0.0.0.0 --port 8003 --reload

#   worker:
#     container_name: apo_campania_celery_worker
#     build: .
#     depends_on:
#       - redis
#       - db
#     env_file:
#       - .env
#     # command: celery -A app.tasks.celery_app.celery_app worker --loglevel=info
#     command: celery -A app.tasks.celery_app worker --loglevel=info

#   beat:
#     container_name: apo_campania_celery_beat
#     build: .
#     depends_on:
#       - redis
#       - db
#     env_file:
#       - .env
#     # command: celery -A app.tasks.celery_app.celery_app beat --loglevel=info
#     command: celery -A app.tasks.celery_app beat --loglevel=info

# volumes:
#   apo_postgres_data:
#   apo_redis_data:

# networks:
#   APO-Campania-Backend-Network:
#     driver: bridge