version: "3.8"

services:
  db:
    image: postgres:15
    container_name: polisplexity_postgres
    restart: always
    ports:
      - "5434:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    env_file:
      - .env
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      retries: 5
      timeout: 5s

  web:
    build: .
    container_name: polisplexity_django
    restart: always
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8010:8002"
    env_file:
      - .env
    command: >
      sh -c "python manage.py migrate &&
             python manage.py collectstatic --noinput &&
             gunicorn polisplexity.wsgi:application --bind 0.0.0.0:8002 --workers=2 --timeout=180"
    volumes:
      - static_data:/app/static
      - media_data:/app/media
      - ./staticfiles:/app/staticfiles
      # - .:/app   # ←❌ No lo uses en producción: desactiva para evitar sobrescribir

volumes:
  pgdata:
  static_data:
  media_data:
