I'm using distillery to package an elixir application, and I want to have access to the current environment in the runtime (is it :dev
, :test
or :prod).
The goal will be checking the env at the runtime, something like this:
if Mix.env() == :prod do
# do this only in production
end
What are the drawbacks of including the mix
app in the release?
def application do
[mod: {EvercamMedia, []}, extra_applications: [:runtime_tools, :os_mon, :recon, :mix]]
end
Using mix
to detect the production environment is clearly an antipattern. Instead, one should probably start the release as
MY_APP_PROD=true release start
and use the system environment check as shown below
if System.get_env("MY_APP_PROD") == "true" do
...
end