如何将系统环境变量传递给 app.yaml? [英] How to pass system environment variables to app.yaml?
问题描述
有可能吗?这是我的 app.yaml
:
Is it possible? Here is my app.yaml
:
runtime: nodejs8
env_variables:
NODE_ENV: production
PORT: 8080
API_KEY: ${API_KEY}
${API_KEY}
就像一个占位符.
当我运行 API_KEY=xdfj212c gcloud app deploy app.yaml
命令时,我想将 API_KEY=xdfj212c
传递给 app.yaml
和将占位符替换为xdfj212c
.
When I run API_KEY=xdfj212c gcloud app deploy app.yaml
command, I want to pass API_KEY=xdfj212c
to app.yaml
and replace the placeholder with
xdfj212c
.
预期结果:
runtime: nodejs8
env_variables:
NODE_ENV: production
PORT: 8080
API_KEY: xdfj212c
或者,在我跑完之后
导出 API_KEY=xdfj212c
gcloud app deploy
我想要相同的行为.
这对谷歌应用引擎部署工作流程有意义吗?
Is this make sense for google app engine deployment workflow?
推荐答案
在 app.yaml
中,您可以include 另一个 YAML 配置
In app.yaml
you can include another YAML config
includes:
- extra_env_vars.yaml
您可以在插入环境时即时创建变量
# Unix-like OS
export DB_PASSWORD=your_password
export DB_HOST=your_host
echo -e "env_variables:
DB_PASSWORD: $DB_PASSWORD
DB_HOST: $DB_HOST" > extra_env_vars.yaml
# Windows
set DB_PASSWORD=your_password
set DB_HOST=your_host
(echo env_variables: & echo. DB_PASSWORD: %DB_PASSWORD% & echo. DB_HOST: %DB_HOST%) > extra_env_vars.yaml
结果 extra_env_vars.yaml
看起来像这样:
The resulting extra_env_vars.yaml
looks like this:
env_variables:
DB_PASSWORD: your_password
DB_HOST: your_host
最后,忽略版本控制系统中的 extra_env_vars.yaml
.
Finally, ignore extra_env_vars.yaml
in your version control system.
这篇关于如何将系统环境变量传递给 app.yaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!