Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 471
jeffskelton3 Avatar asked Aug 07 '16 20:08

jeffskelton3


People also ask

What is Elixir Phoenix Good For?

Phoenix is a web framework built with the Elixir programming language. Elixir, built on the Erlang VM, is used for building low-latency, fault-tolerant, distributed systems, which are increasingly necessary qualities of modern web applications.

What is a staging environment?

A staging environment (stage) is a nearly exact replica of a production environment for software testing. Staging environments are made to test codes, builds, and updates to ensure quality under a production-like environment before application deployment.

Is Phoenix framework fast?

Extreme performanceIn one benchmark test, Elixir with Phoenix framework performed up to 13 times better than Ruby on Rails, and upwards of 50% more performance compared to Node. js and Express. The default performance of Phoenix/Elixir is quite impressive.


1 Answers

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.

like image 101
jeffskelton3 Avatar answered Oct 21 '22 00:10

jeffskelton3