How to deploy one app engine app to multiple projects

后端 未结 4 1194
我在风中等你
我在风中等你 2021-01-07 02:38

My problem is that I want to create dev, stage, prod environments by using different GCP projects.

Basically they are running

相关标签:
4条回答
  • 2021-01-07 03:10

    My preference is to have the different environments managed via the same version control as the code - one branch for each environment, keeping the deployments perfectly aligned with the natural flow of code changes, promoted via branch merges: dev -> stage -> production.

    To minimize the risk of human error I try as much as possible to keep the deployment configs in the code itself (i.e. - have the app IDs, versions, etc. picked up from the .yaml files, not passed to the deploy cmd as args). The deployment cmds themselves are kept in a cheat-sheet file (too simple to warrant a full-blown script at this time), also git-controlled. Illustrated in this answer: https://stackoverflow.com/a/34111170/4495081

    Deployments are done from separate, dedicated workspaces - one for each environment, based on the corresponding git branch (I never switch the branches in these workspaces). I just update the workspace corresponding to the desired environment to the version needed and copy-paste the deployment cmd from the workspace's cheat-sheet.

    This model is IMHO CI/CD-ready and can easily be entirely automated.

    0 讨论(0)
  • 2021-01-07 03:12

    The "standard" approach is to use versions, e.g.

    qa.myApp.appspot.com
    

    Once a version is ready for next step, you deploy it with a different version id.

    One problem with using multiple projects is that you have to maintain a different data set for each project.

    0 讨论(0)
  • 2021-01-07 03:23

    For Python applications, you can set application in the app.yaml file. This allows you to use different data for each project. This is when you deploy using the appcfg.py command.

    application: myproject
    version: alpha-001
    runtime: python27
    api_version: 1
    threadsafe: true
    
    handlers:
    - url: /
      script: home.app
    

    If you don't want to change the application value in this file for each project, you can run the following:

    appcfg.py -A <YOUR_PROJECT_ID> -V v1 update myapp/
    

    https://cloud.google.com/appengine/docs/python/config/appref

    If you do not specify the application in the file, use the --application option in the appcfg command when you deploy. This element is ignored when you deploy using the gcloud app deploy command.

    0 讨论(0)
  • 2021-01-07 03:23

    Instead of using gcloud init to change your configuration each time, use this code to deploy to multiple projects faster:

    gcloud app deploy -q --project [YOUR_PROJECT_ID]
    

    If your projects have similar IDs, let's say: test1, test2, test3, test4, You can deploy to the four projects with one command. Use this code:

    for i in {1..4}; do gcloud app deploy -q --project test${i}; done
    
    0 讨论(0)
提交回复
热议问题