Skip to main content

Preview Apps

Preview apps are a way to create fork applications that are built from a Pull Request (Merge Request). Preview apps are only supported for Git repository based projects.

Enable preview apps

Go to Projects → Settings and enable preview apps. Set up which cluster you want to deploy the preview app to. Often, you'll want to set up a separate cluster so that the preview apps aren't deployed on the same cluster as your production application.

Create your first preview app

Navigate to Projects → Your Project → Preview Apps. You should see any open pull requests available to create a preview app.

Configuring preview apps

To automatically configure your preview apps with environment variables, services, etc, create a YAML file in the root of your project called canine.yml. An example canine.yml file:

scripts:
predeploy: echo "Pre deploy script"
postdeploy: echo "Post deploy script"
predestroy: echo "Pre destroy script"
postdestroy: echo "Post destroy script"
services:
- name: web
container_port: 6379
service_type: web_service
- name: bg-worker
container_port: 6379
service_type: background_worker
environment_variables:
- name: DATABASE_URL
value: postgres://localhost/test

The available variables are:

KeyTypeDescription
scripts.predeploystringScript to run before deployment
scripts.postdeploystringScript to run after deployment
scripts.predestroystringScript to run before destruction
scripts.postdestroystringScript to run after destruction
servicesarrayList of services to deploy
services[].namestringName of the service
services[].container_portnumberPort the container exposes
services[].service_typestringType of service (web_service, background_worker, cron_job)
environment_variablesarrayList of environment variables
environment_variables[].namestringName of the environment variable
environment_variables[].valuestringValue of the environment variable

Templating canine.yml with ERB

Often, you'll want to template the configuration of a new preview app. canine.yml files support ERB templating. For example, a common use case is to set up each preview app with its own separate database, and then delete that database when the preview app is destroyed.

You can achieve something that with a canine.yml file like:

environment_variables:
- name: DATABASE_URL
value: "postgres://postgres_url/preview_app_database_<%= number %>" # Have each preview app have its own database based on the pull request number
scripts:
predeploy: "/script-to-create-database" # Create the database when the preview app is first created
postdestroy: "/script-to-drop-database" # Delete the database when the preview app is destroyed
services:
- name: web
container_port: 6379
service_type: web_service

The available variables are:

VariableTypeDescriptionExample
cluster_idstringID of the cluster the preview app is deployed to1
cluster_namestringName of the cluster the preview app is deployed to (within Canine)staging
project_idstringID of the new preview app1
project_namestringName of the new preview app (within Canine)whiteboarder-5
numbernumberPreview app number5
titlestringTitle of the preview app"Bump version of whiteboarder"
branch_namestringBranch the preview app is deployed frombump_version
usernamestringGit username of the pull request creatorczhu12