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

feat(cmd/influxd): add print-config subcommand to support automation #20524

Merged
merged 2 commits into from
Jan 19, 2021

Conversation

danxmoran
Copy link
Contributor

Closes #20517

This command is meant to support our Docker entry-point in two ways.

First, in our documentation for how to customize the influxd config we can advise running influxd print-config to generate a starting template file. This mirrors the existing docs for our 1.x image.

Second, we want the container entry-point to support running setup scripts mounted by the user, but only if the DB hasn't already been set up. To do this in a robust way while also supporting custom config / env vars / CLI args, we need to be able to determine the final values of configs like the bolt path & HTTP bind address. We can use influxd print-config with the --key-name option to do this.

If the user runs something like:

docker run -e INFLUXD_OPT2=val2 influxdb:2.0 --opt1 val1

Then within our entrypoint script we can run:

opt1=$(influxd print-config --key-name opt1 ${@}) # Expected output: val1
opt2=$(influxd print-config --key-name opt2 ${@}) # Expected output: val2

@danxmoran danxmoran changed the title fix(influxd): add print-config subcommand to support automation feat(influxd): add print-config subcommand to support automation Jan 15, 2021
@danxmoran danxmoran force-pushed the dm-influxd-print-config-20517 branch from c67acea to b3dd742 Compare January 15, 2021 18:32
Use: "print-config",
Short: "Print the full influxd config resolved from the current environment",
Long: `
Print config (in YAML) that the influxd server would use if run with the current flags/env vars/config file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the config file read happen in this code path (I'm sure it does, looking to be educated)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli.NewCommand (called here) is where config & env get loaded into the Viper instance. cli.BindOptions (called here) is where the CLI flags get bound to local vars, with any config/env values injected as defaults.

@danxmoran danxmoran changed the title feat(influxd): add print-config subcommand to support automation feat(cmd/influxd): add print-config subcommand to support automation Jan 15, 2021
@danxmoran danxmoran force-pushed the dm-influxd-print-config-20517 branch from d551cb5 to 134ebe2 Compare January 19, 2021 15:07
Copy link
Contributor

@lesam lesam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@danxmoran danxmoran merged commit e970aae into master Jan 19, 2021
@danxmoran danxmoran deleted the dm-influxd-print-config-20517 branch January 19, 2021 20:34
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.

Add influxd subcommand to print config resolved from the environment
2 participants