preview environments.md
Preview Environments — Test proposed changes in a disposable copy of your production environment.
Preview environments require a Pro workspace plan or higher.
For details, see the pricing page.
It is critical to have testing and staging environments accurately reflect production, but achieving this can be a major operational hassle. Most engineering teams use a single staging environment which makes it hard for developers to test their changes in isolation; the alternative is for devops teams to spin up new testing or staging environments manually and tear them down after testing is done.
Render preview environments solve this problem by automatically creating a fresh copy of your production environment (including services, datastores, and environment groups) with every pull request, so you can test your changes safely and confidently. Copies of datastores and persistent disks do not include data from their corresponding "base" resource (you can seed sample data as part of preview environment initialization).
Preview environments do not currently support Render Workflows.
If you enable preview environments, Render automatically skips creating preview copies of any workflows your Blueprint defines.
Render keeps your preview environments up to date on every commit and automatically destroys them when the original pull request is merged or closed. You can also set up an expiry time to automatically clean up preview environments after a period of inactivity.
Use preview environments to:
- Test out logical and visual changes in a live, production-like environment
- Quickly share links to upcoming features with teammates, customers, and clients
- Run multi-service integration tests against a high-fidelity copy of your production environment before merging
Getting started
Make sure your resources are defined in a YAML file configured as a Blueprint in the Render Dashboard.
- By default, Render creates a Blueprint using the
render.yamlfile at your repository's root. You can specify a custom file path in the Render Dashboard. For details, see Render Blueprints.
- By default, Render creates a Blueprint using the
To enable preview environments for a Blueprint, set the
previews.generationkey to one ofmanualorautomaticin your YAML file:
previews:
generation: automatic
services:
- type: web
...
For details on each option, see Manual vs. automatic preview environments.
Setting the deprecated field
previewsEnabled: trueis equivalent to setting this field toautomatic.
- Merge your changes to your Blueprint's linked branch.
You're all set! Open a new pull request in your repository and see your preview environment deploy with status updates right in the pull request. You can visit the URL for your preview environment by clicking View deployment next to your web service deployment.
[image: preview environment deployment]
If you'd like to try this for yourself, fork our Preview Environments example repository, synchronize the render.yaml file in your dashboard, and open a new pull request.
Manual vs. automatic preview environments
Manual
By default, Render does not create preview environments for PRs.
To create a preview environment for a specific PR, include the string [render preview] in your PR's title (not the commit message):
[render preview] Update homepage
You can also edit an existing PR's title to add or remove [render preview]. If you do, Render provisions or deletes associated preview instances accordingly.
Automatic
By default, Render creates a preview environment for every PR against your Blueprint's linked branch.
To skip creating a preview environment for a specific PR, include any of the following strings in your PR's title (not the commit message):
[skip preview][skip render][preview skip][render skip]
You can also edit an existing PR's title to add or remove one of these strings. If you do, Render provisions or deletes associated preview instances accordingly.
Override preview compute plans
Services in a preview environment can use a different compute plan from their production counterparts. By using smaller compute plans for preview environments, you can reduce costs.
- For Render Postgres and Key Value instances, set the
previewPlanfield. - For all other service types, set the
previews.planfield.
See example render.yaml declarations below. For all supported values, see the Blueprint YAML Reference.
previews:
generation: automatic
services:
- type: web
plan: 1c-2g
previews: # highlight-line
plan: 0.5c-512mb # highlight-line
name: express-server
runtime: node
- type: keyvalue
plan: 1g
previewPlan: 256mb # highlight-line
name: private cache
ipAllowList: [] # only allow internal connections
databases:
- name: my_test_db
plan: 1c-4g
previewPlan: 0.5c-1g # highlight-line
previewDiskSizeGB: 5 # highlight-line
Override number of preview instances
Web services, private services, and background workers in a preview environment can use a different number of instances from their production counterparts. By using fewer instances for preview environments, you can reduce costs.
See example render.yaml declarations below. For all supported values, see the Blueprint YAML Reference.
If you don't specify a preview number of instances for a service, Render uses the same number of instances that you use in production. If autoscaling is configured, Render uses the minimum number of instances.
previews:
generation: automatic
services:
- type: web
plan: 1c-2g
numInstances: 7
previews: # highlight-line
numInstances: 6 # highlight-line
name: express-server
runtime: node
- type: web
plan: 1c-2g
scaling:
minInstances: 2
maxInstances: 10
targetCPUPercent: 70
previews: # highlight-line
numInstances: 6 # highlight-line
name: autoscaling-express-server
runtime: node
Environment variables
You can override environment variables in preview environments with previewValue. This can be useful if you need to override a production API key with a test key, or if you'd like to use a single database across all preview environments. Environment variable overrides are supported for web services, private services, and environment groups.
previews:
generation: automatic
services:
- type: web
plan: 1c-2g
name: express-server
runtime: node
envVars:
- key: MY_API_KEY
value: production-api-key
previewValue: test-api-key # highlight-line
Placeholder environment variables
Placeholder environment variables defined with sync: false are not copied to preview environments. To share secret variables across preview environments:
- Manually create an environment group in the Dashboard.
- Add one or more environment variables.
- Reference the environment group in your
render.yamlfile, as needed.
previews:
generation: automatic
services:
- type: web
plan: 1c-2g
name: express-server
runtime: node
envVars:
# The value for `MY_API_KEY` provided in the Dashboard will *not* be
# copied to preview environments.
- key: MY_API_KEY
sync: false
# Any values in this group will be copied to preview environments,
# if `all-settings` exists and is *not* included in this file.
- fromGroup: all-settings # highlight-line
Preview environment initialization
You might want to run custom initialization for your preview environment after it is created but not on subsequent deploys, for example to seed a newly created database or download files to disk. You can do this by specifying a command to run after the first successful deploy with initialDeployHook.
previews:
generation: automatic
services:
- type: web
plan: 1c-2g
name: express-server
runtime: node
initialDeployHook: ./seed_database.sh # highlight-line
Automatic expiration
You can set the number of days a preview environment can exist without any new commits to help manage costs. Set previews.expireAfterDays to automatically delete the environment after the specified number of days of inactivity. The default is no expiry. The expiration time is reset with every push to the preview environment.
previews:
generation: automatic
expireAfterDays: 3 # highlight-line
services:
- type: web
plan: 1c-2g
name: express-server
runtime: node
Root directory and build filters
If you define a root directory or specify build filters for each service in your Blueprint file, Render will only create a preview environment if the files changed in a pull request match the root directory or build filter paths for at least one service.
Preview environment billing
Preview resources are billed the same as other Render services and are prorated by the second. For details, see the pricing page.
Appendix: Glossary definitions
Render Workflows
Define collections of long-running tasks that execute across distributed compute.
Ideal for agents, ETL pipelines, and background jobs.
Render Blueprints
Render's infrastructure-as-code model.
Configure multiple related services and datastores in a single YAML file. Render automatically syncs any changes you push.
compute plan
Specifies the CPU and RAM available to your service's instances.
Common compute plans for a new web service include:
free: 0.1 CPU / 512 MB RAM0.5c-512mb: 0.5 CPU / 512 MB RAM1c-2g: 1 CPU / 2 GB RAM
Compute plans were previously known as instance types.