How to pass system environment variables to app.ya

2019-06-26 09:33发布

问题:

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:

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.