Managing Versions of an App Engine Application

Hands-On Lab

 

Photo of Matthew Ulasien

Matthew Ulasien

Team Lead Google Cloud in Content

Length

00:30:00

Difficulty

Intermediate

In this hands-on lab, we will deploy an application to Google App Engine, make 'risky' updates to our source files, 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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Managing Versions of an App Engine Application

Introduction

In this hands-on lab, we will deploy an application to Google App Engine, make 'risky' updates to our source files, 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.

Solution

We will use both the web console and Cloud Shell for this lab. Be sure to launch the lab in incognito mode (or your browser's private viewing mode) to avoid cached login issues.

Deploy application

  • Open Cloud Shell by clicking the Cloud Shell icon in the blue bar at the top of the page

  • 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
    cd ~/cp100-bookshelf/app-engine
    pip install -r requirements.txt -t lib
    gcloud app deploy --version 1
  • When prompted, choose the region closest to you

  • Confirm the deployment confirmation by typing 'y'

View your application

Once your application completes deployment, let's go 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
  • Go ahead and 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, go to the Versions menu
  • View your Datastore entries that you just entered on the website by going to the top-left menu, and clicking on Datastore under Storage

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 the pencil icon in the top-right.
  • Browse to cp100-bookshelf/app-engine/bookshelf/templates, then click on base.html to open it.
  • If you are comfortable with HTML, you can make any change that you want. For our guide, we will change the title entry to RISKY UPDATE.
  • If you want, also change the navbar-brand entry to Shelf of Books.
  • Close the code editor by clicking the pencil icon again.

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 that you are still in the 'app-engine' directory

  • Deploy the new version of the app as version 2 without promoting it to the live version by typing the following command:

    gcloud app deploy --no-promote --version 2
  • Confirm the confirmation prompt when prompted by typing 'y', then the app should 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 the App Engine > Versions menu. You should see that version 1 has 100% of traffic allocated to it and version 2 has 0%.
  • On the top bar, click the button labeled SPLIT TRAFFIC
  • Under the Split traffic by field, set it to Random
  • Under Traffic allocation, click the Add version button
  • Make sure the added version is version 2, and set the percentage setting to 10%, then click Save. Once the save is confirmed, go back to your 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 exactly that ratio, but should be close).
  • Go back to the Split traffic screen, and this time set the split to 50/50, and save. This time it should be a roughly 50/50 split between both versions of the app.

Conclusion

Congratulations, you've completed this hands-on lab!