7

I currently have my app up and running, the app.yaml and dispatch.yaml are in the root of the application and I deploy through Google Cloud CLI.

This works well for the moment, though as I move to having a dev, staging and prod environment I can see that it's no longer viable.

The main issue I see is that I have to edit the variables in the app.yaml file so they are appropriate for environment (for example I use env_variables to store mysql credentials...).

I can't find anything in the docs that points to the correct way to manage this, any ideas?

Also... When deploying from a GIT repo it seems that the app.yaml needs to be in the repo, is this correct? It doesn't seem right to me... There must be a better way!

nick
  • 3,521
  • 3
  • 22
  • 32
  • Unfortunately no, and I share your frustration having used GAE for several years. Same question here http://stackoverflow.com/a/28283512/3103979 – Dan Mar 30 '17 at 15:06
  • @Dan damn, I hope they sort this out. – nick Mar 30 '17 at 15:48
  • 1
    check out E.'s comment below. i'm now using something like: `gcloud config configurations activate ` `gcloud app deploy app_.yaml --version ` https://cloud.google.com/sdk/docs/managing-configurations https://cloud.google.com/sdk/gcloud/reference/app/deploy – Dan Apr 04 '17 at 02:51
  • @Dan this looks like an interesting solution. How does it work, does `gcloud` somehow auto-generate a separate `app_.yaml` file for each dev, staging & prod environments? If so, how does it know what values of each environment var to pass into the file? I'm thinking about a case, say, where you have a 'HOST' and 'PORT' vars for each env and how it would set them – kip2 Jun 06 '18 at 16:05

2 Answers2

6

You can use a configuration file or datastore settings to keep track of this environment information. At minute 26 in this talk I give some examples of how to customize your environment without needing different app.yaml files.

gcloud app deploy also accepts a list of yaml files on the command line, with the default being app.yaml.

E. Anderson
  • 3,405
  • 1
  • 16
  • 19
2

Note: assuming you use a different application to implement each environment, not different services/module of the same application, which IMHO would be an unnecessary complication. See How to deploy one app engine app to multiple projects

Personally I use a different git branch for each environment.

Granted I only have 2 environments: a development/staging one and the production one, but the same principle applies:

The branch structure reflects the flow through environments:

  • the master branch is used for the dev environment
  • the staging branch is pulled off the master branch
  • the production branch is pulled off the staging branch

To propagate code changes from one environment to another you'd merge the respective child branch to the newer parent branch version (which contains the changes you want to pick up) and deploy the merged child branch code to the corresponding environment.

Each branch has its own version of the app.yaml file. You'll have to keep an eye on conflicts in this file which may pop up whenever changes to it are propagated from one branch to another.

See also Environment Specific Variables In Google App Engine Java (and maybe its linked/related posts).

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • 1
    I am using different projects so this will work well until Google have come up with a better solution. Thanks! – nick Mar 30 '17 at 15:50