version: '3.8'

services:
  gitea-db:
    image: postgres:15
    # Usará el nombre de tu .env (django_db_local)
    container_name: ${DB_CONTAINER_NAME:-django_db_dev}
    restart: always
    environment:
      POSTGRES_DB: ${DB_NAME:-gitea}
      POSTGRES_USER: ${DB_USER:-gitea}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-gitea}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    # --- ESTO ES LO QUE FALTA ---
    ports:
      - "${DATABASE_EXPOSE_PORT:-5432}:5432"
    # ----------------------------
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-gitea} -d ${DB_NAME:-gitea}"]
      interval: 5s
      timeout: 5s
      retries: 5

  web:
    build:
      context: ..
      dockerfile: deployments/Dockerfile
    container_name: ${APP_CONTAINER_NAME:-django_app_dev}
    restart: always
    env_file:
      - .env
    environment:
      - DEBUG=${DEBUG_MODE:-1}
      # IMPORTANTE: Este nombre debe coincidir con el nombre del servicio arriba (gitea-db)
      - DB_HOST=gitea-db  
      - DB_PORT=5432
    ports:
      - "${PORT:-8000}:8000"
    depends_on:
      gitea-db:
        condition: service_healthy

volumes:
  postgres_data: