How to copy / clone entire Google App Engine Proje

2020-04-19 06:35发布

问题:

I was wondering if there is any way to clone a google app engine project. I could not find any help regarding this, though its quite often one may need this feature. Suppose I started developing an app engine application with so many options / apis configured. Now it would become my staging project and I want a separate project for production. Its never very easy to setup a separate production project with same settings and configurations.

Primarily I would like to make a copy of my staging project for production and make any required changes there.

回答1:

I had my app code in a git repo, in the master branch, from where I used to deploy to a to my_app GAE project. Just as you do I wanted a staging environment.

So I create a new my_app-dev GAE project, which would be the staging environment, with deployments exclusively from the master branch.

Then I pulled a production branch from the master branch (effectively a git-controlled copy of the app code) which I now use as the exclusive deployment source for the my_app (production) GAE project.

To reduce the risk of deploying to the wrong app I decided to only deploy by copy-pasting pre-cooked cmds from a cmds text file (added to the git repo) in the project dir with the complete commands to deploy the code to the appropriate GAE app. I created this file in the master branch, looking like this (I'm using the GAE SDK, not the gcloud one) this:

/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update main/main.yaml apartci/apartci.yaml buildin/buildin.yaml
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_dispatch .
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_indexes -A my_app-dev main
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_cron -A my_app-dev .
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_queues -A my_app-dev .

I then merged the file in the production branch and updated it for the production GAE app (and added the git cmds to merge master branch changes verified in the staging environment into production):

/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update main/main.yaml apartci/apartci.yaml buildin/buildin.yaml
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_dispatch .
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_indexes -A my_app main
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_cron -A my_app .
/usr/bin/python2.7 /usr/local/google_appengine/appcfg.py update_queues -A my_app .

### merge into production:

git checkout master; git pull; git checkout production; git merge master

### check deltas between master and production:

git diff master..production

So now I have 2 side-by-side directories for the 2 environments: my_app-staging and my_app-production, containing git workspaces pulled from the master and production branches respectively. I work in my_app-staging until I'm happy with the results, then I switch to my_app-production and copy-paste the cmds to merge the changes and deploy into production.

At any moment I can check the deltas between the staging and the production branches in my_app-production (most likely there will be others beside just the GAE app name):

git diff master..production

Update

On the actual GAE app side I'm not aware of a cloning capability. I cloned my app manually, very early in the development process when there weren't many configs. The need for most config additions/changes came afterwards and I always applied them to both apps.

It might be possible to create such utility using the Google App Engine Admin API. But I didn't use it yet, I don't know if it covers all knobs for a complete cloning process.