From eb29983999de2b91dee4d7ce7ff125b62d12cd4a Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 30 Jan 2025 14:13:42 +0100 Subject: [PATCH] feat: enforce env vars with run.sh to start prometheus --- docker-compose.yml | 5 ++++- .../{prometheus.yml => prometheus.yml.example} | 0 prometheus/run.sh | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) rename prometheus/{prometheus.yml => prometheus.yml.example} (100%) create mode 100755 prometheus/run.sh diff --git a/docker-compose.yml b/docker-compose.yml index 079db670..b00e9506 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -152,9 +152,12 @@ services: image: prom/prometheus:${PROMETHEUS_VERSION:-v2.46.0} user: ":" networks: [dvnode] + environment: + PROM_REMOTE_WRITE_TOKEN: ${PROM_REMOTE_WRITE_TOKEN} volumes: - - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + - ./prometheus:/etc/prometheus - ./data/prometheus:/prometheus + entrypoint: /etc/prometheus/run.sh restart: unless-stopped grafana: diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml.example similarity index 100% rename from prometheus/prometheus.yml rename to prometheus/prometheus.yml.example diff --git a/prometheus/run.sh b/prometheus/run.sh new file mode 100755 index 00000000..4fcc9819 --- /dev/null +++ b/prometheus/run.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ -z "$PROM_REMOTE_WRITE_TOKEN" ] +then + echo "\$PROM_REMOTE_WRITE_TOKEN variable is empty" >&2 + exit 1 +fi + +sed "s|\$PROM_REMOTE_WRITE_TOKEN|${PROM_REMOTE_WRITE_TOKEN}|g" \ + /etc/prometheus/prometheus.yml.example > /etc/prometheus/prometheus.yml + +/bin/prometheus \ + --config.file=/etc/prometheus/prometheus.yml