-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Environment Variable Override #4085
Conversation
I see this is failing for code coverage... I'm working on adding a test that will complete this. |
Could you explain the use case for this? |
Sure, basically it's because I'm using a fleet manager to deploy and manage applications on hosts. I can set up configurations for all of the computers to share settings in the fleet manager via environment variables and it performs the work of syncing those settings down to the devices. It's much easier for me to deploy changes across the entire fleet via environment variables rather than managing the configuration.yaml on a per device basis. |
I need to be able to manage settings on this service via Environment Variables. I've added the ability to override anything in the settings schema with a corresponding environment variable. e.g. to override settings.serial.port you can set ZIGBEE2MQTT_SERIAL_PORT=/dev/ttyS0 to override the mqtt username you can set ZIGBEE2MQTT_MQTT_USER=testusername This new addition will not perform any action on existing installations unless the matching environment variable is set. I have tested this setting string, number, boolean, object and array values.
… ensure 100% code coverage.
…es. Also realized that I was errantly applying the env variables to the defaults for testing. Understanding what this is doing more clearly I realize that should be clean.
1. Remove the test variables from the schema and defaults and manually reflect the tests in the test. 2. Rename environment variable base from ZIGBEE2MQTT_ to ZIGBEE2MQTT_CONFIG_
6b2f475
to
c5ad499
Compare
Can the overrides mutate configuration.yaml? |
@qm3ster the overrides to not mutate configuration.yaml. My addition of the env variable feature simply overrides settings after the configuration.yaml file has been loaded. In my set up devices.yaml and/or coordinator_backup.json would still be stored locally to the device. |
I need to be able to manage settings on this service via Environment Variables. I've added the ability to override anything in the settings schema with a corresponding environment variable.
e.g. to override settings.serial.port you can set ZIGBEE2MQTT_SERIAL_PORT=/dev/ttyS0
to override the mqtt username you can set ZIGBEE2MQTT_MQTT_USER=testusername
This new addition will not perform any action on existing installations unless the matching environment variable is set. I have tested this setting string, number, boolean, object and array values.