services:
  rstmdb:
    build:
      context: .
      dockerfile: Dockerfile
    image: rstmdb:latest
    container_name: rstmdb
    restart: unless-stopped
    ports:
      - "7401:7401"
      - "9090:9090"
    volumes:
      - rstmdb-data:/data
      # Optional: Mount config file
      - ./config.dev.yaml:/config/config.yaml:ro
      # Optional: Mount TLS certificates
      # - ./certs:/certs:ro
    environment:
      RUST_LOG: info
      RSTMDB_BIND: 0.0.0.0:7401
      RSTMDB_DATA: /data
      # Metrics
      RSTMDB_METRICS_ENABLED: "true"
      RSTMDB_METRICS_BIND: "0.0.0.0:9090"
      # Optional: Enable authentication
      # RSTMDB_AUTH_REQUIRED: "true"
      # RSTMDB_AUTH_TOKEN_HASH: "sha256-hash-of-your-token"
      # Optional: Use config file
      RSTMDB_CONFIG: /config/config.yaml
      # Optional: Compaction settings
      # RSTMDB_COMPACT_ENABLED: "true"
      # RSTMDB_COMPACT_EVENTS: "10000"
      # RSTMDB_COMPACT_SIZE_MB: "100"
    healthcheck:
      test: ["CMD", "rstmdb-cli", "-s", "127.0.0.1:7401", "ping"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 5s
    deploy:
      resources:
        limits:
          memory: 512M
        reservations:
          memory: 128M

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    volumes:
      - ./grafana/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    ports:
      - "9091:9090"
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--web.enable-lifecycle'
    depends_on:
      - rstmdb

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    volumes:
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
      - ./grafana/dashboards:/var/lib/grafana/dashboards:ro
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /var/lib/grafana/dashboards/rstmdb.json
      GF_USERS_ALLOW_SIGN_UP: "false"
    depends_on:
      - prometheus

volumes:
  rstmdb-data:
    driver: local
  prometheus-data:
    driver: local
  grafana-data:
    driver: local
