Deploy a preview for each pull request
Turn on pull request previews for a project so every same-repository pull request gets its own environment, deployed from its branch and deleted when the pull request closes or goes idle.
A preview is a short-lived environment that NebulaCtrl clones from a base environment for one pull request. You review the change running on its own deployment before you merge.
Before you begin
- Connect a Git provider and deploy at least one service from the repository the pull requests target. See Deploy from Git and Git providers and registries. GitHub, Forgejo and GitLab connections deliver pull request events.
- Have a base environment: a non-production environment of the project that is bound to a cluster. A preview never clones a production environment or another preview. If the project has no such environment, the settings show "Create a non-production environment first."
- Hold the
adminrole or higher to change preview settings or to close a preview by hand. Theviewerrole can read the settings. - If your GitHub connection predates previews, approve the new pull request permission. Settings > Integrations shows a warning titled "Approve the new pull request permission on GitHub to enable previews" with a Review on GitHub button. Until you approve it, no preview is created for that connection. Pushes still deploy.
Turn on previews
Open the project, open the environment menu in the top bar, and select Environment settings…. The panel has a section named Pull request previews.
Turn on Previews. Three rows appear: Base environment, Expire idle previews after and Focused previews.
Under Base environment, choose the environment to clone. Only non-production environments are listed.
Under Expire idle previews after, choose 1 day, 3 days or 7 days. The default is 3 days.
Under Focused previews, choose whether a pull request builds only what it changes. See Build only what a pull request changes.
Select Save. A toast reads "PR previews on": "The next same-repository pull request gets its own environment."
You can also open the environment menu in the top bar, select + New environment, choose PR previews, pick the base environment and lifetime, and select Enable PR previews.
If the base is production, the API answers 422 with baseEnvironmentId set to the offending field and a message that asks for a non-production environment. Turning previews on without a base returns 422 with "is required to enable previews; pick the environment previews are cloned from".
Changing the settings never touches previews that already exist. They keep the lifetime they were created with.
What a pull request creates
Open a pull request from a branch of the same repository. NebulaCtrl creates an environment named pr-NUMBER, where NUMBER is the pull request number. It appears under Pull request previews in the environment menu as "PR #NUMBER · BRANCH · expires in 3 days".
NebulaCtrl starts a build of every service in the project that tracks the repository, from the pull request's head commit. A service with an image push trigger waits for the externally built tag instead. With Focused previews on, only the services the pull request touches and the services they need are built; see Build only what a pull request changes.
Push more commits to the branch. Each push builds and deploys, and restarts the idle clock.
The preview has auto-deploy on and tracks the pull request's head branch. The Environment settings… panel of a preview shows the pull request, its branch and when it Expires.
What the preview copies from the base environment:
| Copied | Not copied |
|---|---|
| The cluster binding | Domains |
| Environment variables and service variables, secrets included | Releases |
| External resources | |
| Per-environment settings: process, volume and service overrides |
A service that tracks a different repository gets no build in the preview. See Variables for how variables resolve.
NebulaCtrl posts a commit status named nebulactrl/pr-NUMBER on the head commit for builds and deployments. Its link opens the service's Deployments tab in the preview.
A preview is not a protected environment, so its deployments need no approval and a deploy freeze does not apply.
Build only what a pull request changes
With Focused previews on, a pull request builds the services it touches and nothing else. The other services are still created in the preview, so the environment looks the same as its base, but they are skipped: not built, not deployed, and marked Skipped with the reason. A project created with no saved preview settings has Focused previews on. A project that existed before focused previews keeps it off until you turn it on in the Pull request previews section of Environment settings…, so its previews build every service as before.
On every pull request open and every push to its branch, NebulaCtrl reads the files the pull request changes and decides each service from them:
| Service | Deployed when |
|---|---|
| Built from Git, with watch paths | A changed file matches one of its watch paths |
| Built from Git, without watch paths | A changed file is under its build context. A service built from the repository root, ., is affected by every change |
| Image service or database | Never because of a file. It is deployed only when another deployed service needs it |
| Any service | A deployed service needs it: a variable references it, it is connected to it, or the deployed service's Deploy after list names it. The walk follows the chain, so what a needed service needs is deployed too |
A service you deployed anyway stays deployed on every later push. When NebulaCtrl cannot read the changed files, every service is deployed and the reason names why: a preview is never short of a build because a lookup failed.
Set watch paths
Watch paths are globs, relative to the repository root, that name the files that rebuild a service. Use them for a service that depends on files outside its build context, such as a shared library in a monorepo.
| Pattern | Selects |
|---|---|
apps/web | Everything under apps/web |
apps/web/** | The same |
*.md | Markdown files in the repository root only |
**/*.md | Markdown files at any depth |
!apps/web/**/*.md | Excludes the files it matches; the last pattern that matches a file decides |
Open the service, select Settings, find Watch paths under Source and select Edit…. Write one glob per line and select Save. A toast reads "Watch paths saved". Only services built from Git show the row.
See what was skipped
Open the preview, open the environment menu in the top bar and select Environment settings…. Under Pull request, every service of the pull request is listed as Deployed, Deployed anyway or Skipped, with the reason in full. A skipped service also carries a Skipped badge on its canvas card, and hovering it shows the reason. The same list over the API is listPreviewServices (GET /api/v1/environments/ENVIRONMENT_ID/preview/services).
On the pull request, NebulaCtrl keeps one comment, titled "NebulaCtrl preview pr-NUMBER". It shows the short head commit, an Open the preview link, a Deployed table of the services built from that commit and a Skipped table with each reason and a Deploy anyway link. It edits the comment in place at every push and every Deploy anyway. When the preview is deleted, it edits the comment to say the preview was deleted because its pull request closed, or because it saw no push for its whole lifetime. The comment needs write access to pull requests. A GitHub App created for NebulaCtrl asks for it; an installation that granted read access only keeps working, and gets no comment until you approve Pull requests: Read and write for the App on GitHub. A Forgejo or GitLab token needs permission to comment on the repository. A refused comment never fails the preview.
Deploy a skipped service anyway
Open Environment settings… of the preview.
Next to the skipped service, select Deploy anyway. A toast reads "Deploying SERVICE", naming every service it started. Right-clicking the skipped card and selecting Deploy anyway, or selecting its Skipped badge, does the same.
NebulaCtrl builds the pull request's current head for that service and for the skipped services it needs, so that it runs. The service shows Deployed anyway and every later push keeps it current. Over the API this is deployPreviewServiceAnyway (POST /api/v1/environments/ENVIRONMENT_ID/preview/services/SERVICE_ID/deploy); the caller needs the deployer role or higher.
Close a preview
A preview is deleted when:
- The pull request is closed or merged. NebulaCtrl deletes the preview as soon as the provider reports it.
- The preview sits idle past its lifetime. The lifetime counts from the last push to the pull request, or from creation before the first push. NebulaCtrl checks every 5 minutes.
To delete one earlier:
Closing a preview deletes its namespace and everything the preview owns at once. A preview is not recoverable: it skips the recovery window that applies to other environments. The pull request is untouched. A later push to the open pull request creates a new preview from the base environment.
Open the environment menu in the top bar. Under Pull request previews, select the ✕ next to the preview.
In the dialog titled "Close pr-NUMBER?", select Close preview. A toast reads "Closed pr-NUMBER".
The same operation over the API is deleteEnvironment (DELETE /api/v1/environments/ENVIRONMENT_ID). For environments that are not previews, see Restore a deleted resource.
Limits
- Only pull requests from the same repository get a preview. A pull request from a fork never does, because it would build and run code the organization has not reviewed with the base environment's variables.
- One preview per pull request and project. If several projects track the repository, each creates its own.
- A pull request opened before you turned previews on gets its preview at its next push, or when it is reopened.
- The idle lifetime is one of 1, 3 or 7 days.
- If the base environment is bound to no cluster, the preview is created but nothing is built.
- A focused preview needs the pull request's list of changed files. If the provider cannot list them (a Forgejo older than Gitea 1.18, a GitLab token without access to the merge request, a pull request of more than 3,000 files), every service is deployed and the reason says so.
- Watch paths decide only which services a preview builds. They do not change what a push to a persistent environment builds.
If a pull request creates no preview, check Settings > Integrations. A connection whose last webhook delivery was declined shows Last delivery failed. A fork, previews switched off for the project and a repository no service tracks all decline the delivery.
Verify
- Open a same-repository pull request.
- Open the environment menu.
pr-NUMBERis listed under Pull request previews. - On the pull request, the commit shows a
nebulactrl/pr-NUMBERstatus. It turns green when the deployment is healthy.
Next steps
Compare and sync environments
Compare two environments of a project service by service, then stage the variables, settings and releases you pick from one into the other as an ordinary change set.
Restore a deleted resource
Restore a service, database, volume, environment or project you deleted within the recovery window, delete it for good before the window ends, and change how long NebulaCtrl keeps deleted resources.