Managing Versions of an App Engine Application

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy Application
  1. Open Cloud Shell.

  2. 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
  3. When prompted, choose the region closest to you.

  4. Confirm the deployment confirmation by typing y.

View Your Application

Once your application completes deployment, check it for success.

  1. 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.
  2. Add a couple book entries to your bookshelf list. Close out of the tab when done.
  3. Back in the web console, from the App Engine menu, click Versions.
  4. 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.

  1. Back in Cloud Shell, open the editor by clicking Open Editor.
  2. Browse to cp100-bookshelf > app-engine > bookshelf > templates.
  3. Click base.html to open it.
  4. 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.
  5. If you want, also change the navbar-brand entry to Shelf of Books.
  6. 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.

  1. Back in the Cloud Shell command line view, make sure you are still in the app-engine directory.

  2. Deploy the new version of the app as version 2 without promoting it to the live version:

    gcloud app deploy --no-promote --version 2
  3. Confirm when prompted by typing y. The app should then deploy.

Check Live App Version and Split Traffic to Our “Risky” Update
  1. 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.
  2. Go to App Engine > Versions. You should see version 1 has 100% of traffic allocated to it and version 2 has 0%.
  3. On the top bar, click the button labeled SPLIT TRAFFIC.
  4. Set Split traffic by to Random.
  5. Under Traffic allocation, click the Add version button.
  6. Make sure the added version is 2, and set the percentage setting to 10%.
  7. Click Save.
  8. 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.
  9. 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.
  10. Click Save.
  11. Refresh the bookshelf application tab. This time, it should be a roughly 50/50 split between both versions of the app.

Additional Resources

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.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?