Travis

AWS OpsWorks Deployment

This page documents deployments using the dpl v2. Please see our blog post for details. You can check previous dpl v1 documentation here.

Travis CI can automatically deploy your AWS OpsWorks application after a successful build.

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

deploy:
  provider: opsworks
  access_key_id: <encrypted access_key_id>
  secret_access_key: <encrypted secret_access_key>
  app_id: <app_id>
  edge: true # opt in to dpl v2

You can obtain your AWS Access Key Id and your AWS Secret Access Key from here.

region defaults to us-east-1. If your application is located in a different region you will see an error Unable to find app.

Status #

Support for deployments to AWS OpsWorks is stable.

Known options #

Use the following options to further configure the deployment.

access_key_id AWS access key id — required, secret, type: string
secret_access_key AWS secret key — required, secret, type: string
app_id The app id — required, type: string
region AWS region — type: string, default: us-east-1
instance_ids An instance id — type: string or array of strings
layer_ids A layer id — type: string or array of strings
migrate Migrate the database. — type: boolean
wait_until_deployed Wait until the app is deployed and return the deployment status. — type: boolean
update_on_success When wait-until-deployed and updated-on-success are both not given, application source is updated to the current SHA. Ignored when wait-until-deployed is not given. — type: boolean, alias: update_app_on_success
custom_json Custom json options override (overwrites default configuration) — type: string

Shared options #

cleanup Clean up build artifacts from the Git working directory before the deployment — type: boolean
run Commands to execute after the deployment finished successfully — type: string or array of strings

Environment variables #

All options can be given as environment variables if prefixed with AWS_ or OPSWORKS_.

For example, access_key_id can be given as

  • AWS_ACCESS_KEY_ID=<access_key_id> or
  • OPSWORKS_ACCESS_KEY_ID=<access_key_id>

Securing secrets #

Secret option values should be given as either encrypted strings in your build configuration (.travis.yml file) or environment variables in your repository settings.

Environment variables can be set on the settings page of your repository, or using travis env set:

travis env set AWS_ACCESS_KEY_ID <access_key_id>

In order to encrypt option values when adding them to your .travis.yml file use travis encrypt:

travis encrypt <access_key_id>

Or use --add to directly add it to your .travis.yml file. Note that this command has to be run in your repository’s root directory:

travis encrypt --add deploy.access_key_id <access_key_id>

Migrate the Database #

If you want to migrate your rails database on travis to AWS OpsWorks, add the migrate option:

deploy:
  provider: opsworks
  # ⋮
  migrate: true

Waiting for Deployments #

By default, the build will continue immediately after triggering an OpsWorks deploy. To wait for the deploy to complete, use the wait_until_deployed option:

deploy:
  provider: opsworks
  # ⋮
  wait_until_deployed: true

Travis CI will wait up to 10 minutes for the deploy to complete, and log whether it succeeded.

Updating App Settings after successful Deployments #

By default the deploy from Travis CI triggers a deployment on OpsWorks but does not touch any other configuration. To also update the revision in App Settings use the update_app_on_success option. In addition you have to set the wait_until_deployed option:

deploy:
  provider: opsworks
  # ⋮
  wait-until-deployed: true
  update-app-on-success: true

Travis CI will wait until the deployment returns successful and only then update the revision in App Settings.

Pull Requests #

Note that pull request builds skip the deployment step altogether.

See also #