# Development override: point the web service to rad/.env.dev and map nginx to
# non-privileged host ports so you can run without sudo.

services:
  web:
    env_file:
      - ../.env.dev
    # Development: run Django's autoreloading development server instead of
    # the production entrypoint/gunicorn. Mount the repository into the
    # container so code edits on the host trigger Django's autoreload.
    entrypoint: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
    # Clear any command set by the prod compose file (which would be passed
    # as an extra argument to manage.py). Setting an empty command prevents
    # the image `command` from being appended to the entrypoint.
    command: []
    volumes:
      - ../:/usr/src/app:cached
      # Mount the app log directory so logs are visible on the host at ./logs
      - ../logs:/var/log/rad
  nginx:
    # Development nginx override: mount a simplified config that does not
    # reference LetsEncrypt certs so the container can start without real
    # certificates present on the host.
    image: nginx:1.25-alpine
    volumes:
      - ../deploy/nginx/dev.conf:/etc/nginx/conf.d/default.conf:ro

  loki:
    image: grafana/loki:2.8.2
    command: -config.file=/etc/loki/local-config.yaml
    ports:
      - "3100:3100"
    volumes:
      - ./loki-config/local-config.yaml:/etc/loki/local-config.yaml:ro
      - ./loki-data:/loki
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:3100/ready || exit 1"]
      interval: 5s
      timeout: 3s
      retries: 6

  promtail:
    image: grafana/promtail:2.8.2
    volumes:
      - ../logs:/var/log/rad:ro
      - ./promtail-config.yml:/etc/promtail/promtail-config.yml:ro
    command: -config.file=/etc/promtail/promtail-config.yml
    depends_on:
      - loki
    restart: unless-stopped

  grafana:
    image: grafana/grafana:10.2.0
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    volumes:
      - grafana-data:/var/lib/grafana
    depends_on:
      loki:
        condition: service_healthy
    restart: unless-stopped

volumes:
  grafana-data:
  loki-data:

