forge icon indicating copy to clipboard operation
forge copied to clipboard

Support for environment variables

Open falzm opened this issue 8 years ago • 4 comments

It would be super handy if Forge could support calling environment variables from configuration files, for example:

some_var = "blah"
some_section {
  base_dir = "%env{HOME}/myapp" # would resolve to "/home/user/myapp" after parsing
}

The token format is up to you (suggestions: %env{VARIABLE}, $env{VARIABLE}...), this is just to illustrate the idea :)

falzm avatar Sep 10 '16 11:09 falzm

Note: a non-existent referenced environment variable would return an empty string instead of an error, if possible.

falzm avatar Sep 10 '16 11:09 falzm

hey @falzm sorry that it took me so long to respond here, unfortunately I stared at it for far too long in my email :(

I originally had a PR open previously for adding in environment variables #19, it was closed as it was previously determined that using environment variables for configuration should be left to the application rather than forge. As I think more and more about 12-factor apps, and thinking back on this, I am more than willing to open discussions again.

My thinking specific with 12fa is that I really like the nested config file approach, rather than having to do config.some_namespaced_config_name, you get config.some.namespaced.config.name, but still being able to override this from an environment variable would be nice.

Some options (syntax TDB) but:

some_section {
    value = ${SOME_SECTION_VALUE : "default value"}
}

Or maybe, we make an option that will just override settings from environment variables.

For example:

some_section {
    value = "default value"
}

When the parser gets to value it'll look to see if SOME_SECTION_VALUE environment variable exists and override the default value with that value.

I think both of these examples are a little different from what you are proposing which is more support for interpolation of environment variables in configuration options, but maybe being able to do SOME_SECTION_BASE_DIR=$HOME/myapp ./app is just as useful for your use case?

brettlangdon avatar Sep 16 '16 16:09 brettlangdon

Hi @brettlangdon

Yes, that would work for me :)

falzm avatar Sep 17 '16 08:09 falzm

@brettlangdon please let know if you're adding env variables support.

jeevatkm avatar Sep 26 '16 21:09 jeevatkm