无法启动Elixir Phoenix混合发行 [英] Can't start a Elixir Phoenix as a mix release

查看:102
本文介绍了无法启动Elixir Phoenix混合发行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从mix release开始我的项目.但是,如果我运行mix phx.server

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

然后编辑mix.exs并添加发布部分:

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

然后从config/prod.exs

# import_config "prod.secret.exs

运行mix release

运行_build/dev/rel/asdf_umbrella/bin/asdf_umbrella start

应用程序就挂在那里.

我在做什么错,为什么它只是挂在那里?

What am I doing wrong and why is it just hanging there?

我的版本信息:

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:

  1. config文件夹内创建releases.exs文件;
  2. 复制您在prod.exs中提供的所有配置,或者至少复制要覆盖的部分;
  3. 使用System.fetch_env!\1从环境变量获取数据;
  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;

您应该记住,运行时配置会覆盖以前的配置,因此,例如,如果您在编译时提供了prod.exs的配置,则releases.exs中的所有新内容都将覆盖旧的配置.

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

然后在部署环境中将这些环境变量设置为所需的值.推荐使用System.fetch_env!/1爆炸版本,因为如果未设置环境变量,它将引发错误.

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.

这篇关于无法启动Elixir Phoenix混合发行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆