Search code examples
google-app-enginegoogle-cloud-platformapp-engine-flexible

How to use GAE's dispatch.yaml with multiple development environments?


I am trying to understand the dispatch.yaml file for Google App Engine.

We have a vanilla web app with a frontend and a backend. We also have a development and a production environment. Both environments have two services on GAE - frontend and default, which is the backend.

We have a vanilla web app with a frontend and a backend. We also have a development and a production environment. We have two services on GAE - frontend and default, which is the backend. We have two projects on GAE - staging, which is our dev environment, and production, which is our production environment. The staging environment is built from our dev branch in both our frontend and backend. The production environment is built from our master in both our frontend and backend.

We want to use custom routes for both the staging and production environments.

I have tried using dispatch_staging.yaml and dispatch_prod.yaml to differentiate the files but GAE won't recognize those file names. I guess we could rename the frontend service but it looks like there is no way getting around default.

How do you use dispatch.yaml to specify the environment being built?


Solution

  • The way I approached this problem is by using different repo branches for the application code.

    • the master branch version is deployed to my_app-dev - the development environment app
    • the production branch version is deployed to my_app - the production environment app

    This way the file is always named dispatch.yaml. The service names don't change between environments, but the custom domain names associated to them do - and that's reflected in the content of the dispatch.yaml file in the 2 branches:

    $ git diff production master -- dispatch.yaml
    diff --git a/dispatch.yaml b/dispatch.yaml
    index 0768a6a..c1326cf 100644
    --- a/dispatch.yaml
    +++ b/dispatch.yaml
    @@ -1,14 +1,14 @@
    -application: my_app
    +application: my_app-dev
     dispatch:
    -  - url: "service1.my_app.com/*"
    +  - url: "service1-dev.my_app.com/*"
         module: service1
    -  - url: "service1-dot-my_app.appspot.com/*"
    +  - url: "service1-dot-my_app-dev.appspot.com/*"
         module: service1
       - url: "*/service1/*"
         module: service1
    -  - url: "service2.my_app.com/*"
    +  - url: "service2-dev.my_app.com/*"
         module: service2
    -  - url: "service2-dot-my_app.appspot.com/*"
    +  - url: "service2-dot-my_app-dev.appspot.com/*"
         module: service2
    

    Note: I'm implementing the different environments at the app level (as opposed to the service level, see Advantages of implementing CI/CD environments at GAE project/app level vs service/module level?). A service-level implementation cannot use this approach.