version: '3.8'

services:
  db:
    image: postgres:15-alpine
    container_name: ${DB_CONTAINER_NAME:-django_core_db}
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_NAME:-django_core_db}
      POSTGRES_USER: ${DB_USER:-postgres}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "${DATABASE_EXPOSE_PORT:-5432}:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d ${DB_NAME:-django_core_db}"]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 10s

  web:
    build:
      context: ..
      dockerfile: deployments/Dockerfile
    container_name: ${APP_CONTAINER_NAME:-django_core_app}
    restart: unless-stopped
    env_file:
      - .env
    environment:
      - DB_HOST=db
      - DB_PORT=5432
    ports:
      - "${PORT:-8000}:8000"
    depends_on:
      db:
        condition: service_healthy

volumes:
  postgres_data:
