Hide
Google App Engine

2. Use a Standard Runtime

In this step, you will break out of the sandbox and run in a managed VM. You must specify your VM machine resources, and select the Python standard runtime. This is all done in the app.yaml file for the module, the main.py file is unchanged.

Once you've run your code, you'll be able to view a Dockerfile that was automatically generated by the SDK, and see your managed VM in the cloud.

Edit the app.yaml configuration file

Python27 is one of the available standard VM runtimes. You can use this runtime in both the sandboxed and managed VM environments. To switch to managed VMs:

  • Add vm: true
  • Replace the instance_class key with a resources section. App Engine will assign an appropriate GCE machine type.

Test and deploy

Run locally

Kick off the devserver again:

$ gcloud preview app run ./app.yaml

Your app is ready to serve requests once you see successful replies to health check requests:

INFO: Starting module "default" running at: http://localhost:8080
INFO: Starting admin server at: http://localhost:8000
INFO: Image vm2-demo-id.default.1 built, id = 8dfa7c2eedb3
INFO: Creating container...
INFO: Container d727ba7d22117a97063587126e8e60cbff081ff5ccb03826630d69194f38eb05 created.
INFO: default: "GET /_ah/start HTTP/1.1" 404 52
INFO: default: "GET /_ah/health?IsLastSuccessful=no HTTP/1.1" 200 2
INFO: default: "GET /_ah/health?IsLastSuccessful=yes HTTP/1.1" 200 2

And visit http://localhost:8080/.

Deploy to the cloud

If you've created a project and enabled billing, you can deploy this app to the cloud:

$ gcloud preview app deploy ./app.yaml

It takes some time to provision your VM and crank it up. At the end of the deployment, you'll get polling messages until your app is ready to serve:

12:21 PM Cloning 5 application files.
12:21 PM Uploading 4 files and blobs.
12:21 PM Uploaded 4 files and blobs.
12:21 PM Starting deployment.
12:21 PM Checking if deployment succeeded.
12:21 PM Deployment successful.
12:21 PM Checking if updated app version is serving.
12:21 PM Will check again in 5 seconds.
...
12:23 PM Checking if updated app version is serving.
12:23 PM Enough VMs ready (1/1 ready).
12:23 PM Completed update of app: vm2-demo-id, version: 1

Once the app is deployed, you can point your browser to its address at appspot, which will look like this (insert your app's project ID):

http://<your-project-id>.appspot.com/

Point your browser at this address and reload the page a few times.

View your app in the Developers Console

If you've deployed to the cloud, you can see an overview of your app's activity in the Developers Console. The dashboard shows you overall performance statistics. You can find the dashboard in the left-hand menu, under Compute>App Engine. The instances page lets you drill down to the docker containers running each instance of a module. Select an instance and peruse the detailed information. You can see what type of Compute Engine machine is being used and the zone in which it's running.

Dockerfile

When you use gcloud to run or deploy a managed VM application based on a standard runtime (in this case Python27), the SDK will create a minimal Dockerfile using the standard runtime as a base image. You'll find this Dockerfile in your project directory:

# Dockerfile extending the generic Python image with application files for a
# single application.
FROM google/appengine-python27

ADD . /app

The base image google/appengine-python27 provides a full Python language implementation. The ADD instruction includes your application files. Since this app does not require any additional software, no other instructions are needed. Later steps in this tutorial will show you how to extend the capabilities of your runtime environment by adding instructions to the Dockerfile.

Next

Switching the hosting environment to a managed VM did not change the functionality of your app. In the next step, you'll modify your application code, using the full-blown VM environment to read and write to the local file system.

Go to Step 3