Testing and Deploying your Application

Learn how to run your application locally, deploy it, and test on App Engine.

Running locally

To test your application's functionality before deploying, run your application in your local environment with the development tools that you usually use.

For example, you can usually run a Flask application with Flask's development server using:

python main.py

Django applications can be started using:

python manage.py runserver

To simulate a production App Engine environment, you can run the full Web Server Gateway Interface (WSGI) server locally. To do this, use the same command specified as entrypoint in your app.yaml, for example:

gunicorn -b :$PORT main:app

Deploying your application

Deploy your app to App Engine using the gcloud app deploy command. This command automatically builds a container image by using the Container Builder service and then deploys that image to the App Engine flexible environment. The container will include any local modifications that you've made to the runtime image.

To programmatically deploy your apps, use the Admin API.

Before you begin

Before you can deploy your app:

Ensuring successful deployment

If you enable updated health checks, deployments are rolled back if your application does not reach healthy status.

When you deploy your first application to the flexible environment, there might be a delay as your virtual machine (VM) and other infrastructure are set up. After the initial setup, health checks begin to confirm that your instance is healthy and ready to receive traffic. If your application does not reach ready status in a specified amount of time, then your deployment fails and is rolled back.

Your application might need more time to become ready. For example, you might initialize your application by downloading large files or preloading caches. If you are using updated health checks, then you can increase the amount of time by modifying the app_start_timeout configuration setting in your app.yaml file.

Deploying a service

You deploy your app to App Engine by deploying versions of your app's services and each of their configuration files.

To deploy a version of your app's service, run the following command from the directory where the app.yaml file of your service is located:

gcloud app deploy

Specifying no files with the command deploys only the app.yaml file of a given service. By default, the command automatically generates a unique ID for the version that you deploy, deploys your version to the GCP project which was used to initialize the gcloud tool, and also routes all traffic to that version.

You can change the default behavior of the command by targeting specific files or including additional command parameters:

  • To deploy the other configuration files of your service, you must target and deploy each file separately. Examples:

    gcloud app deploy cron.yaml
    gcloud app deploy dispatch.yaml
    gcloud app deploy index.yaml
    
  • To specify a custom version ID, use the --version flag.

  • To prevent traffic from being automatically routed to the new version, use the --no-promote flag.

  • To deploy your app to a specific GCP project, use the --project flag.

For example, to deploy the service defined by app.yaml to a specific GCP project, assign it a custom version ID, and prevent traffic from being routed to the new version:

gcloud app deploy --project PROJECT_ID --version VERSION_ID --no-promote

For more information about this command, see the gcloud app deploy reference.

Deploying multiple services

You use the same deployment command for deploying or updating the multiple services that make up your application.

To deploy multiple services, you must separately deploy each service's app.yaml file. For example:

gcloud app deploy service1/app.yaml
gcloud app deploy service2/app.yaml

You can specify multiple files with a single deploy command:

gcloud app deploy service1/app.yaml service2/app.yaml

Requirements for deploying multiple services

  • You must initially deploy a version of your app to the default service before you can create and deploy subsequent services.

  • The ID of each of your services must be specified in their corresponding app.yaml configuration files. To specify the service ID, you include the service element definition in each configuration file. By default, excluding this element definition from your configuration file deploys the version to the default service.

Manually building a container for deployment

To build your container images outside of Google Cloud Platform, you must first upload your images to a container image repository before you can deploy your images to App Engine with the gcloud app deploy command.

For example, if you build your container images locally with Docker, you can push those images to Google Container Registry and then specify the URL of your image in the --image-url flag of the command:

gcloud app deploy --image-url gcr.io/YOUR_PROJECT_ID/YOUR_CONTAINER_IMAGE

Using automated continuous deployment pipelines

You can use Container Builder to automate deployments in continuous deployment pipelines. For more information, see Deploying artifacts, and Automating Builds using Build Triggers in the Container Builder documentation.

Docker base images for Python

If you'd like to build a Python custom runtime application from scratch, use a provided base image in your Dockerfile:

Runtime Docker command Equivalent Google runtime
Python (2.7, 3.6 can be specified in the Dockerfile) FROM gcr.io/google-appengine/python runtime: python

Viewing your application

After you deploy your app to App Engine, you can run the following command to launch your browser and view the app at http://YOUR_PROJECT_ID.appspot.com:

gcloud app browse

Testing on App Engine

Before configuring a new version to receive traffic, you can test it on App Engine. For example, to test a new version of your default service:

  1. Deploy your new version and include the --no-promote flag:

    gcloud app deploy --no-promote
  2. Access your new version by navigating to the following URL:

    http://VERSION_ID.default.YOUR_PROJECT_ID.appspot.com
    

    Now you can test your new version in the App Engine runtime environment. You can debug your app by viewing its logs. For more information, see Writing Application Logs.

    Requests sent to http://YOUR_PROJECT_ID.appspot.com will still be routed to the version previously configured to receive traffic.

  3. When you want to send traffic to the new version, use the GCP Console to migrate traffic:

    Manage versions

    Select the version you just deployed and click Migrate traffic.

You can use the same process to test new versions of other services by replacing default in the URL with your service's name:

http://VERSION_ID.SERVICE_ID.YOUR_PROJECT_ID.appspot.com

For more information about targeting specific services and versions, see How Requests are Routed.

Troubleshooting

The following is a common error message that you might encounter when deploying apps:

PERMISSION_DENIED: Operation not allowed
The "appengine.applications.create" permission is required.
If the GCP project does not include the required App Engine application, the gcloud app deploy command can fail when it tries to run the gcloud app create command. Only accounts with Owner role have the necessary permissions to create App Engine applications.

Send feedback about...

App Engine flexible environment for Python docs