gcloud app deploy '--appyaml' flag doesn't seem to work

Viewed 580

For Google App Engine, I want to inject env_variables into my app.yaml upon deploy. In the docs for gcloud app deploy, I see that there is the flag --appyaml that will:

Deploy with a specific app.yaml that will replace the one defined in the DEPLOYABLE.

https://cloud.google.com/sdk/gcloud/reference/app/deploy

So I have a Fabric script that reads my app.yaml, injects my extra env variables, writes this new app.yaml to a tempfile, and then runs gcloud app deploy. The command to gcloud ends up looking like this:

gcloud app deploy . --version dev --project myproject --appyaml='/var/folders/1z/qk45g9p934lg75byl8b74xyh0000gn/T/tmpgdjVUG.yaml'

The deploy succeeds and new code gets uploaded, however my new env variables don't seem to make it up.

If I provide a bogus value to --appyaml then it throws an error, so it does seem to use my input.

Any ideas what I could be doing wrong?

2 Answers

I have tested it on standard AppEngine with small HelloWorld modification in node.JS like this:

'use strict';

const express = require('express');
const app = express();

app.get('/', (req, res) => {
    var my_respond = "variables: ";
    res.status(200).send(Object.entries(process.env)).end();
});

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});

module.exports = app;

The sample is showing environment variables as result.

Than I added simplest app.yaml:

runtime: nodejs10
env_variables:
  MY_VAR: "my value from app.yaml"

Than in other location I have added different yaml called app1.yaml:

runtime: nodejs12
env_variables:
  MY_VAR: "my value from app1.yaml"

So this is changing node version and value of MY_VAR.

According to my tests this seems to be working little bit differently than explained in the doc, at least I understand it differently.

It's possible to use --appyaml flag, but only when there is no app.yaml file in the directory. If you do not have it in app directory, than using the flag you can point to different yaml.

So when I was trying to deploy with gcloud app deploy --appyaml="/home/vitooh/app1.yaml" and app.yaml was in application directory, the app was deployed with it - so the flag does not do anything. However when I done it without app.yaml the flag works, variable value is changed.

Actually you can spot it just after submitting command where there is a summary shown, just before you confirm deployment, in descriptor value like this:

descriptor:      [/home/vitooh/app1.yaml]
source:          [/home/vitooh/appEngine/nodejs-docs-samples/appengine/hello-world/standard]
target project:  [xxxxx-test-01]
target service:  [default]
target version:  [20200819t094956]
target url:      [https://xxxxx-test-01.appspot.com]

Do you want to continue (Y/n)?

The question is a blackbox without any details: "I have a fabfile and then things happen but they happen wrong". However here's a tip how to do this a bit simpler without messing with app.yaml. app.yaml can contain a directive called includes, which can reference another yaml file, where you can have the environment variables, so you dont have to touch the original file.

app.yaml:

(...)

includes:
  - my_vars.yaml

my_vars.yaml:

env_variables:
    MY_VAR: value
Related