Install MIX_ENV on Heroku for Phoenix Framework

I have successfully created two Heroku applications: my-app-prod and my-app-test. There are certain environment variables that I configured in the settings of the Heroku application. I use standard configuration files in Phoenix: config.exs, test.exs, prod.exs, dev.exs.

After setting up the my-app test in Heroku using the application variable MIX_ENV = test, it still loads the variables from prod.exs.

Are there any additional steps that I am missing so that my application uses test.exs?

I followed all the instructions here: https://hexdocs.pm/phoenix/heroku.html

When I run git push, I can test it with prod.exs based on the following output.

remote: Generated my_phoenix_app_name app remote: -----> Creating .profile.d with env vars remote: -----> Writing export for multi-buildpack support remote: -----> Executing post compile: pwd remote: /tmp/build_f5b9e6e5890fcb58b9689f433c554c6a remote: -----> Phoenix app detected remote: remote: -----> Loading configuration and environment remote: Loading config... remote: Detecting assets directory remote: * package.json found in custom directory remote: Will use phoenix configuration: remote: * assets path . remote: * mix tasks namespace phoenix remote: Will use the following versions: remote: * Node 5.3.0 remote: Will export the following config vars: remote: CLIENT_ID remote: DATABASE_URL remote: POOL_SIZE remote: SECRET_KEY_BASE remote: SHOPIFY_SECRET remote: * MIX_ENV=prod 
+5
source share
2 answers

Buildpack for Elixir sets MIX_ENV to prod by default , so you really don't need this parameter in your Procfile, you can change it just like this:

 web: mix phoenix.server 

In my-app-prod you don't have to do anything. On my-app-test just set MIX_ENV to test . You can use the command line

 heroku config:set MIX_ENV=test --app my-app-test 

If this does not work, try redistributing your applications in Heroku.

+1
source

In Procfile , where it says:

 web: MIX_ENV=prod mix phoenix.server 

You can change it to:

 web: mix phoenix.server 

since you already set MIX_ENV in the application settings configuration settings, you should just leave this part of MIX_ENV off.

0
source

Source: https://habr.com/ru/post/1271515/


All Articles