services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: mitaka
      POSTGRES_USER: mitaka
      POSTGRES_PASSWORD: mitaka
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mitaka -d mitaka"]
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  web:
    build: .
    env_file:
      - .env
    environment:
      DJANGO_SETTINGS_MODULE: config.settings.local
      DATABASE_URL: postgres://mitaka:mitaka@db:5432/mitaka
      REDIS_URL: redis://redis:6379/0
      CELERY_BROKER_URL: redis://redis:6379/0
      DJANGO_DEBUG: "True"
      DJANGO_ALLOWED_HOSTS: localhost,127.0.0.1,web
    volumes:
      - .:/app
      - media_data:/app/media
      - static_data:/app/staticfiles
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    expose:
      - "8000"

  nginx:
    image: nginx:1.27-alpine
    ports:
      - "8080:80"
    volumes:
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
      - static_data:/app/staticfiles:ro
      - media_data:/app/media:ro
    depends_on:
      - web

volumes:
  postgres_data:
  media_data:
  static_data:
