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 support for config file #135

Merged
merged 8 commits into from
Mar 28, 2024
Merged

Add support for config file #135

merged 8 commits into from
Mar 28, 2024

Conversation

Maelkum
Copy link
Contributor

@Maelkum Maelkum commented Mar 25, 2024

This PR adds support for loading configuration options from a config file besides using the CLI arguments.

It's possible to use both side by side, and in that case the CLI options take precedence and override the config file options. Default values for CLI flags are used where applicable.

Values are determined by (less to more important):

  1. Default CLI flags
  2. Config file options
  3. CLI flags

This might not be the final version, it might evolve further if it turns out to be too clunky for use from the dev side (user is fine IMO).

Complication comes from the fact that the CLI flags are flat (e.g. --address 127.0.0.1 --port 9000 --runtime-path ~/blockless/runtime), compared to the file which is structured. Currently the config file has four sections - log, connectivity, worker and head. In the example above, the address and port options live in the connectivity section, whereas the runtime-path lives in the worker section.

I didn't want to go the typical route of the group being embedded in the CLI flag (--connectivity-address, --connectivity-port, --worker-runtime-path) as it's pretty noisy. Instead, we define the group in which the flag lives and we map values to sections in code. This mapping is done in flags.go.

Example of a config file:

role: worker
concurrency: 10
workspace: /tmp/workspace
attributes: false

log:
  level: debug

connectivity:
  address: 127.0.0.1
  port: 9000
  private-key: ~/.b7s/path/to/priv/key.bin
  websocket: true


worker:
  runtime-path: ~/.local/blockless-runtime/bin
  cpu-percentage-limit: 0.8

For a more detailed reference of the config file, I added example.yaml.

@Maelkum Maelkum requested a review from dmikey March 25, 2024 17:56
@Maelkum Maelkum self-assigned this Mar 25, 2024
Copy link
Contributor

@dmikey dmikey left a comment

Choose a reason for hiding this comment

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

love this change!

@dmikey dmikey merged commit f5d478c into main Mar 28, 2024
2 checks passed
@dmikey dmikey deleted the support-for-config-files branch March 28, 2024 15:21
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.

2 participants