All documentation

Pull request previews

A separate copy of the app for every GitHub pull request or GitLab merge request, with its own link.

A preview is a copy of your app for every open pull request (a merge request in GitLab). You can show a branch to a client or a teammate at its own link without touching production. A new commit in the PR rebuilds the preview. When the PR is closed or merged, the preview is deleted.

How it works

  • Preview address: pr-<number>-<name>-xxxxxx.<apps domain>, for example pr-12-shop-ab12cd.... You will find it on the resource's “Previews” tab.
  • A preview is a regular resource on the plan of the main app. It is billed by the hour; in “Balance” previews have their own line “Pull request previews”.
  • A preview always sleeps after 5 minutes without visitors and wakes up on the first request. While it sleeps you pay only for the disk.
  • By default a preview lives 72 hours after the last commit, then it is deleted automatically.
  • At most 2 previews per resource are open at once (you can raise it to 10). The account resource limit applies too. If the balance does not cover at least one hour, the preview is not created and the reason appears in the resource events.
  • Deleting the main app deletes all its previews.
  • Background processes (bots, workers) get no previews: a second process with the same Telegram token would break the main one. Use a separate test token in the staging environment.

1. Turn previews on

  1. Open the app → “Deploy” tab. If it says the webhook signature is not checked, press “New URL and secret”. The secret is shown once. Previews are created only from signed events.
  2. Open the “Previews” tab, tick “Create previews for pull requests” and save.

The repository must be connected over https. For a private repository add an access token on the “Deploy” tab.

2. Set up the webhook in GitHub

Settings → Webhooks → your deploy webhook (or Add webhook):

FieldValue
Payload URLthe webhook URL from the “Deploy” tab
Content typeapplication/json
Secretthe secret from step 1
Which events“Let me select individual events”: Pushes and Pull requests

2. Or in GitLab

Settings → Webhooks → your webhook:

FieldValue
URLthe webhook URL from the “Deploy” tab
Secret tokenthe secret from step 1
TriggerPush events and Merge request events

One URL accepts both pushes (deploys the main app) and PR events (previews).

Link in the PR

If the app has a saved Git access token, we post a comment with the preview link right in the PR. The token needs permission to comment: Pull requests: Read and write for a GitHub fine-grained token, scope api in GitLab. Without a token the link is shown only on the “Previews” tab and in the CLI: uc previews ls shop.

Variables

A preview from your own repository gets the regular variables of the main app. References like ${{api.URL}} are resolved in the project's preview environment, and whatever is missing there comes from staging. This way a frontend preview talks to the staging API, not to production. Shared preview variables: uc env set --project shop --env preview KEY=value.

Production secrets are not passed by default: variables whose name contains PASSWORD, SECRET, TOKEN, KEY and the like, generated passwords of catalog apps, and URLs with a password such as DATABASE_URL. If the preview or staging environment has a shared variable with the same name, the preview gets that one. Every withheld variable is noted in the preview events. The “Pass parent secrets to previews” option passes them too, but then code from any branch gets production passwords.

Pull requests from forks

Code from someone else's fork could read your secrets, so such PRs are not deployed by default. In “Pull requests from forks” you can choose “After approval in the panel”. The preview then appears in the list as “awaiting approval”. “Approve” approves the specific commit shown in the list: exactly that commit is built, without your variables and without the Git token, even if the author has pushed more since. Every new commit from the fork needs approval again.

CLI and API

uc previews ls shop           # open previews and their URLs
uc previews rm shop 12        # delete the preview of PR #12
uc previews approve shop 14   # approve PR #14 from a fork

API v1: GET and PUT /api/v1/workloads/{id}/previews, POST .../previews/{number}/approve, DELETE .../previews/{number}.