Deploy your app to upload and run them on App Engine. When you deploy your apps, you create versions of those apps and their corresponding services in App Engine. You can deploy entire apps, including all the source code and configuration files, or you can deploy and update individual versions or configuration files.
Before you begin
Before you can deploy your app, you must have a Cloud Platform project and an App Engine application, see Managing Projects, Applications, and Billing for more information.
To deploy your app with the
gcloud tool, you
must download, install, and initialize the
Google Cloud SDK:
If you already have the gcloud tool installed and want
to configure it to use a Cloud Platform project ID other than the one
that you initialized it to, see
Managing Cloud SDK Configurations.
Using a proxy
If you are running the deployment command from a system which uses an HTTP or HTTPS proxy, you must configure the tool so that it can communicate via the proxy.
gcloud
Run the following commands to configure the gcloud tool:
gcloud config set proxy/type [PROXY_TYPE]
gcloud config set proxy/address [PROXY_ADDRESS]
gcloud config set proxy/port [PROXY_PORT]
You can also set a username and password for the
proxy. For more information, see
gcloud config.
appcfg
Set the environment variable that corresponds to your proxy:
- Windows
-
set HTTP_PROXY=http://cache.example.com:3128 set HTTPS_PROXY=http://cache.example.com:3128
- Mac / Linux
-
export HTTP_PROXY="http://cache.example.com:3128" export HTTPS_PROXY="http://cache.example.com:3128"
Deploying an app
To deploy your app to App Engine, you run
the
gcloud app deploy
command from within the root directory of your application where
your configuration files
are located, for example app.yaml.
gcloud
gcloud app deploy [YOUR_DEPLOYMENTS]
Where [YOUR_DEPLOYMENTS] is one or more configuration file's path and
name. You separate each configuration file that you specify with a single
white space. By default, the app.yaml is deployed when no configuration
file is specified.
Optional flags:
- Include the
--projectflag to specify an alternate Cloud Platform project ID to what you initialized as the default in thegcloudtool. Example:--project [YOUR_PROJECT_ID] - Include the
-vflag to specify a version ID, otherwise one is generated for you. Example:-v [YOUR_VERSION_ID]
Examples:
gcloud app deploy
gcloud app deploy app.yaml dos.yaml index.yaml
gcloud app deploy --project [YOUR_PROJECT_ID] -v [YOUR_VERSION_ID]
By default, each version that you deploy is automatically configured to
receive 100% of traffic. For configuration options, see the --promote
flag in the gcloud app deploy
reference.
Tip: Run gcloud help from the command line for a complete list of
arguments and flags.
appcfg
appcfg.py update [YOUR_APP_DIR] -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID]
By default, the initial version that you deploy to a service is automatically configured to receive 100% of traffic. However, all subsequent versions that you deploy to the same service must be manually configured, otherwise they receive no traffic.
Deploying multiple service applications
When your application is factored into multiple services, you can deploy and update individually targeted services or all the services simultaneously. Deploying updates to services can include updating individual configuration files or updating the source code in the corresponding versions.
For example, you can deploy and create two versions in App Engine, where each version runs in their own service. The first version serves as the frontend service and the other as the backend of your app. You can then deploy individual configuration files to update only the settings of a service. You can also choose to deploy a new version to a service in order to update the source code of the frontend, backend, or both simultaneously.
Requirements for multiple services
You use the same deployment commands for deploying and updating the multiple services of your application with the following requirements:
-
You must initially deploy a version of your app to the
defaultservice before you can create and deploy subsequent services. -
You must specify the ID of your service in the
app.yamlconfiguration file of the corresponding version. To specify the service ID, you include theservice: [YOUR_SERVICE_ID]element definition in each configuration file. By default, excluding this element definition from your configuration file deploys the version to thedefaultservice. -
You must specify all the corresponding
app.yamlconfiguration files in your deployment command to simultaneously deploy multiple services.
To deploy multiple services
From the root directory of the application where the configuration files are
located, you run the deployment command and specify the relative paths and file
names for each service's app.yaml file:
gcloud
gcloud app deploy [DEPLOYMENTS]
appcfg
appcfg.py update [DEPLOYMENTS]
Where [DEPLOYMENTS] is one or more configuration file's path and name. You
separate each configuration file that you specify with a single white space.
Example
gcloud
gcloud app deploy main/app.yaml service1/app.yaml service2/app.yaml
appcfg
appcfg.py update main/app.yaml service1/app.yaml service2/app.yaml
You will receive verification via the command line as each service is successfully deployed.
Updating indexes
If your app's index.yaml
file defines an index that doesn't yet exist, App Engine will create it after
you upload your app.
It can take a while for App Engine to create all the indexes. If your app is already configured to receive traffic, any query that requires one of the missing indexes will raise an exception until that index is built.
To avoid exceptions you must allow time for the indexes to build, for example:
-
You can deploy the new version of your app with a different version ID:
- Define a different version ID in your app's
app.yamlfile. - Deploy the new version.
- In the Cloud Platform Console, monitor the status of the app's indexes.
- After the index has been built, move traffic over to the new version.
- Define a different version ID in your app's
-
You can deploy the
index.yamlconfiguration file before you deploy the new version of your app:-
Deploy the
index.yamlfile:gcloud gcloud app deploy index.yaml
appcfg appcfg.py update_indexes [YOUR_APP_DIR] -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID]
-
In the Cloud Platform Console, monitor the status of the app's indexes.
- After the index has been built, deploy the new version of your app.
-
Troubleshooting
The following are common error messages that you might encounter:
Command not found-
If you did not create symlinks for the
appcfg.pyordev_appserver.pytools when you installed the SDK, you might need to specify the full directory path to run the tool, for example:[PATH_TO_APP_ENGINE_SDK]/appcfg.pyor[PATH_TO_CLOUD_SDK]/bin/dev_appserver.py.Note: To use
appcfg.pyyou must download and install the App Engine SDK for Python. [400] The first service (module) you upload to a new application must be the 'default' service (module)-
Before you can deploy and create the multiple services of your application, you must first deploy and create the
defaultservice. For details about how to deploy a version to thedefaultservice, see Deploying multiple service applications. Too Many Versions (403)-
App Engine has a limit on the number of deployed versions of your application. These differ for free applications and deployed applications. You can use the Cloud Platform Console to delete an older version and then upload your latest code.
What's next
- Learn how to download source code you've uploaded.
- Use services to build a large application.
- Split traffic or migrate traffic to route traffic to the versions you deploy.
- Review the
gcloud app deploycommand line arguments and flags. - Optional: Review the
appcfgcommand line arguments.