1

In the Google App Engine app.yaml file, you specify a version property (though the current preference instead of app.yaml: "...instead, use a command-line flag (--version) to specify your version ID").

In my case, I use this for different environments. (See note at bottom) As documented in app.yaml, unique version values produce unique URLs:

Note: Version names should begin with a letter, to distinguish them from numeric instances which are always specified by a number. This avoids the ambiguity with URLs like 123.my-service.appspot.com...

I use two versions, the first as my "QA environment" , the second as my "Production environment":

  • dev
  • 1

I want my code to set a variable is_prod, and I want the value to be a boolean True if the version value is equal to 'dev'. How can I do that?

*Note, as @Dan Cornilescu says in the comments, using-versions-for-environments may be a bad idea, per posts like this and this

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
  • 1
    Side note: using versioning to implement environments is questionable, see https://stackoverflow.com/questions/40192557/continuous-integration-deployment-delivery-on-google-app-engine-too-risky/40193364#40193364. The recommended ones use either services or entire apps, see https://stackoverflow.com/questions/43218971/advantages-of-implementing-ci-cd-environments-at-gae-project-app-level-vs-servic – Dan Cornilescu Dec 06 '17 at 14:42
  • I think that's good warning to incorporate into my question itself. Thank you. Can you give an example of why /how you would /should use versioning, (if not environments?) – Nate Anderson Dec 06 '17 at 19:29
  • 1
    Not really - I wouldn't use versioning to implement environments to start with ;) Primarily because I'd be losing (or at least making very difficult) to version both the environments and the app code itself: would a certain version string represent an environment (and, if so - which version of that environment?) or a certain version of the app code? – Dan Cornilescu Dec 06 '17 at 19:37
  • 1
    Personally I prefer separate apps to implement environments to ensure the datastore isolation - I don't want a misbehaving environment polluting or potentially corrupting data for another environment, especially the production one: https://stackoverflow.com/questions/43118879/google-cloud-app-engine-app-yaml-for-multiple-environments/43121949#43121949 – Dan Cornilescu Dec 06 '17 at 19:44
  • Sorry Dan, I like your suggestion separate apps, but I was wondering, what is a good use for `version` differences? *Is* there a good use? Why are they there? (Maybe you gave a reason, but I missed it...) Documentation re: `version` is good but doesn't prescribe why to use `version`. IMO, documentation doesn't even make it very clear how `version` affect the URL... (again maybe I missed some documentation, GAE documentation has changed a lot since I started using it) – Nate Anderson Dec 06 '17 at 21:09
  • 1
    The version's original goal is to version the app deployments. But for that you have to explicitly change the version, so it effectively depends on what you want to do with it. Important uses of versioning are testing before switching live traffic to a new version, as well as [traffic splitting](https://cloud.google.com/appengine/docs/standard/python/splitting-traffic) for live A-B testing and [traffic merging](https://cloud.google.com/appengine/docs/standard/python/migrating-traffic) for hitless app upgrades – Dan Cornilescu Dec 07 '17 at 05:07

1 Answers1

1

The google.appengine.api.modules.modules module appears to have the method I want. It produces a string, even though the value is an integer my app.yaml (Google calls this a "numeric instance"):

from google.appengine.api.modules  import modules

# Adjust for your different versions, these string values are based on my setup in the OP
is_prod = modules.get_current_version_name()=='1'
is_dev= modules.get_current_version_name()=='dev'
Nate Anderson
  • 18,334
  • 18
  • 100
  • 135