【发布时间】:2017-11-15 13:23:12
【问题描述】:
按照本指南使用 Distillery 发布 elixir/phoenix 项目:
在设置config/prod.exs步骤,作者写道:
config :myapp, Myapp.Repo,
adapter: Ecto.Adapters.Postgres,
hostname: "${DB_HOSTNAME}",
username: "${DB_USERNAME}",
password: "${DB_PASSWORD}",
database: "${DB_NAME}",
配置数据库。这里使用${DB_HOSTNAME}类型获取环境变量,而不是System.get_env("DB_HOSTNAME")。
但是,当我运行 MIX_ENV=prod mix release --env=prod 并在本地设置环境变量时:
REPLACE_OS_VARS=true PORT=4000 HOST=0.0.0.0 SECRET_KEY_BASE=highlysecretkey DB_USERNAME=postgres DB_PASSWORD=postgres DB_NAME=myapp_dev DB_HOSTNAME=localhost ./_build/prod/rel/myapp/bin/myapp foreground
循环:
12:05:13.671 [error] Postgrex.Protocol (#PID<0.1348.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.671 [error] Postgrex.Protocol (#PID<0.1347.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.672 [error] Postgrex.Protocol (#PID<0.1344.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
12:05:13.672 [error] Postgrex.Protocol (#PID<0.1346.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (${DB_HOSTNAME}:5432): non-existing domain - :nxdomain
...
似乎${DB_HOSTNAME} 不为 elixir/phoenix 所知。
我现在正在使用 Elixir 1.5.2 和 Phoenix 1.3。版本问题?
【问题讨论】:
-
原因是我现在使用
zshshell。应该使用export来设置环境变量。
标签: environment-variables elixir phoenix-framework release distillery