Can't start a Elixir Phoenix as a mix release

烈酒焚心 提交于 2019-12-11 02:45:10

问题


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)

回答1:


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:

  1. Inside config folder create releases.exs file;
  2. Copy all the config you have provided in prod.exs or at least the parts you want to override;
  3. 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.



来源:https://stackoverflow.com/questions/58815793/cant-start-a-elixir-phoenix-as-a-mix-release

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!