version: '3.8'

services:
  web:
    build: .
    command: >
      sh -c "python manage.py migrate &&
             python manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    env_file:
      - .env  # Load environment variables from .env file
    environment:
      # Override specific variables or set defaults
      - DATABASE_HOST=db
      - DATABASE_NAME=${DATABASE_NAME:-reviewsdb}
      - DATABASE_USER=${DATABASE_USER:-postgres}
      - DATABASE_PASSWORD=${DATABASE_PASSWORD:-postgres}
      - SECRET_KEY=${SECRET_KEY:-changeme}
      - DEBUG=${DEBUG:-1}
      - SITE_URL=${SITE_URL:-https://localhost:8000}
    depends_on:
      - db

  db:
    image: postgres:15
    environment:
      POSTGRES_USER: ${DATABASE_USER:-postgres}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-postgres}
      POSTGRES_DB: ${DATABASE_NAME:-reviewsdb}
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata: