# Producao: docker compose -f docker-compose.prod.yml up -d --build
#
# O container web escuta apenas em 127.0.0.1:8000 (nao expoe na internet).
# Configure o cPanel/Apache para fazer proxy de chat.souasf.com.br -> 127.0.0.1:8000

services:
  db:
    image: postgres:16-alpine
    container_name: chat_ia_db
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 10

  web:
    build: .
    container_name: chat_ia_web
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DJANGO_SETTINGS_MODULE: config.settings.production
      POSTGRES_HOST: db
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "127.0.0.1:8001:8000"
    command: >
      sh -c "python manage.py migrate --noinput &&
             python manage.py collectstatic --noinput &&
             gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 3 --timeout 60"

volumes:
  pgdata:
