In this hands-on lab, we will deploy an application to Google App Engine, make “risky” updates to our source files, and then redeploy the new update without directing traffic to the new version. We will then split traffic between two different versions of our application using the web console controls.
Successfully complete this lab by achieving the following learning objectives:
- Deploy Application
Open Cloud Shell.
Type the following commands to clone the GitHub repo, browse to the directory, install requirements, and deploy our application as version 1:
git clone https://github.com/GoogleCloudPlatformTraining/cp100-bookshelf
pip install -r requirements.txt -t lib
gcloud app deploy --version 1
When prompted, choose the us-east1 region.
Confirm the deployment confirmation by typing
- View Your Application
Once your application completes deployment, check it for success.
- Go to App Engine in the web console, and launch the app using the top-right URL. URL format will be (PROJECT_ID).appspot.com.
- Add a couple book entries to your bookshelf list. Close out of the tab when done.
- Back in the web console, from the App Engine menu, click Versions.
- Click the three-line hamburger menu icon, and navigate to Datastore. You should see the books you added.
- Edit Application Source Code Files
Let’s now make some changes to our source code files before we re-deploy the application.
- Back in Cloud Shell, open the editor by clicking Open Editor.
- Browse to
base.htmlto open it.
- If you are comfortable with HTML, you can make any change that you want. For our guide, we will change the
- If you want, also change the
Shelf of Books.
- Close the code editor by clicking Open Terminal.
- Deploy New Version of App Without Sending Traffic to It
Now that we have changed our app, let’s deploy it again without promoting it to the live version.
Back in the Cloud Shell command line view, make sure you are still in the
Deploy the new version of the app as version 2 without promoting it to the live version:
gcloud app deploy --no-promote --version 2
Confirm when prompted by typing
y. The app should then deploy.
- Check Live App Version and Split Traffic to Our “Risky” Update
- Back in the web console, go back to the App Engine menu and re-open your app. It should still be on the previous version. Leave this tab open.
- Go to App Engine > Versions. You should see version 1 has 100% of traffic allocated to it and version 2 has 0%.
- On the top bar, click the button labeled SPLIT TRAFFIC.
- Set Split traffic by to Random.
- Under Traffic allocation, click the Add version button.
- Make sure the added version is 2, and set the percentage setting to 10%.
- Click Save.
- In the bookshelf application tab, keep clicking the refresh button. On every refresh, the newer update should appear roughly 1 out of 10 times (it won’t be that exact ratio, but should be close). We should see RISKY UPDATE as its title in the browser tab.
- In the web console, still on the Split traffic screen, change version 2’s percentage to 50% to make it an even 50/50 split.
- Click Save.
- Refresh the bookshelf application tab. This time, it should be a roughly 50/50 split between both versions of the app.