Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Support config files with viper #4558

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

Merged
merged 43 commits into from
Oct 21, 2022
Merged

feat: Support config files with viper #4558

merged 43 commits into from
Oct 21, 2022

Conversation

f0ssel
Copy link
Contributor

@f0ssel f0ssel commented Oct 14, 2022

This supports intaking settings for coder server from a config file named server.yaml in the --global-config directory. It changes the way we do flags to be config first, meaning all settings have a config value and all settings can optionally have a flag.

We use viper to first set default values defined in the schema for each setting. We look for a config file if that exists and load that in, then we bind each setting to a cli flag if it's defined. Viper automatically maps to environment variables. The intake order is the following:
viper defaults from schema < values in server.yaml < coder env variable < cli flag

Checkout cli/deployment/config.go for a view of the new deployment config schema.

Net negative loc 🔥

Proposing the following breaking Changes:

  • (hidden) Env var CODER_INMEMORY -> CODER_IN_MEMORY_DATABASE to match parity with config value in_memory_database
  • (hidden) Env var CODER_TEMPLATE_AUTOIMPORT -> CODER_AUTO_IMPORT_TEMPLATES

@f0ssel f0ssel force-pushed the f0ssel/cli-gen branch 2 times, most recently from 841a3b7 to b44978a Compare October 20, 2022 21:18
@f0ssel f0ssel marked this pull request as ready for review October 21, 2022 02:42
@f0ssel f0ssel requested a review from a team as a code owner October 21, 2022 02:42
@f0ssel f0ssel requested review from BrunoQuaresma, kylecarbs, a team and Emyrk and removed request for a team October 21, 2022 02:42
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

This is awesome.

Few questions:

  1. How do I structure objects like arrays with keys and values?
  2. I see we don't generate a default config right now... should we?

"github.com/coder/coder/codersdk"
)

func newConfig() codersdk.DeploymentConfig {
Copy link
Member

Choose a reason for hiding this comment

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

How would I structure an object array in this form?

eg.

gitauth:
- client_id: ...
- client_secret: ...

@kylecarbs
Copy link
Member

Oh @f0ssel there's an empty server.yaml at the root which I assume is just a mistake.

@f0ssel
Copy link
Contributor Author

f0ssel commented Oct 21, 2022

@kylecarbs look at how derp server path is configured. Basically the path for the config can use dot notation to make objects, but each field will still be a top level field in the schema.

I think generating a default is not a bad idea. Where do you think something like that would live in the repo?

@kylecarbs
Copy link
Member

I think a default can be done later tbh, this seems good to merge as-is so we can unblock.

Just to confirm, can you manually test a few bespoke existing options to make sure that the environment variables are an exact match? I assume we're kinda hoping that Viper doesn't change anything right?

@kylecarbs
Copy link
Member

@f0ssel I mean a structured array, not an object.

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

This came out nice 👍

@f0ssel
Copy link
Contributor Author

f0ssel commented Oct 21, 2022

Just to confirm, can you manually test a few bespoke existing options to make sure that the environment variables are an exact match? I assume we're kinda hoping that Viper doesn't change anything right?

Yes, I actually do think a few may change - I think this may be ok if we can document it since otherwise we'll have to manually specify overrides which gets annoying and people who know and expect the viper default will be confused. If I document a list of the changes would that work?

@f0ssel f0ssel requested a review from kylecarbs October 21, 2022 19:00
@f0ssel f0ssel enabled auto-merge (squash) October 21, 2022 19:14
@f0ssel
Copy link
Contributor Author

f0ssel commented Oct 21, 2022

We are gonna merge this without the structured array support to unblock other work and will make updates soon for it.

@f0ssel f0ssel merged commit c8e299c into main Oct 21, 2022
@f0ssel f0ssel deleted the f0ssel/cli-gen branch October 21, 2022 19:26
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants