air
air copied to clipboard
Load environment variables from file
This pull request adds a new key env_file
to the configuration, the key specifies a file from which the environment variables for running bin
should be sourced.
If env_file
is set, the environment file is sourced every time the bin
is run, so that it works as expected when "env" is in include_ext
and the env file is updated.
The new feature was suggested in #47 and removes the need for less elegant solutions like the one suggested in #58.
Does it also work when cmd
and full_bin
run? Please add some docs on where it exactly applies. I guess some people might also prefer a separate vars file between cmd
vars and bin
/ full_bin
, so that will need two options.
I would suggest setting the default to ""
, so this is not enabled by default and does not break existing setups.
Another problem I see that this does not support multipe files, so it would not be useable as-is to me, as I use setups with at least two files, like this.
I think using cmd
or full_bin
will not work if you use air on e.g. Linux and Windows for the same project, as both environment are defining env variables differently. I think using a env_file
configuration parameter is the only way to make this feature for all operating systems available.
The implementation doesn't break existing setups, if the env_file
parameter is not specified it defaults to ""
(due to how the parameters are parsed) and thus no environment file is loaded. I added the env_file = ".env"
parameter in the example configuration as a form of documentation, but that file is meant to be modified by the user when doing the first configuration.
The environment file is loaded when running bin
/full_bin
but not when running cmd
. I think that this feature is much more important for bin
/full_bin
rather than cmd
, because the environment variables used in the build command can generally be safely committed in git, while the variables used at runtime may contain secrets; either way we could extend this implementation with another cmd_env_file
(or something similar) quite easily.
Multiple environment files are indeed not supported, I could extend this to accept a list of files instead of a single file.
Any updates on this?
I think using
cmd
orfull_bin
will not work if you use air on e.g. Linux and Windows for the same project, as both environment are defining env variables differently. I think using aenv_file
configuration parameter is the only way to make this feature for all operating systems available.
~I found that it also doesn't work on Mac Os, not sure what's missing but my environment variables aren't being brought over~
Solution is to use bin
instead of full_bin
. i.e bin=";APP_ENV= local APP_USER=me ./tmp/main"