version: '3.8'

services:
  # Base de données PostgreSQL avec PostGIS
  db:
    image: postgis/postgis:15-3.3
    environment:
      POSTGRES_DB: senelec_db
      POSTGRES_USER: senelec_user
      POSTGRES_PASSWORD: senelec_password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - senelec_network

  # Redis pour cache et Celery
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - senelec_network

  # Application Django
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/app
      - media_files:/app/media
    ports:
      - "8000:8000"
    depends_on:
      - db
      - redis
    environment:
      - DEBUG=True
      - DB_HOST=db
      - REDIS_URL=redis://redis:6379/1
    networks:
      - senelec_network

  # Celery Worker
  celery:
    build: .
    command: celery -A senelec_backend worker -l info
    volumes:
      - .:/app
    depends_on:
      - db
      - redis
    environment:
      - DEBUG=True
      - DB_HOST=db
      - CELERY_BROKER_URL=redis://redis:6379/0
    networks:
      - senelec_network

  # Celery Beat (tâches programmées)
  celery-beat:
    build: .
    command: celery -A senelec_backend beat -l info
    volumes:
      - .:/app
    depends_on:
      - db
      - redis
    environment:
      - DEBUG=True
      - DB_HOST=db
      - CELERY_BROKER_URL=redis://redis:6379/0
    networks:
      - senelec_network

volumes:
  postgres_data:
  redis_data:
  media_files:

networks:
  senelec_network:
    driver: bridge