Ployter

Pull request previews

How to deploy a temporary copy of the service for each pull request (GitHub) or merge request (GitLab), with its own address and a link in the PR.

With previews turned on, each pull request to the service's branch deploys a copy of it with the PR's code, at its own address. The link shows up in a comment on the PR. On every push to the PR, the preview updates. When the PR closes, the preview is removed.

Requirements

  • The service's source must be GitHub, GitLab or Bitbucket. On GitLab, the card is called Merge request previews and the comment goes on the MR. See Connect GitLab.
  • The panel needs to receive the repository's pull_request event. With the GitHub App, this is already set up. With a token, the panel creates the webhook for you when you turn on previews, as long as the token has webhook permission. See Connect GitHub.
  • For the comment with the link to show up on the PR, the credential must be able to comment on pull requests. Without that, the preview works the same, it just doesn't comment.
  • The service's server must have a public IP, because the preview uses an automatic domain (.ployter.app).

Turn on previews

  1. Open the service (e.g. web) and go to Settings.
  2. In the PR previews card, turn on Enable.
  3. Adjust:
    • Previews at the same time: from 1 to 20. A PR over the limit gets a comment asking you to close another one.
    • Removed after how many days without a push: from 1 to 90.
  4. Under Preview variables, add what changes in the preview (see below).
  5. Click Save.

PR previews card turned on for the web service, with one preview live
PR previews card turned on for the web service, with one preview live

Preview variables

The preview copies the service's variables and the shared variable sets. Under Preview variables, you only define what changes:

  • Variable: adds a name and the value it has in the preview, for example a test database in DATABASE_URL.
  • Don't copy: leaves the variable out of the preview. Use it for production keys that a PR shouldn't use.
DATABASE_URL=${{mysql-staging.MYSQL_URL}}
APP_URL=https://preview.loja.com.br
Warning

Without preview variables, the copy uses the same variables as production, including the database. Point the preview to a test database.

What goes to the preview and what doesn't

Included: the service's settings (build, port, health check, limits), the variables with the preview ones on top, the variable sets and the linked databases.

Not included:

  • Volumes: the preview starts empty.
  • Extra processes and scheduled jobs.
  • The release command (migrations). A PR doesn't change the database on its own.

How a preview works

  • A PR opened (or moved out of draft) against the service's branch creates the preview and deploys the PR's latest commit. It is ready in 1 to 3 minutes.
  • The preview shows up in the project as a service with the PR icon, and its header shows Preview PR #12 with the link to the PR.
  • Each push to the PR runs a new deploy of the preview.
  • The PR comment is updated on each push, without flooding the conversation.
  • When the PR is closed or merged, the preview is removed. It is also removed after the number of days without a push that you set.

Draft PRs don't get a preview until they are ready for review. PRs from forks don't either: outside code would run with the service's variables.

View and remove previews

The PR previews card lists the live previews, with the link, the PR and the time of the last push. Click Remove to take a preview down before the PR closes. The PR stays open, and a new push deploys another preview.

When you turn off previews in the card, the live ones are removed right away.