I can get my environment variables compiled with the release build on the build host

I’m using edeliver and distillery to build the app on the build host.

I have tried so many things to make sure my environment variables get compiled while the release is being built on the build host but it seems not work.

I added this snippet to my .deliver/config

status "Configuring Environment Variable"
  local _environment_var_path="/home/deploy/.env"
  __sync_remote "
    ln -sfn '$_environment_var_path' '$BUILD_AT/.env'
    cd '$BUILD_AT'
    source .env

But still doesn’t work.

I have in my config/config.exs

config :extwitter, :oauth,
        consumer_key: {:system, "CC_TWITTER_CONSUMER_KEY"},
        consumer_secret: {:system, "CC_TWITTER_CONSUMER_SECRET”}

And I will like the environment to be compiled with the release version on the build host

Please any hint on how to achieve this?

What exactly does “doesn’t work” mean?

Do you get an error message? Which one? Is something deployed to your remote but it fails to start? Or crashes after a couple of seconds without beeing hit by requests?

Sorry, I misunderstood the question…

Long story short: :extwitter doesn’t seem to understand the :system-tuple.

The application could not retrieve the value of the environment keys CC_TWITTER_CONSUMER_KEY and CC_TWITTER_CONSUMER_SECRET. It returned nil

I have tried with System.get_env() as well but didn’t work on production server.

Also the issue also applies to ex_twilio config.

Is this BASH or ZSH? If so, your environment variables won’t be expanded due to the use of singlequotes:

$ echo $HOME
$ echo "$HOME"
$ echo '$HOME'

as you can see, you are triying to link a file with the literal name $_environment_var_path to a file called literally .env in a folder called literally $BUILD_AT, into which you also cd. Even if the targets could work, they will probably not as you expect it :wink: The source though does definitifely not work, I can’t imagine a file $_environment_var_path to exist in your pwd

It’s the config file of edeliver. This is full part for the code section shared

pre_erlang_get_and_update_deps() {
	status "Configuring Environment Variable"
  	local _environment_var_path="/home/deploy/.env"
  	__sync_remote "
    ln -sfn '$_environment_var_path' '$BUILD_AT/.env'
    cd '$BUILD_AT'
    source .env

Let me rephrase: does edliver shell out and runs that snippet in BASH or ZSH? It will not run in elixir!

It runs in bash while building the release on the build host server.

OK, I see. Also I do see now, that they are expanded locally.

So, if you do those steps manually on your server, does it work then? do you see any error messages in the process? Can you log in edeliver which commands are actually sent to the remote site?

I did this manually on the server but it didn’t work. And there were no error messages.

Are the corresponding variables set correctly after sourcing the .env file? Check using echo ... or env

Yes the variables are correctly set.

When i checked the sys.config i noticed that actual value was not been set in the sys.config file.

Thanks so much @NobbZ for your time and experience shared.

I have resolved to look into suggestions raised here Distillery and EDeliver on Custom Phoenix Port

Thanks immensely for your support! I really appreciate you.