-
Notifications
You must be signed in to change notification settings - Fork 13
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
chore: make config overridable by environment variables #2
base: master
Are you sure you want to change the base?
chore: make config overridable by environment variables #2
Conversation
dotenv is often used as a method to override variables defaults, but defaults are still hardcoded. |
It all depend of the context. But this particular
The sole purpose of This pattern is used and recommended by Symfony (leading PHP framework / industry standard) since its version 4.
I'm used to working with this pattern and find it pretty convenient since all environment variable defaults are listed in a single file. If you feel more comfortable with just a config file and no // config.ts
export const TIMEOUT = process.env.TIMEOUT ? parseInt(<string>process.env.TIMEOUT) : 24 * 60 * 60 * 1000;
export const RETRY_INTERVAL = process.env.RETRY_INTERVAL ? parseInt(<string>process.env.RETRY_INTERVAL) : 10000;
export const POLLING_INTERVAL = process.env.POLLING_INTERVAL ? parseInt(<string>process.env.POLLING_INTERVAL ) : 30000;
... ; but we would miss the opportunity to list other vars that are not present in the config, for convenience for advanced users:
We could also add all those vars is the config file but it is more rework, if you agree. Tell me what you think :) |
GAS_STATION_API_REQUEST_TIMEOUT_MS=10000 | ||
|
||
# When loading wallet from MNEMONIC | ||
MNEMONIC= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea to have the option to set the MNEMONIC here, some users might set this and it's definitely very unsafe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very unsafe indeed but the only way as far as I know to start the node without a TTY, in a CI pipeline for instance. We could provide an option to use Docker Swarm Secrets or Kubernetes File Secrets with an environment variables like MNEMONIC_FILE
targeting the path of a mounted file in the container, but it probably is worth opening a whole new issue for this. The MNEMONIC
env var is an undocumented feature but it could be nice to reference the variable here for advanced users who are able to add other layers of security to prevent leaks until a better solution is offered. We could even write a warning in the comment like so:
# [UNSAFE, DO NOT USE] When loading wallet from MNEMONIC
What do you think?
MNEMONIC_PATH= | ||
|
||
# When loading wallet from SEED | ||
SEED= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem as MNEMONIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting contributions, like last time 🙂
ce22f0a
to
53f3eb2
Compare
Updated branch to resolve conflicts with master. |
53f3eb2
to
c0d6d43
Compare
Rebased onto master. |
Hi!
I have a use case where I need to run the node with some config values that differ from the predefined constants in config.ts.
To do so we currently need to clone the repository, edit the file config file, re-build the Docker image, and repeat for every new release, which is quite tedious.
In this PR I introduced a new
.env
file which contains default values, and set-up thedotenv
module which loads those default values or the ones already defined by the user in the environment.The
.env
file contains every variable defined inconfig.ts
plus all the other environment variables that are used in the app. Doing so allows new users to easily get a grasp on allowed environment variable with a quick glance at the file (self-documenting).Please tell me if you have any question or you would like to see more improvement to the work I've done. Thanks!