如何将系统环境变量传递给app

如何将系统环境变量传递给app

本文介绍了如何将系统环境变量传递给app.yaml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能吗?这是我的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

或者,在我运行后

  1. export API_KEY=xdfj212c

  2. 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

  1. export API_KEY=xdfj212c

  2. 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:46