Managing App Engine Applications
Cloud SDK includes the
gcloud preview app
command for managing App Engine applications.
You can use this command to upload new versions of application code, configuration, and
static files for your app to App Engine. You can also use the command to
manage datastore indexes and download log data.
Preview
This is a Preview release of
gcloud preview app
.
As a result, we may make backward-incompatible changes and it is not covered
by any SLA or deprecation policy. Developers should take this into account
when using this Preview release of
gcloud preview app
.
Table of Contents
- Installation
- Running the app locally
- Deploying an app
- Listing app versions
- Deploying datastore indexes
- Deploying Task Queue configuration
- Deploying the DoS protection configuration
- Managing scheduled tasks
- Downloading source code
- Downloading logs
Installation
In order to use
gcloud preview app
, you need to install the
app
component:
$ gcloud components update app
If you have not already installed the Cloud SDK, follow the installation instructions in the Quick Start guide.
Running the app locally
Once you have authenticated into Google Cloud Platform and created a directory for your app containing app.yaml configuration file, you can run your app in a local development web server.
$ gcloud preview app run DIRECTORY
The web server listens on port 8080 by default. You can visit the application at this URL: http://localhost:8080 .
To change which port the web server uses, use the
--host
flag:
$ gcloud preview app run --host localhost:9999 DIRECTORY
To stop the web server in Mac OS X or Unix, press Control-C, or Control-Break in your command prompt window if you are running in Windows.
Deploying an app
To deploy application files, run
gcloud preview app
with the
deploy
command
and the name of your application's root directory. The root directory
should contain the
app.yaml
file for the application.
$ gcloud preview app deploy DIRECTORY
gcloud preview app deploy
deploys all
application code and modules as well as indexes, cron jobs, denial of service settings, and
queues. You can deploy some of the configuration settings of your app
separately. For example, to deploy just indexes, see
Deploying datastore indexes
.
Only application owners and the developer who uploaded the code can download it. If anyone else attempts to download the app, they'll see an error message.
Listing app versions
You can maintain multiple versions of you App Engine application. To list the versions of the default module for your application, use the command:
$ gcloud preview app list-versions default
To list all versions for all modules, use
gcloud preview app list-versions
without
specifying a module.
Deploying datastore indexes
When you deploy an application using
gcloud preview app deploy
, it includes
the app's
index.yaml
file, if it exists. If the
index.yaml
file defines an index that
doesn't exist yet on App Engine, App Engine creates the new index.
Depending on how much data is already in the datastore that needs to be mentioned
in the new index, the process of creating the index may take a while.
If the app performs a query that requires an index that hasn't finished building yet, the query will raise an exception.
To prevent this, you must ensure that the new version of the app that requires a
new index is not the live version of the application until the indexes finish building.
One way to do this is to give the app a new version number in
app.yaml
whenever you
add or change an index in
index.yaml
. The app is uploaded as a new version, and
does not become the default version automatically. When your indexes have finished building,
you change the default version to the new one using the "Versions" section of the
Admin Console
.
Another way to ensure that new indexes are built before the new app goes live is
to deploy the
index.yaml
configuration separately before deploying the app.
To deployg only the index configuration for an app, use the following command:
$ gcloud preview app deploy DIRECTORY/index.yaml
You can check the status of the app's indexes from the "Indexes" section of the Admin Console . For more information about indexes, see Datastore Index Configuration .
Deploying Task Queue configuration
You can deploy just the configuration for an app's task queues without
uploading the full application. To upload the
queue.yaml
file, use the
command:
$ gcloud preview app deploy DIRECTORY/queue.yaml
For more information, see Task Queue Configuration .
Deploying the DoS protection configuration
You can deploy just the configuration for the DoS Protection for an app without
uploading the full application. To upload the
dos.yaml
file, use the
command:
$ gcloud preview app deploy DIRECTORY/dos.yaml
For more information, see DoS Protection Service .
Managing scheduled tasks
App Engine supports scheduled tasks (known as cron jobs). You can deploy
just the cron jobs configuration for an app without uploading the full application.
To upload the
cron.yaml
file, use the command:
$ gcloud preview app deploy DIRECTORY/cron.yaml
For more information, see the Scheduled Tasks With Cron documentation.
Downloading source code
You can download an application's source code for the default module with the command:
$ gcloud preview app download --version VERSION --output-dir OUTPUT_DIR MODULE default
Only the developer who uploaded the code and the application owner(s) can download it. If anyone other than these parties attempts to download the app, they will see an error message.
Downloading logs
App Engine maintains a log of messages that your application emits using the standard library of the language the app uses, as well as other messages printed to the standard error stream.
App Engine also records each request in the log. Each log level has a fixed buffer size that controls the amount of log information you can access. Normally, you use logging features more at lower log levels; thus, the time window is smaller for log events at these levels. You can browse your app's logs of the last 90 days from the "Logs" section of the Admin Console .
If you wish to perform more detailed analysis of your application's logs, you
can download the log data to a file on your computer. To download logs to a
file named
mylogs.txt
, use the following command:
$ gcloud preview app get-logs --version 1 default mylogs.txt
By default, the command downloads log messages from the current calendar day (since midnight Pacific Time) with a log level of INFO or higher (omitting DEBUG level messages). The command overwrites the local log file. You can adjust the number of days, the minimum log level, and whether to overwrite or append to the local log file using command-line options. See below for more information on these options.
You can limit the log messages that are downloaded to just those emitted during
request on a given domain name using the
--vhost VHOST
option. You can use
this to download the logs for your live app using a Google Apps domain or
http://your_app_id.appspot.com
, excluding log messages emitted by versions
you are testing on URLs such as
http://2.latest.your_app_id.appspot.com
.
Or you can use it to download just the log messages for a given test domain.
Using an HTTP proxy
If you are running
gcloud preview app
behind an HTTP proxy, you must tell
gcloud preview app
the name of the proxy. To set an HTTP proxy for
gcloud preview app
,
set the
http_proxy
and
https_proxy
environment variables.
Using Windows (in Command Prompt):
$ set HTTP_PROXY=http://cache.mycompany.com:3128
$ set HTTPS_PROXY=http://cache.mycompany.com:3128
$ gcloud preview app deploy --env-vars HTTP_PROXY,HTTPS_PROXY DIRECTORY
Using the command line in Mac OS X (in Terminal) or Linux:
$ export http_proxy="http://cache.mycompany.com:3128"
$ gcloud preview app deploy --env-vars HTTP_PROXY,HTTPS_PROXY DIRECTORY