jeffskelton3
jeffskelton3

Reputation: 492

Setting up a staging environment in Elixir with Phoenix?

I am trying to set up a staging environment and running into problems when I compile using anything other than prod for my mix env. I’ve tried setting up a custom env called stag with a stag.exs file and all that but it appears to break. I’m pretty sure its because of this line I see in mix.exs:

build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,

The problem is that i see this line in all my deps folders as well. Does this mean that I should be using a Mix.env of prod even for my staging environments?

Upvotes: 9

Views: 2521

Answers (1)

jeffskelton3
jeffskelton3

Reputation: 492

I don't think I phrased the question correctly. I am creating a release binary and having trouble deploying it in a staging context when I set the MIX_ENV to anything other than prod. I was trying to create a custom environment called stag for staging with its own stag.exs config file but that was not working as expected. I think I have found the answer I was looking for:

I've discovered via some Elixir IRC channels that :prod is in fact a build mode and should be used for any cases where one intends to deploy. So in other words, my staging deployment should be set to MIX_ENV=prod and then either use environment variables for dynamic configuration settings in the prod.exs file or, as I have done in this case, dynamically load a deployment specific configuration in prod.exs like so:

deployment_config=System.get_env("DEPLOYMENT_CONFIG")
import_config "./deployment_config/#{deployment_config}.exs"

This approach solved my problem and I am now happily able to run different deployments with their own custom configurations in a release context.

Upvotes: 24

Related Questions