问题描述
有可能吗?这是我的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
.
预期结果:
runtime: nodejs8
env_variables:
NODE_ENV: production
PORT: 8080
API_KEY: xdfj212c
或者,在我运行后
-
export API_KEY=xdfj212c
-
gcloud app deploy
我想要相同的行为.
这对Google App Engine部署工作流程有意义吗?
您始终可以使用sed
:
$ sed -i 's/${API_KEY}/xdfj212c/g' app.yaml && gcloud app deploy
'坏'的事情是,这会将密钥存储回去,但是您始终可以添加新的sed
命令以再次用占位符替换密钥,或者使用VCS机制仅重置更改文件. /p>
另一种选择是将您的app.yaml
文件另存为app_template.yaml
之类的文件,并针对您的部署执行此操作:
$ sed 's/${API_KEY}/xdfj212c/g' app_template.yaml | tee app.yaml; gcloud app deploy
这将在新文件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}
is like a placeholder.
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 withxdfj212c
.
Expect result:
runtime: nodejs8
env_variables:
NODE_ENV: production
PORT: 8080
API_KEY: xdfj212c
Or, After I run
export API_KEY=xdfj212c
gcloud app deploy
I want the same behavior.
Is this make sense for google app engine deployment workflow?
You could always use sed
:
$ sed -i 's/${API_KEY}/xdfj212c/g' app.yaml && gcloud app deploy
The 'bad' thing is that this stores the key back, but you can always append a new sed
command to replace the key again with the placeholder, or use your VCS mechanism to just reset the change the file.
Another option is saving your app.yaml
file as something like app_template.yaml
and do this for your deployments:
$ sed 's/${API_KEY}/xdfj212c/g' app_template.yaml | tee app.yaml; gcloud app deploy
This will do the replacement in a new file, app.yaml
, and then do the deployment.
这篇关于如何将系统环境变量传递给app.yaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!