简体   繁体   中英

Distillery not replacing environment variables

In my umbrella project using distillery for releases, I have a db app config with the following:

config :main, Main.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "${DB_USERNAME}",
  password: "${DB_PASSWORD}",
  database: "${DB_NAME}",
  hostname: "${DB_HOST}",
  pool_size: 10

As I have set REPLACE_OS_VARS=true in my build, the environment vars are read correctly configures the database.

I have a similar set up in an email app which has the following config:

config :email, from_email: "${FROM_EMAIL}"

I am then looking to access this from inside my email app, like so:

@from_email Application.get_env(:email, :from_email)

But the value of @from_email is "${FROM_EMAIL}" not the environment variable I set for FROM_EMAIL .

I am not too familiar with how distillery works and am unsure how passing in these environment variables in these similar ways is causing it to be read differently.

Insight as to why this may be happening would be greatly appreciated.


EDIT :

We are able to pass the $FROM_EMAIL environment variable in when distillery compiles, but we would like to pass this in at run time. We are able to do this in the db app, but not in the email app for some reason.

Code directly inside the module definition (ie outside def ) is evaluated at compile time. You'll need to call Application.get_env at runtime to get the correct value:

Add:

def from_email, do: Application.get_env(:email, :from_email)

to the module and then change all @from_email in the module to from_email() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM