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
export API_KEY=xdfj212c
gcloud app deploy
I want the same behavior.
Is this make sense for google app engine deployment workflow?
In app.yaml
you can include another YAML config
includes:
- extra_env_vars.yaml
that you can create on the fly while inserting the environment variables
# Unix-like OS
export DB_PASSWORD=your_password
export DB_HOST=your_host
echo -e "env_variables:\n DB_PASSWORD: $DB_PASSWORD\n 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
The resulting extra_env_vars.yaml
looks like this:
env_variables:
DB_PASSWORD: your_password
DB_HOST: your_host
Finally, ignore extra_env_vars.yaml
in your version control system.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With