Skip to content

Instantly share code, notes, and snippets.

@shantanoo-desai
Created July 20, 2023 12:07
Show Gist options
  • Save shantanoo-desai/291052ae8c118add9b5784a8c793e281 to your computer and use it in GitHub Desktop.
Save shantanoo-desai/291052ae8c118add9b5784a8c793e281 to your computer and use it in GitHub Desktop.
INIT_ADMIN_TOKEN with and without _FILE suffix env var problem for InfluxDBv2
INFLUXDBV2_ADMIN_USERNAME=admin
INFLUXDBV2_ADMIN_PASSWORD=testInfluxDB
INFLUXDBV2_ADMIN_TOKEN=testtoken
DOCKER_INFLUXDB_INIT_ORG=komponistorg
DOCKER_INFLUXDB_INIT_BUCKET=komponistdb
DOCKER_INFLUXDB_INIT_RETENTION=7d
TELEGRAF_MQTT_USERNAME=admin
TELEGRAF_MQTT_PASSWORD=test

Generate Compose file

docker compose -f docker-compose.influxdbv2.yml -f docker-compose.mosquitto.yml -f docker-compose.telegraf.yml config -o docker-compose.yml

Run

docker compose up -d

Logs

docker compose logs -f <influxdbv2/mosquitto/telegraf>

InfluxDBv2 Checks

docker compose exec -it influxdbv2 sh

Token Checks

curl -XGET "http://localhost:8086/api/v2/authorizations" \ 
      --header "Authorization: Token testtoken" \
      --header "Content-type: application/json"
services:
influxdbv2:
image: docker.io/influxdb:2.6-alpine
container_name: komponist_influxdbv2
environment:
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_ORG=${DOCKER_INFLUXDB_INIT_ORG}
- DOCKER_INFLUXDB_INIT_BUCKET=${DOCKER_INFLUXDB_INIT_BUCKET}
- DOCKER_INFLUXDB_INIT_RETENTION=${DOCKER_INFLUXDB_INIT_RETENTION}
- DOCKER_INFLUXDB_INIT_USERNAME_FILE=/run/secrets/influxdbv2_admin_username
- DOCKER_INFLUXDB_INIT_PASSWORD_FILE=/run/secrets/influxdbv2_admin_password
# - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN_FILE=/run/secrets/influxdbv2_admin_token # Uncomment this to test with Docker Secrets
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDBV2_ADMIN_TOKEN} # Comment this out when using Docker Secrets
- INFLUXD_HTTP_BIND_ADDRESS=0.0.0.0:8087
- INFLUXD_LOG_LEVEL=debug
ports:
- "8087:8087"
secrets:
- source: influxdbv2_admin_username
mode: 0444
- source: influxdbv2_admin_password
mode: 0444
- source: influxdbv2_admin_token
mode: 0444
security_opt:
- "no-new-privileges=true"
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
secrets:
influxdbv2_admin_username:
environment: INFLUXDBV2_ADMIN_USERNAME
influxdbv2_admin_password:
environment: INFLUXDBV2_ADMIN_PASSWORD
influxdbv2_admin_token:
environment: INFLUXDBV2_ADMIN_TOKEN
services:
mosquitto:
image: docker.io/eclipse-mosquitto:2.0.15
container_name: komponist_mosquitto
configs:
- mosquitto_conf
- mosquitto_acl
- mosquitto_users
entrypoint: mosquitto -c /mosquitto_conf
logging:
options:
max-size: "5m"
ports:
- "1883:1883"
security_opt:
- "no-new-privileges=true"
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
configs:
mosquitto_conf:
file: ./mosquitto.conf
mosquitto_users:
file: ./users
services:
telegraf:
image: telegraf:1.27-alpine
container_name: komponist_telegraf
command: --config /telegraf_conf
depends_on:
- influxdbv2
- mosquitto
environment:
- DOCKER_INFLUXDB_INIT_ORG=${DOCKER_INFLUXDB_INIT_ORG}
- DOCKER_INFLUXDB_INIT_BUCKET=${DOCKER_INFLUXDB_INIT_BUCKET}
secrets:
- source: influxdbv2_admin_token
mode: 0444
- source: mqtt_username
mode: 0444
- source: mqtt_password
mode: 0444
security_opt:
- "no-new-privileges=true"
configs:
- telegraf_conf
configs:
telegraf_conf:
file: ./telegraf.conf
secrets:
influxdbv2_admin_token:
environment: INFLUXDBV2_ADMIN_TOKEN
mqtt_username:
environment: TELEGRAF_MQTT_USERNAME
mqtt_password:
environment: TELEGRAF_MQTT_PASSWORD
listener 1883
protocol mqtt
# Authentication
allow_anonymous false
password_file /mosquitto_users
# Logging Configuration
log_timestamp true
log_type all
[agent]
debug = true
quiet = false
[[outputs.influxdb_v2]]
urls = ["http://komponist_influxdbv2:8087"]
token = "@{komponist_secretstore:influxdbv2_admin_token}"
organization = "${DOCKER_INFLUXDB_INIT_ORG}"
bucket = "${DOCKER_INFLUXDB_INIT_BUCKET}"
[[inputs.mqtt_consumer]]
servers = [ "tcp://komponist_mosquitto:1883" ]
topics = [ "test/readwrite" ]
username = "@{komponist_secretstore:mqtt_username}"
password = "@{komponist_secretstore:mqtt_password}"
[[secretstores.docker]]
id = "komponist_secretstore"
admin:$7$101$3jvHGANgDGEMQegd$ohTpyrO873j3PNk+DGq3/k0GfQlMRGwW7UhkRkINkDoi4ZWMTBwW1G781FxvjFe46GI5q16Zj0cNzcM83+W7HQ==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment