I'm not able to start my project from a mix release
. But it works fine if I run mix phx.server
I'm able to recreate this problem from an empty project by doing:
mix phx.new asdf --umbrella --no-ecto --no-html --no-webpack
then edit mix.exs
and add a release section:
def project do
[
apps_path: "apps",
start_permanent: Mix.env() == :prod,
deps: deps(),
version: "0.1.0",
releases: [
mega_umbrella: [
applications: [
mega: :permanent,
mega_web: :permanent
]
]
]
]
end
then remove the last line from config/prod.exs
# import_config "prod.secret.exs
run mix release
run _build/dev/rel/asdf_umbrella/bin/asdf_umbrella start
And the application just hangs there.
What am I doing wrong and why is it just hanging there?
My version info:
elixir --version
Erlang/OTP 22 [erts-10.5.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.9.2 (compiled with Erlang/OTP 22)
First of all when it comes to configs, in new releases of distillery there is a new feature, called runtime configs, witch are favored instead of the ones at compile time, you can read more about them here.
The basic idea behind this feature is that you can fetch environment variables when the server is run, when compared to the old config you had to provide all the configuration at build time, this comes really handy when working with containers and in general is more flexible.
The steps for making runtime config are the following:
- Inside
config
folder create releases.exs
file;
- Copy all the config you have provided in
prod.exs
or at least the parts you want to override;
- Use
System.fetch_env!\1
to get the data from environment variables;
You should remember that runtime config overrides the previous config, so if for example you provide prod.exs
config at compile time, everything new in releases.exs
will override the old config.
An example of a part of such config is:
config :tachocard_api, TachocardApi.Repo,
username: System.fetch_env!("PGUSER"),
password: System.fetch_env!("PGPASSWORD"),
database: System.fetch_env!("PGDATABASE"),
hostname: System.fetch_env!("PGHOST"),
pool_size: 10
Then in your deploy environment you set those environment variables to the values you need. System.fetch_env!/1
bang version is recommended, since it will throw an error if the environment variable is not set.