How to pass system environment variables to app.ya

2019-06-26 09:23发布

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 with xdfj212c.

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?

1条回答
疯言疯语
2楼-- · 2019-06-26 09:51

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.

查看更多
登录 后发表回答