首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >凤凰城环境变量如何用蒸馏库设置?

凤凰城环境变量如何用蒸馏库设置?
EN

Stack Overflow用户
提问于 2017-11-15 03:15:44
回答 1查看 1K关注 0票数 1

按照本指南使用Distillery发布灵丹妙药/凤凰城项目:

https://blog.polyscribe.io/a-complete-guide-to-deploying-elixir-phoenix-applications-on-kubernetes-part-1-setting-up-d88b35b64dcd

在set config/prod.exs步骤中,作者写道:

代码语言:javascript
复制
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并设置本地环境变量时:

代码语言:javascript
复制
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

它循环:

代码语言:javascript
复制
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}并不为灵丹妙药/凤凰城所知。

我现在使用的是灵丹妙药1.5.2和凤凰1.3。版本问题?

EN

回答 1

Stack Overflow用户

发布于 2017-11-15 05:23:12

我从未见过这种方法,我也不知道它应该如何运作。在运行时获取环境变量的常见方法是:

代码语言:javascript
复制
{:system, "VAR"}

就你的情况而言:

代码语言:javascript
复制
config :myapp, Myapp.Repo,
  adapter: Ecto.Adapters.Postgres,
  hostname: {:system, "DB_HOSTNAME"},
  username: {:system, "DB_USERNAME"},
  password: {:system, "DB_PASSWORD"},
  database: {:system, "DB_NAME"}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47298764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档