From 7b3f32d387b7b79b82a524f025773ae1a3e685e7 Mon Sep 17 00:00:00 2001 From: furyhawk Date: Sun, 12 Jul 2026 07:20:16 +0800 Subject: [PATCH] feat: add Grafana and Prometheus service configurations with Docker support --- makefile | 2 ++ swarm/grafana.yml | 38 ++++++++++++++++++++++++++++++++++++++ swarm/nodepad.yml | 3 +-- swarm/prometheus.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 swarm/grafana.yml create mode 100644 swarm/prometheus.yml diff --git a/makefile b/makefile index 44ec69c..9d13030 100644 --- a/makefile +++ b/makefile @@ -241,6 +241,8 @@ deploy-prometheus: pull } deploy-nodepad: pull { \ + echo "Building the nodepad image..." ;\ + docker build -t nodepad:latest -f ./swarm/inline.Dockerfile ./swarm ;\ echo "Deploying the nodepad stack..." ;\ set -a ;\ . ./swarm/.env ;\ diff --git a/swarm/grafana.yml b/swarm/grafana.yml new file mode 100644 index 0000000..07a8568 --- /dev/null +++ b/swarm/grafana.yml @@ -0,0 +1,38 @@ +volumes: + grafana_data: {} + +networks: + traefik-public: + external: true + +services: + grafana: + image: grafana/grafana:latest + environment: + - GF_SECURITY_ADMIN_USER=${ADMIN_USER:-admin} + - GF_SECURITY_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin} + - GF_USERS_ALLOW_SIGN_UP=false + - GF_INSTALL_PLUGINS=${GRAFANA_PLUGINS:-} + - GF_SERVER_ROOT_URL=https://grafana.${DOMAIN} + volumes: + - grafana_data:/var/lib/grafana + - /var/data/grafana/grafana.ini:/etc/grafana/grafana.ini:ro + - /var/data/grafana/provisioning:/etc/grafana/provisioning:ro + - /var/data/grafana/dashboards:/var/lib/grafana/dashboards:ro + networks: + - traefik-public + deploy: + mode: replicated + replicas: 1 + placement: + constraints: + - node.role == manager + labels: + - traefik.enable=true + - traefik.swarm.network=traefik-public + - traefik.constraint-label=traefik-public + - traefik.http.routers.grafana-https.rule=Host(`grafana.${DOMAIN?Variable not set}`) + - traefik.http.routers.grafana-https.entrypoints=https + - traefik.http.routers.grafana-https.tls=true + - traefik.http.routers.grafana-https.tls.certresolver=le + - traefik.http.services.grafana.loadbalancer.server.port=3000 diff --git a/swarm/nodepad.yml b/swarm/nodepad.yml index c214cd1..47b0cda 100644 --- a/swarm/nodepad.yml +++ b/swarm/nodepad.yml @@ -1,6 +1,6 @@ services: nodepad: - container_name: nodepad + image: nodepad:latest build: context: . dockerfile: inline.Dockerfile @@ -11,7 +11,6 @@ services: # Add your AI model API keys below if needed by the app: # - OPENAI_API_KEY=your_key_here # - ANTHROPIC_API_KEY=your_key_here - restart: unless-stopped networks: - traefik-public deploy: diff --git a/swarm/prometheus.yml b/swarm/prometheus.yml new file mode 100644 index 0000000..d712f25 --- /dev/null +++ b/swarm/prometheus.yml @@ -0,0 +1,40 @@ +volumes: + prometheus_data: {} + +networks: + traefik-public: + external: true + +services: + prometheus: + image: prom/prometheus:latest + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION:-30d}' + - '--web.console.libraries=/etc/prometheus/console_libraries' + - '--web.console.templates=/etc/prometheus/consoles' + - '--web.enable-lifecycle' + volumes: + - prometheus_data:/prometheus + - /var/data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro + - /var/data/prometheus/rules:/etc/prometheus/rules:ro + networks: + - traefik-public + deploy: + mode: replicated + replicas: 1 + placement: + constraints: + - node.role == manager + labels: + - traefik.enable=true + - traefik.swarm.network=traefik-public + - traefik.constraint-label=traefik-public + - traefik.http.routers.prometheus-https.rule=Host(`prometheus.${DOMAIN?Variable not set}`) + - traefik.http.routers.prometheus-https.entrypoints=https + - traefik.http.routers.prometheus-https.tls=true + - traefik.http.routers.prometheus-https.tls.certresolver=le + - traefik.http.services.prometheus.loadbalancer.server.port=9090 + - traefik.http.middlewares.prometheus-auth.basicauth.users=${ADMIN_USER?Variable not set}:${HASHED_PASSWORD?Variable not set} + - traefik.http.routers.prometheus-https.middlewares=prometheus-auth