Skip to main content
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. Qovery’s Preview Environments solve this problem by automatically creating a clone of your production environment (including applications, databases and configuration) on every pull request, so you can test your changes with confidence without affecting your production. Use Qovery when each pull request needs the whole stack (backend, database, configuration), not only the frontend, running on a cluster in your own cloud account.
No configuration file in your repository. Qovery does not read a qovery.yml, .qovery.yml or .qovery.toml, and there is no qovery init. Projects, environments and services are created in the Console, with qovery api, or with Terraform. For the full path from a repository to a running app with commands only, see Deploy with the CLI and API.

Quick Path: Preview Environments on Your Existing Cluster

Prerequisites:
  • Your cluster is connected to Qovery. For an existing EKS, GKE or Scaleway Kapsule cluster, see BYOK (Bring Your Own Kubernetes). For other clusters, see the installation with the Qovery CLI. To let Qovery create the cluster, see Create Your Cluster.
  • The repository is deployed in a Qovery environment on that cluster and the deployment succeeds. This environment becomes the blueprint that each preview environment clones.
  • The Qovery CLI is installed and authenticated: qovery auth, or qovery auth --headless on a machine without a browser. For an AI agent, use a scoped token such as an API Policy Token (the qovery-policy-token skill creates one) instead of an admin token.
Install the Qovery Agent Skills once:
Then ask your agent:
Or run /qovery-preview, or /qovery-preview PR-123 for one pull request. The qovery-preview skill finds or creates the blueprint environment, sets the base branches and auto_preview, validates the blueprint, clones it for the pull request, configures auto-shutdown (stop, delete or recycle), shows the plan and asks for confirmation before it deploys. See Agent Skills.
Success: after the pull request is opened, qovery environment list --organization "My Org" --project "My Project" shows a new environment of type PREVIEW on the blueprint’s cluster, and its status becomes DEPLOYED. If it fails, see Diagnose a Failed Build or Deployment.
To stop a staging or blueprint environment at night, use the same deployment rule: set auto_stop to true with start_time, stop_time, timezone and weekdays, for example {"auto_stop": true, "timezone": "UTC", "start_time": "1970-01-01T08:00:00.000Z", "stop_time": "1970-01-01T19:00:00.000Z", "weekdays": ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"]}. See Deployment Rules.
The rest of this guide shows the same setup in the Console.
Flow on how Qovery Preview Environment works
Qovery 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. Preview Environments can be helpful in a lot of cases:
  • Share your changes live in code reviews: no more Git diffs for visual changes!
  • Get shareable links for upcoming features and collaborate more effectively with internal and external stakeholders.
  • Run CI tests against a high fidelity copy of your production environment before merging.
In this step-by-step guide you will learn how to get started using the Preview Environments on AWS with Qovery.
This guide also works with other cloud service providers supported by Qovery.
For any questions, existing customers can reach out via Pylon directly in the Qovery console.

Prerequisites

You have at least already deployed successfully a first application

Steps

  1. Create a “Blueprint” environment
  2. Enable Preview Environment feature
  3. Create a Preview Environment
  4. Delete a Preview Environment
  5. Seed your database
  6. Auto stop and start your Preview Environments
  7. Integrate your CI (Continuous Deployment) platform

Create your Blueprint Environment

Even if not required, we recommend creating an environment that will serve as a root to create your Preview Environments. The idea is to keep this environment as a template of a fully working environment. This environment should not be directly used. This is what we call “blueprint environment”. I assume you already have a working environment, so to create a blueprint environment you need to:
  1. Go to your working environment
  2. Click on “Actions” > “Clone”
  3. Name your environment “blueprint”
  4. Click on “Create”
We recommend using a different cluster than your production for your Preview Environments.Preview Environments are deployed on the blueprint’s cluster. To send them to another cluster, add a project deployment rule matching their name, for example [PR]*.

Enable Preview Environment

Now, you can go to turn on Preview Environments by:
  1. Click on your Blueprint environment “Settings”.
  2. Click on the Preview environments tab
  3. Turn on Preview Environment feature for all your applications by clicking on Activate preview environment for all apps.
A preview environment copies every service of the blueprint, containers built from a Git repository included. For such a container, its own auto_preview decides what the copy runs: on, the copy builds the pull request’s branch and commit; off, the copy stays unchanged on its base branch. auto_preview is false unless you set it, and the Console does not set it for these containers yet: use Terraform, or PUT /container/{containerId} as shown for auto_deploy in Auto-Deploy. The preview’s copy takes auto_deploy from the blueprint container, so it follows later pushes to the pull request only when the blueprint container has auto_deploy on. The steps in Validate your Blueprint Environment turn auto-deploy off for applications only. To turn it off on such a container, set auto_deploy = false on its qovery_container, or send the body of GET /container/{containerId} back with PUT /container/{containerId} and auto_deploy set to false, as shown in Auto-Deploy. Its previews then no longer follow later pushes to the pull request.
A preview environment builds the pull request’s code, pull requests from forks included, and runs it with the environment’s variables and secrets, so that code can read and expose them. If people you do not trust can open pull requests on the repository, keep secrets out of the blueprint environment.

Change your base branch

Now that you have turned on the Preview Environment feature, you need to change the base branch from your applications inside your Blueprint Environment. Let’s say, every new feature branch you create are coming from staging. Then you will need to change all your applications to target the staging branch. From the CLI, run this for each application of the blueprint:
Here is a flow example showing what happen when you create a new Pull Request from a feat/xxx branch that has been created from the base branch staging.
Flow on how Qovery Preview Environment Branching works
  1. A developer creates a git branch feat/xxx is created from staging.
  2. A developer creates a Pull Request for feat/xxx.
  3. Qovery creates a Preview Environment feat/xxx from the blueprint environment. The frontend, backend, PostgreSQL and Redis instances are cloned!
  4. The frontend app from the environment feat/xxx is accessible via a dedicated URL.

Validate your Blueprint Environment

Before creating a Preview Environment, validate that your Blueprint environment works.
Once done, you need to:
  1. Stop your Blueprint environment by clicking on “Actions” > “Stop”.
  2. Turn off “auto-deploy” by clicking on “Settings” > “Deployment” > “Auto-deploy off” > “Save”.
We are now ready to try out our Preview Environment configuration.

Create a Preview Environment

To create a Preview Environment, here are the steps:
  1. Checkout your staging branch.
  2. Create a branch test_qovery_preview_environment and push it.
  3. Create a Pull Request/Merge Request.
Qovery take care of cloning all your services and the configuration as well (Environment Variables and Secrets included).
You must see a new environment appearing in your environment list on Qovery. Wait until it is fully deployed, then you will be able to connect to it. This environment is fully isolated from your base environment.

Check it worked

The list shows a new environment of type PREVIEW. Its status becomes DEPLOYED once the deployment ends. To see the status of each of its services, run qovery environment statuses --project "My Project" --environment "<previewEnvironmentName>".

Delete a Preview Environment

To delete you need to merge test_qovery_preview_environment into staging. You also have the ability to delete it manually on Qovery. To delete it from the CLI, run qovery environment delete --project "My Project" --environment "<previewEnvironmentName>".
By merging into staging, Qovery will auto-redeploy the new version in your staging environment. Turn off auto-deploy from the staging environment settings if you want to manually deploy new version in staging.

Advanced

Eager to know how to go integrate Qovery Preview Environments with your CI and much more? Check out our the following guides:

Wrapping up

Congrats! You have set up your Preview Environments features. In the next guide, we will go deeper configuration to integrate the Preview Environment with your existing products and workflow.