Environment variables for configuration

Hi

In the documentation of chirpstack Configuration - ChirpStack open-source LoRaWAN® Network Server documentation it says:

Values in the configuration file can be substituted by environment variables. Example:

[integration.mqtt]
  server="tcp://$MQTT_BROKER_HOST:1883/"
  json=true

In the above example, $MQTT_BROKER_HOST gets replaced if the MQTT_BROKER_HOST variable is set, with the value of this environment variable.

But in the documentation of the gateway-bridge Configuration - ChirpStack open-source LoRaWAN® Network Server documentation it says:

Although using the configuration file is recommended, it is also possible to use environment variables to set configuration variables. Configuration dots . are replaced with double underscores __.

Example:

[backend.semtech_udp]
udp_bind="0.0.0.0:1700"

Can be set using the environment variable:

BACKEND__SEMTECH_UDP__UDP_BIND="0.0.0.0:1700"

If I understand correctly, on the gateway-brigde side, I can omit an entry on the toml file and pass it instead via an environment variable as longs as dots are replaced with double underscores. But does this also apply in the chirpstack service as well?

In chirpstack I want to set the value of the api.secret in the .env file (I want to deploy it with docker), so should I do this?

# .env file

API_SECRET=......


---------

# docker-compose.yml

services:
  chirpstack:
    image: chirpstack/chirpstack:4
    ...
    environment:
      ...
      - API_SECRET=${API_SECRET}


---------------


# configuration/chirpstack/chirpstack.toml

[api]
  bind="0.0.0.0:8080"
  secret="${API_SECRET}"

or can I also do this?

# .env file

API_SECRET=......


---------

# docker-compose.yml

services:
  chirpstack:
    image: chirpstack/chirpstack:4
    ...
    environment:
      ...
      - API__SECRET=${API_SECRET}


---------------


# configuration/chirpstack/chirpstack.toml

[api]
  bind="0.0.0.0:8080"
  
  # omitting it here, passed via API__SECRET
  # secret="${API_SECRET}"

Thanks.

Unfortunately, you’ve hit some confusion due to the Gateway Bridge using the older v3-style environmental variable syntax that isn’t available in the newer v4 ChirpStack service. While you can use some substitution, as noted in your first example, you will likely have the most success mounting your configuration directory in Docker and then using minimal, site-specific variable substitutions, IMHO.

you will likely have the most success mounting your configuration directory in Docker and then using minimal, site-specific variable substitutions, IMHO.

I plan to mount the configuration directory. I’ve made a fork of chirpstack/chirpstack-docker.git and I’m going to commit my changes, but I don’t want to store the secret directly in the repository. That’s why I want to use the .env file which is not going to be committed.

If my first example (the one with secret="${API_SECRET}") works, then I’m more than happy to use that. I just found strange how inconsistent he environment variables sections are in the documentation of both services.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.