Skip to content
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

Merged
merged 6 commits into from
Aug 13, 2020

Conversation

trankin
Copy link
Contributor

@trankin trankin commented Aug 11, 2020

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.

@trankin
Copy link
Contributor Author

trankin commented Aug 11, 2020

I see this is failing for code coverage... I'm working on adding a test that will complete this.

@Koenkk
Copy link
Owner

Koenkk commented Aug 12, 2020

Could you explain the use case for this?

@trankin
Copy link
Contributor Author

trankin commented Aug 12, 2020

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.

lib/util/settings.js Outdated Show resolved Hide resolved
lib/util/settings.js Outdated Show resolved Hide resolved
@trankin trankin requested a review from Koenkk August 13, 2020 18:34
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.
…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_
@Koenkk Koenkk force-pushed the feature/environment_variables branch from 6b2f475 to c5ad499 Compare August 13, 2020 19:40
test/settings.test.js Outdated Show resolved Hide resolved
@trankin trankin requested a review from Koenkk August 13, 2020 20:22
Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this pull request Aug 13, 2020
Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this pull request Aug 13, 2020
@Koenkk
Copy link
Owner

Koenkk commented Aug 13, 2020

@Koenkk Koenkk changed the base branch from master to dev August 13, 2020 21:50
@Koenkk Koenkk merged commit 0852495 into Koenkk:dev Aug 13, 2020
@trankin trankin deleted the feature/environment_variables branch August 13, 2020 21:57
@qm3ster
Copy link
Contributor

qm3ster commented Sep 23, 2020

Can the overrides mutate configuration.yaml?
@trankin what do you do to manage coordinator_backup.json and devices.yaml(or corresponding section of configuration.yaml) in your fleet?

@trankin
Copy link
Contributor Author

trankin commented Sep 23, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants