services:
  db:
    image: postgres:16-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-shooter_hub}
      POSTGRES_USER: ${POSTGRES_USER:-shooter}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-shooter_secret}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-shooter} -d ${POSTGRES_DB:-shooter_hub}"]
      interval: 5s
      timeout: 5s
      retries: 5

  web:
    build: .
    command: >
      sh -c "python manage.py migrate --noinput &&
             python manage.py compilemessages &&
             python manage.py create_default_admin &&
             python manage.py import_weapons_csv /app/weapon.csv &&
             python manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    depends_on:
      db:
        condition: service_healthy
    env_file:
      - .env

  frontend:
    image: nginx:alpine
    volumes:
      - ./frontend:/usr/share/nginx/html:ro
      - ./frontend/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    ports:
      - "5173:80"
    depends_on:
      - web

volumes:
  postgres_data:
