Preview environments

Every pull request can get its own running copy of an environment: built from the PR’s branch, with empty databases its migrations fill, at its own URL, posted on the PR, and gone when the PR closes.

Turning it on

In the environment’s yawl.yaml:

project: acme
environment: staging
server: hel1
preview: true

Only one environment of a project has preview: true. The GitHub App must be connected (yawl github connect). An App made before previews existed needs two changes in its settings on GitHub: under Permissions, Pull requests: Read and write (then accept it on the installation), and under Subscribe to events, Pull request. Until then no preview is made. Without the permission alone, previews still run and the project page shows their state, but the PR gets no comment.

What a preview is

When a pull request is opened (or reopened) against a repository that one of that environment’s services builds, Yawl makes the environment pr-<number> in the same project, on the same server:

  • the services of the PR’s repository build the PR’s branch, and a push to it deploys again; the others build what the source builds;
  • databases start empty, and the release command (migrations) runs as in any deploy;
  • variables are copied from the source environment as they are (sealed to the same agent: no value crosses the panel), and a reference like acme-db.url names the preview’s own database;
  • no cron jobs, no custom domains, no outside ports; volumes start empty;
  • no Telegram messages, backups or watcher checks.

Yawl keeps one comment on the PR, edited as things change:

Preview: https://api-pr-12.1-2-3-4.sslip.io (deployed 4f2c1e0)

or the failure, for example Preview: deploy of 4f2c1e0 failed: Health check failed, or Preview: acme-db failed: <cause> when its database could not be made (the next push tries again).

A source environment whose variables use another environment’s database (production/acme-db.url) gets no previews: the PR’s migrations would change that database. The PR says so.

Limits

  • At most 5 previews per project run at once. A sixth waits, and the project page and the PR say pr-31 waits: 5 previews are running. It starts when one closes.
  • A pull request from a fork gets no preview: its code would run on your server. The PR says so.
  • pr- names are reserved: yawl apply refuses an environment called pr-….

Removal

A preview is removed when its PR is closed or merged, or after 7 days without a push (a push renews it), or with Close on the project page. It skips the trash: containers, databases, volumes and rows go within a minute, and the PR’s comment says Preview removed. Reopening the PR makes it again.