Travis

Google App Engine Deployment

This page documents deployments using dpl v1 which is currently the legacy version. The dpl v2 is released, and we recommend useig it. Please see our blog post for details. dpl v2 documentation can be found here.

Travis CI can automatically deploy your Google App Engine or Managed VMs application after a successful build.

For a minimal configuration, add the following to your .travis.yml:

deploy:
  provider: gae
  keyfile: "YOUR SERVICE ACCOUNT JSON FILE"
  project: "YOUR PROJECT ID"

Then go to the Google Cloud Console Dashboard and:

  1. Enable “Google App Engine Admin API”,
  2. Go to “Credentials”, click “Add Credential” and “Service account key”, finally click “JSON” to download your Service Account JSON file.

It is strongly recommended that you encrypt your key before committing it to a repo. First make sure you have the Travis command line tool installed. Then execute the following command from the terminal:

travis encrypt-file client-secret.json --add

The --add flag automatically adds the decryption step to the .travis file.

Keep in mind that the above command has to run in your project directory, so it can modify the .travis.yml for you.

More detailed instructions for encrypting keys using Travis can be found here.

Deploy Project #

By default, the project will be deployed with the same name as the repository. Usually, you will want to explicitly configure the project option to match the project ID found in your Cloud console (note that this is sometimes, but not always, the same as the project name).

You can explicitly set the project id via the project option:

deploy:
  provider: gae
  keyfile: ...
  project: continuous-deployment-demo

Deploy Version #

Either the version flag or the default option must be set. If default is true, the default version will be deployed to, which will be http://your-project-id.appspot.com. If the version flag is set instead, it will deploy to http://version-dot-your-project-id.appspot.com.

Deployment Branch #

By default, Travis will only deploy from your master branch.

You can also explicitly specify the branch to deploy from with the on option:

deploy:
  provider: gae
  keyfile: ...
  project: ...
  on: production

Alternatively, you can also configure it to deploy from all branches:

deploy:
  provider: gae
  keyfile: ...
  project: ...
  on:
    all_branches: true

Builds triggered from Pull Requests will never trigger a deployment.

Deploy without Promoting #

By default, when your application is deployed, it will be promoted to receive all traffic. You can disable that using the no_promote option:

deploy:
  provider: gae
  keyfile: ...
  project: continuous-deployment-demo
  no_promote: true

In addition to that, and according to the Google Cloud SDK changelog, “in a future Cloud SDK release, deployments that promote the new version to receive all traffic will stop the previous version by default”.

You can prevent that from happening by setting the option no_stop_previous_version:

deploy:
  provider: gae
  keyfile: ...
  project: continuous-deployment-demo
  no_stop_previous_version: true

Skip Cleanup #

Many App Engine apps use pip to vendor library requirements into the directory, and sometimes you need build artifacts or other credentials to deploy. If so, you want to avoid the Travis cleanup step that will clean you working directory before the deployment.

deploy:
    provider: gae
    skip_cleanup: true

Example #

See this link for an example App Engine app with a Travis deployment configured. See the other branches in the project for Managed VMs examples, and examples without using this provider.

Other Configuration Options #

  • project: Project ID used to identify the project on Google Cloud.
  • keyfile: Path to the JSON file containing your Service Account credentials in JSON Web Token format. To be obtained via the Google Developers Console. Defaults to "service-account.json". Note that this file should be handled with care as it contains authorization keys.
  • config: Path to your module configuration file. Defaults to "app.yaml". This file is runtime dependent (Go, Java, PHP, Python)
  • version: The version of the app that will be created or replaced by this deployment. If you do not specify a version, one will be generated for you. See gcloud app deploy
  • default: Flag to set the deployed version to be the default serving version. See gcloud app deploy
  • verbosity: Lets you adjust the verbosity when invoking "gcloud". Defaults to "warning". See gcloud.
  • docker_build: If deploying a Managed VM, specifies where to build your image. Typical values are "remote" to build on Google Cloud Engine and "local" which requires Docker to be set up properly (to utilize this on Travis CI, read Using Docker on Travis CI). Defaults to "remote".