简体   繁体   English

无法将 Elixir Phoenix 作为混合版本启动

[英]Can't start a Elixir Phoenix as a mix release

I'm not able to start my project from a mix release .我无法从mix release开始我的项目。 But it works fine if I run mix phx.server但是如果我运行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:然后编辑mix.exs并添加一个发布部分:

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然后从config/prod.exs中删除最后一行

# import_config "prod.secret.exs

run mix release运行mix release

run _build/dev/rel/asdf_umbrella/bin/asdf_umbrella start运行_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 .首先,当谈到配置时,在 distillery 的新版本中有一个新功能,称为运行时配置,它更受青睐,而不是编译时的配置,您可以在此处阅读有关它们的更多信息。

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;config文件夹中创建releases.exs文件;
  2. Copy all the config you have provided in prod.exs or at least the parts you want to override;复制您在prod.exs中提供的所有配置,或者至少复制您想要覆盖的部分;
  3. Use System.fetch_env!\1 to get the data from environment variables;使用System.fetch_env!\1从环境变量中获取数据;

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.您应该记住,运行时配置会覆盖以前的配置,因此,例如,如果您在编译时提供prod.exs配置, releases.exs中的所有新配置都将覆盖旧配置。

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.推荐使用System.fetch_env!/1 bang 版本,因为如果没有设置环境变量会抛出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM