Hide
Google App Engine

1. Introduction

This tutorial starts with a small App Engine Python application that runs in the sandboxed hosting environment. In step 2 you'll deploy the app into a managed VM. Each subsequent step extends the managed VM configuration by modifying the Dockerfile, and adds application code that takes advantage of the new runtime capabilities.

The tutorial emphasizes the progressive elaboration of the Dockerfile, which is essentially done the same way regardless of the language you will ultimately use for your own work. Using Python source code makes it easy to demonstrate the new functionality added in each step.

If you are a Java developer who uses maven, you might prefer to read about maven for managed VMs and begin by trying one of the Java sample apps.

If you are not familiar with Managed VMs, it would be helpful to read the Managed VMs Overview page before you begin the tutorial.

The tutorial files are available on GitHub. The code for each step is stored in a separate branch.

Set up your development environment

To begin, follow the instructions to install Google Cloud SDK and Docker. If you want to deploy as you develop (rather than just run locally in a VM), you'll need to create a project with billing enabled. (For a limited time, Google is offering a free trial with $300 you can use to explore managed VMs and the rest of the Cloud Platform.)

Build an initial sandboxed app

Start by creating a development directory for your project. Copy these two files into the directory. This is a version of the basic "Hello World" Python app. It's configured to run in the App Engine sandboxed hosting environment.

app.yaml

main.py

Trial run

Run the command in the local development server. Technically, you could do this using dev_appserver.py, the original App Engine devserver, but since all managed VM work must be done using the Cloud SDK gcloud command, we suggest you start using that right away.

Many gcloud commands require a project ID. You can include a project ID in every command using the --project flag. Alternatively, you can set the current project ID once with a gcloud command:

$ gcloud config set project <project-id>

If you created a project, use its ID. If you haven't, use any string for the value. Now you can run the app locally from your development directory:

$ gcloud preview app run ./app.yaml

The first time you launch the devserver, it takes some time to download the resources necessary to provision your local VM. If you've preloaded the standard runtime images the command may run faster. Be patient. You'll know the process is complete when the terminal output shows the _ah/start request:

INFO: Starting module "default" running at: http://localhost:8080
INFO: Starting admin server at: http://localhost:8000
INFO: Image vm22.default.1 built, id = 59d0c46b8a31
INFO: Creating container...
INFO: Container d79f59a7e4d6398a78a4273a5760a236c071330103a5d5438b70c4b644a9282a created.
INFO: default: "GET /_ah/start HTTP/1.1" 404 52

Go to http://localhost:8080/ to run the app.

Next

This exercise was just for starters. In the next step, you'll run the same code in a managed VM.

Go to Step 2