Deployment.io

Previews


Previews

While working, the agent can stand up a live preview of a static site the Task changes, on your cloud, and check that it loads. The pull request lists each preview's URL so a reviewer can open it.

How the preview is built depends on the site:

  • A static site Deployment.io deploys — Deployment.io builds the preview from the agent's work the same way the deployment builds it, using its build command, root directory and publish directory.
  • Another repository — Deployment.io detects how to build it and builds it the same way. It recognises Vite, Create React App, Vue CLI, Astro, Gatsby, SvelteKit with its static adapter, and Next.js with static export. When it can't tell how, the agent builds the site itself.

A preview is removed after a period without use, when its Task is deleted, and once every pull request the Task opened has been merged or closed (GitHub repositories only). Removal usually finishes within about half an hour.

Backend previews — APIs and their preview databases — are removed sooner, about 4 hours after the Task's last preview deploy. To see a Task's live previews and when they're removed, see Resources → Previews.

Preview configuration

Previews Deployment.io builds use your organization's Preview configuration: variables and secret files set in Org Settings → Agents → QA.

A preview runs a Task's code before anyone has reviewed it, so add only values meant for previews — test-mode keys, sandbox endpoints and the public settings the build needs. Never add staging or production secrets.

Stored values are never shown again; to change one, enter a new value. The agent never sees these values.

Its variables also supply backend previews' build arguments and runtime variables — see Backend previews below.

Backend previews

A Task can also preview an API. A web service gets a backend preview when Deployment.io deploys it from a repository with a Dockerfile, in the runner's region. Private services and services deployed from an image get none; the Task's log says why.

Built like production

A backend preview is built like production, with the same root directory, Dockerfile, port, health check path, CPU and memory.

Production's values never reach a preview:

  • Build arguments take the value of the Preview configuration variable of the same name, and are left out otherwise.
  • Build secrets: a preview never gets the service's production Build secrets. When the Dockerfile reads a build secret (RUN --mount=type=secret,…), the preview is built with BuildKit and offered the service's own preview build secrets instead. For a secret the Dockerfile reads but the service has no preview value for, the Task's log says "Preview build: no preview build secret <NAME>; add it on <service>'s Previews tab." — and a mount marked required=true fails the build.
  • The running service gets only Preview configuration variables — no production variables or env files.
  • Secret files are files in the build, available only if the Dockerfile copies them.
  • The production pre-deploy command never runs.

Which service a preview is built like

A preview is built like one service. When a repository is deployed as several web services from the same root directory — for example a Staging and a Production copy of one app — the preview uses the one that deploys the Task's base branch and, among those, one in an environment classified Production. Its preview settings, such as the preview database and preview build secrets, are the ones used, and the Task's log names it: "Backend preview: <preview> built by deployment.io like <service> (<environment>)". If that still leaves more than one, the preview isn't built and the log says why.

Services in different root directories of a repository are different apps; the agent picks one by its root directory.

Its address

Each backend preview is served at its own https://<id>.cloudfront.net address, which stays the same across redeploys in a Task. The pull request lists it.

Pages a backend serves

Some services serve their own pages — a server-rendered app — rather than only answering requests. After a backend preview deploys, Deployment.io finds out which it is. It waits for the preview's health check to answer 200, for up to 10 minutes. Then it requests the preview's front page, /, asking for a web page (Accept: text/html). It follows redirects only while they stay on that preview's address, and retries twice when there is no answer or a 502, 503 or 504.

The preview serves pages when the final answer is a 2xx with Content-Type text/html. Anything else — another status, another content type, no answer, or a health check that didn't answer within 10 minutes — means it's an API.

The Step's log says which, with the reason — for example "the backend preview of <repository> serves pages (GET / answered 200 text/html)" or "the backend preview of <repository> is an API (GET / answered 404 with no content type)".

It goes by / alone. An API whose / shows an HTML landing page or Swagger UI counts as serving pages, so its smoke check loads that page. A server-rendered app whose / answers an error counts as an API, so its health check still runs. There is no setting to override it.

QA checks a backend preview that serves pages in the browser as well — see QA on a preview.

Preview settings

A web service built from a repository has a Previews tab on its service page, after Settings. It holds the settings of the service's Task previews; each section has its own Save. Static sites, private services and services deployed from an image have no Previews tab.

"When a Task changes this service, the agent builds and runs a preview of it in your cloud to test its change, and QA tests the change on it. These settings apply only to those previews; production uses the Settings tab. The agent can read everything a preview gets, so never enter production values here."

Variables shared by every service's previews stay in Preview configuration (Org Settings → Agents → QA).

On the Services list, the pencil in a web service's Preview database column (Preview settings) opens this tab.

Preview build secrets

The tab's Preview build secrets section holds the build secrets the service's Task previews are offered when their Dockerfile reads one — never production's Build secrets, which are on the Settings tab. Use read-only, preview-only tokens, for example an npm token that can install but not publish: the agent writes the code previews are built from.

Click Add preview build secret and enter a name and a value, then Save preview build secrets; it shows "Preview build secrets saved". They follow the same rules as build secrets: names start with a letter or underscore and use only letters, digits and underscores, a service can have at most 50, and each value can be up to 64 KiB. Values are write-only: a saved one shows its name and a masked value, Change replaces it and Keep current value leaves it as it is.

A Dockerfile reads one the same way as a build secret — for example RUN --mount=type=secret,id=NPM_TOKEN,env=NPM_TOKEN npm ci. See Build secrets.

Preview database

When the API's code uses PostgreSQL, MySQL or MongoDB, its preview gets its own empty database. Deployment.io detects it from the code — Prisma, Rails, Django, TypeORM, Sequelize, Knex or compose configuration, else the dependencies. The database is reachable only from the preview, and its address is put in the variables the code reads.

It is skipped when Preview configuration already sets that variable: "Preview configuration sets <VAR>, so the preview uses that".

Its data lasts only while the preview runs — it has no storage.

Migrations run only with a preview migrate command. To set one, or to choose the database yourself, use the Preview database section of the service's Previews tab:

"Each preview of this service gets its own empty database. deployment.io detects the engine and the variable from the code; set it here if that's wrong. If Preview configuration sets the variable, previews use that value instead — unless you choose Use."

Choose one:

  • "Detect from the code (recommended)"
  • "Use" — pick the engine (PostgreSQL 13–17, MySQL 8.0/8.4, MongoDB 6.0/7.0), the version and the variables. "Names like DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME or PGHOST get that part of the address; any other name gets the full address (URL)."
  • "None"

Unless you choose None, set the Preview migrate command (optional): "Runs against the preview's own database before the API starts, with the database's variables set. Leave empty to run no migrations. Previews never run the production pre-deploy command."

When the service has a production pre-deploy command and no preview migrate command is saved yet, Start from the production pre-deploy command copies it in. While the field holds exactly the production pre-deploy command, a warning shows: "This is the production pre-deploy command. Make sure it doesn't set a database address or credentials itself — it must use the preview's variables."

Click Save; it shows "Preview database saved." Changing it needs permission to edit the service.

Test users

To give a service's previews test users, use the Test users section of the service's Previews tab, after Preview database:

"Test users let QA check what a signed-in user sees on this service's previews. A role is just a name for one test user — it doesn't need to match a role in your app; an app without roles can use a single role, such as user. Deployment.io generates each role's email and password for every preview, your seed command creates the users, and QA signs in as them. QA never sees the password or the session."

The preview seed command

Preview seed command (optional) is the app's own seed command, for example npx prisma db seed. It runs on every backend preview deploy, after the preview migrate command (whether or not one is set) and before the API starts, as a one-off task from the preview's image, with the preview database's variables. It never runs in production, and not when a deploy only restarts the service. It has 30 minutes. It can be at most 1000 characters.

Under the field: "Runs on every preview deploy, after the preview migrate command, against the preview's own database. It gets QA_ROLES (the role names, separated by spaces) and, for each role, QA_ROLE_<ROLE>_EMAIL and QA_ROLE_<ROLE>_PASSWORD — <ROLE> is the name in upper case with - turned into _. Make it safe to run again: create each user if it's missing and set its password."

On top of the preview's variables, it gets:

  • QA_ROLES — the role names in their saved order, separated by single spaces.
  • For each role, QA_ROLE_<ROLE>_EMAIL and QA_ROLE_<ROLE>_PASSWORD, where <ROLE> is the role's name in upper case with every character other than a letter or a digit turned into _ (billing-admin → QA_ROLE_BILLING_ADMIN_EMAIL).

Only the seed's task gets them: never the API, the migrate command or production.

The email is qa-<role>-<the last 8 characters of the preview's id>@example.com and stays the same for a preview. The password is 24 letters and digits, generated by Deployment.io and stored nowhere; a preview keeps it for one run of the Task (its QA rounds included), and a later run gets a new one. That is why the seed must set the password every time it runs: create the user if it's missing, and set its password either way.

For example, a seed script in Node with the pg package, hashing the password as your app does:

const { Client } = require("pg");
const { randomBytes, scryptSync } = require("crypto");

(async () => {
  const db = new Client({ connectionString: process.env.DATABASE_URL });
  await db.connect();
  for (const role of process.env.QA_ROLES.split(" ").filter(Boolean)) {
    const key = role.toUpperCase().replace(/[^A-Z0-9]/g, "_");
    const email = process.env[`QA_ROLE_${key}_EMAIL`];
    const salt = randomBytes(16).toString("hex");
    const hash = salt + ":" + scryptSync(process.env[`QA_ROLE_${key}_PASSWORD`], salt, 64).toString("hex");
    await db.query(
      "INSERT INTO users (email, password_hash) VALUES ($1, $2) ON CONFLICT (email) DO UPDATE SET password_hash = EXCLUDED.password_hash",
      [email, hash]
    );
    console.log("seeded " + role);
  }
  await db.end();
})();

The seed's output goes to the Task's log. A password it prints shows as <QA_ROLE_<ROLE>_PASSWORD> (for example <QA_ROLE_OWNER_PASSWORD>) instead.

The log shows "Running the preview seed command", then "Preview seed command finished (exit code N) in <time>". A failure doesn't stop the deploy. The log says why — one of:

  • "The preview seed command failed with exit code N."
  • "The preview seed command couldn't start: …"
  • "The preview seed command couldn't run: …"
  • "The preview seed command didn't finish within 30 minutes and was stopped."

followed by "The preview has no test users; the deploy goes on."

After a deploy that succeeded, one line says what the seed did:

  • "Preview test users: seeded owner, viewer"
  • "Preview test users: ran the preview seed command (no roles)"
  • "Preview test users: the preview seed command failed, so there are no test users"
  • "Preview test users: roles are set but there's no preview seed command, so there are no test users"

There's no line when neither is set.

Roles

Roles (one test user each) has a name and a description per row ("What this user can do, e.g. manages the workspace"), Add role, and a remove button per row. A service can have up to 10 roles.

  • Names start with a lower-case letter and use only lower-case letters, digits, - and _, at most 32 characters. Two names that give the same <ROLE> can't both be saved (billing-admin and billing_admin).
  • Descriptions are at most 200 characters. QA reads them to choose a role for a criterion.

A role is a name for one test user, not one of your app's roles; an app without roles uses one, such as user.

QA_ROLES and the QA_ROLE_… names are Deployment.io's: a seed script that reads them is never listed under the pull request's "Before deploying", because production never gets them. Don't use those names for your own settings.

How QA signs in

Under How QA signs in: "Turn on each way your app signs in. Most apps need one."

  • Browser sign-in — "For checking pages: QA's browser signs in on your app's sign-in page before it checks a page that needs a signed-in user." See the browser sign-in page.
  • Sign-in request — "For checking API requests: Deployment.io sends POST <path> to the preview with the role's email and password, as JSON or a form, and QA sends its requests with the session your app answers with — its cookies, or the token in a field of its JSON body." See the sign-in request.

The two are independent: a service can have either, both or neither. Sign-in request is how QA signs in to the API's requests; Browser sign-in is how QA's browser signs in to the site's pages, or to the service's own pages when it serves them.

A switch starts on when that sign-in is saved. Turning a switch off hides its fields; saving with it off removes that sign-in.

With at least one named role and both switches off, the tab warns: "QA can't sign in as these roles yet: turn on Browser sign-in, Sign-in request, or both." It doesn't block Save.

The browser sign-in page

Turn on Browser sign-in: "For checking pages: QA's browser signs in on your app's sign-in page before it checks a page that needs a signed-in user." It then shows Browser sign-in page, for example /signin: "A page with an email and password form — on the site that calls this service, or on this service itself when it serves its own pages."

It is a path on the site that calls this service — the page of your frontend where a person signs in, for example a React app's /signin, which sends the sign-in to this API. For a service that serves its own pages, it is a path on the service itself, for example /login.

With the switch on, the page is required: "Enter the browser sign-in page, or turn Browser sign-in off." The tab also checks it: "The browser sign-in page must start with /, be at most 200 characters, and have no spaces, ? or #."

When QA checks a criterion about a page that needs a signed-in user, Deployment.io signs in before the check. It opens the path on the site preview, https://<site preview><path>, or on the backend preview itself when it serves pages, https://<backend preview><path>, and waits up to 10 seconds for the form:

  • The password field is the first visible password input.
  • The email field is the first visible email input, else the first text input whose autocomplete has username or email, or whose name or id has email, user or login.
  • It fills the email and the password and submits by pressing Enter in the password field, or by clicking the form's submit button when Enter didn't submit it. A form that asks for the email first and then shows the password field works too.
  • It is signed in when no password field is left on the page within 10 seconds.

It doesn't work for a form inside an iframe, a form behind a "Sign in" button that must be clicked first, a CAPTCHA, a one-time code, or a sign-in only through another site (OAuth, such as "Continue with Google"). QA then reports the criterion as not checked.

QA names only the role. Deployment.io fills the email and the password; the password is replaced by <redacted> in anything QA reads, the same as for the sign-in request.

Its limits:

  • A service whose preview serves pages offers its roles on its own preview only. Any other service's roles are offered only on the site previews connected to it.
  • An app that signs out on every page load can only be checked from the page it shows after signing in and the pages reached from it by clicking.

The sign-in request

Turn on Sign-in request: "For checking API requests: Deployment.io sends POST <path> to the preview with the role's email and password, as JSON or a form, and QA sends its requests with the session your app answers with — its cookies, or the token in a field of its JSON body." It then shows:

  • Sign-in path — for example /api/login.
  • Body — JSON or Form.
  • Email field and Password field — email and password by default.
  • Session — Cookie, or Token in the JSON body with a Token field, for example token or data.access_token.

With JSON, a . in a field name nests objects (user.email → {"user": {"email": …}}); with a form the names are used as they are (user[email]).

The tab checks them:

  • "Enter the sign-in path, or turn Sign-in request off."
  • "The sign-in path must start with /, be at most 200 characters, and have no spaces, ? or #."
  • "Field names start with a letter or _ and use only letters, digits, _, -, . and [ ], at most 64 characters."
  • "The email and password fields must be different."
  • "With a JSON body, one field can't be inside the other."
  • "A bearer session needs the JSON field that holds the token, e.g. token or data.access_token."

When QA needs a signed-in request, Deployment.io sends POST https://<preview><path> with the role's email and password and keeps what the app answers: with Cookie, the cookies it sets; with a token, that field of the JSON body, sent back as Authorization: Bearer <token>. It signs in successfully when the answer's status is 200–399 and carries the session. QA retries a sign-in that didn't succeed once at most.

QA never sees the password, the cookies or the token: in what QA reads, each is replaced by <redacted>.

It works for an app that signs in with one POST of an email and a password. A sign-in that needs more — a CSRF token, another field, several steps, a redirect to another site (OAuth), an emailed link — can't be used yet.

Click Save to save the whole section; it shows "Test users saved." Changing it needs permission to edit the service. The settings hold no secret, and anyone who can open the service can read them.

Connecting a site to its API

When a Task has both a static site and an API, QA builds the site's preview to call the API's preview:

  • A production setting of the site that holds the API's address is pointed at the API preview.
  • A production setting of the API that lists the site's origin (CORS) gets the site preview's origin.

The pull request says what QA connected:

  • "QA built <site>'s preview to call <api>'s preview (<variables>) and allowed its origin on <api>'s preview (<variables>)."
  • When no setting lists the site: "…No production setting of <api> lists <site>'s address, so <api>'s preview allows the origins Preview configuration gives it."

When they aren't connected, it says "QA didn't connect <site>'s preview to <api>'s preview: " followed by one of:

  • "<api>'s preview failed to deploy."
  • "<site>'s preview failed to deploy."
  • "deployment.io couldn't look up their production settings."
  • "<api>'s production setting <VAR> holds a single origin, used by <other site>'s preview."
  • "no production setting of <site> holds <api>'s address."

QA on a preview

After the Review stage, Deployment.io checks the change in a running site. For each repository with a static site Deployment.io can build — one it deploys, or one it can detect how to build, the same rules as the previews above — it builds a preview, and a QA agent checks that preview in a real browser, at desktop, tablet and phone sizes as a criterion needs.

A backend preview that serves pages is checked like a site preview as well as an API. A criterion about its pages — what a page shows, a form, a link, a flow through its pages — is checked in QA's browser at the backend preview's own address. A criterion about how it answers a request is still sent as a request.

QA is advisory: it never holds the pull request. What it finds is reported on the pull request, and you decide what to do about it.

QA first calls each API preview's health check, and calls it again while the preview isn't reachable yet: a new API preview takes a few minutes to answer while its service starts and its CloudFront address starts serving. QA doesn't count that wait against the change. A backend that fails to deploy is reported, never a failed criterion.

QA then checks a criterion about how the API answers a request — any method (GET, HEAD, POST, PUT, PATCH, DELETE or OPTIONS), with request headers or a body — and about the response's status code, headers or body by sending that request to https://<preview><path> itself, not through its browser. A JSON body is sent with the header Content-Type: application/json. QA reads the status, the headers and the first 8 KiB of the body. JSON is compared by meaning (the same keys and values), not by spacing or key order. A criterion that expects an error status passes when the API answers with it: "POST /version answers 404" passes on a 404. Redirects aren't followed: a criterion about a redirect is judged from its status and its Location header ("GET /old answers 301 with Location /new"). QA sends at most 60 requests in a QA round. Criteria about a site preview's pages are still checked in the browser.

Requests can change the preview's data, which lives in the preview's own throwaway database. QA may create, through the API, data a criterion itself describes, in the order the criterion gives: "POST /items with {"name":"a"}, then GET /items lists it".

When the service has roles and a sign-in request, and the preview seed command succeeded on that preview, QA checks a criterion that needs a signed-in request as a role — the one the criterion names, else the one whose description fits. Deployment.io signs in as that role (see The sign-in request) and QA sends the criterion's requests with its session: "Signed in as owner, GET /me answers 200 with the role owner".

When a site preview is connected to an API preview whose service has roles and a browser sign-in page, and the preview seed command succeeded on that API preview, QA checks a criterion about a page that needs a signed-in user as one of that service's roles — the one the criterion names, else the one whose description fits: "Signed in as owner, the Billing page shows the current plan". Deployment.io signs in on the site preview's sign-in page (see The browser sign-in page) before the check. The check starts on the page the app shows after signing in, and QA reaches the page the criterion is about by clicking, as a person would: loading a page directly can sign the browser out of an app that keeps its session in memory. Each signed-in check signs in again, in a fresh browser. A signed-in check has 60 seconds by default, the sign-in included.

A backend preview that serves pages is signed in to on its own pages. When its service has roles and a browser sign-in page, and the preview seed command succeeded on that preview, Deployment.io signs in on the backend preview's own sign-in page, https://<backend preview><path>, and QA checks its signed-in pages the same way.

Neither needs a sign-in request. A backend preview that serves pages offers its roles only on its own address, not on the site previews connected to it. Any other API preview offers its roles only on the site previews connected to it; when two of those have a role with the same name, QA says which API's role it means.

What it checks

QA checks each of the Task's acceptance criteria and reports it as passed, failed, or not checked with a reason. The criteria come from the Acceptance criteria box when you create or edit a Task, or from the session's spec for a Task converted from an Assistant session — see Creating and Running a Task. QA checks only these; it never picks criteria out of the description.

A Task with no acceptance criteria gets a smoke check instead: each site preview, and each backend preview that serves pages, loads with no page errors and no failed requests to itself; each other backend preview answers its health check.

A criterion comes back not checked when QA can't check it by looking at the site — for example, an email or a webhook. When QA runs again on production after a merge, a criterion that can only be checked by changing data is not checked either; see Deploy After Merge. QA on production never signs in: a criterion that needs a signed-in page or request is not checked there.

These criteria about a site preview's pages, or a backend preview's own pages, come back not checked, each with the reason QA gives:

  • One that needs a signed-in page when no API preview the site is connected to offers a role to sign in as in the browser — its service has no roles or no browser sign-in page, its preview seed command failed, or the site isn't connected to it — or, on a backend preview that serves pages, when its service has no roles or no browser sign-in page, or its preview seed command didn't succeed on that preview (it failed, or none is set): "needs a login".
  • One where signing in as the role didn't work, after one retry: "couldn't sign in as <role>". A sign-in that fails is never counted against the change.
  • One where the browser refused the API's session cookie: "the browser refused the session cookie across preview hosts". A site preview and an API preview are on different *.cloudfront.net addresses, which the browser treats as different sites: it keeps and sends a session cookie the API sets for the site's pages only when the cookie is SameSite=None; Secure. An app that keeps the token from the sign-in answer itself, rather than in a cookie, isn't affected. This concerns a site preview signed in through an API preview, not a backend preview's own pages: a session cookie a backend that serves pages sets is for its own address.

Requests that fail while signing in, and cookies the browser refuses, are never reported as problems with the change.

These API criteria come back not checked, each with the reason QA gives:

  • One that needs a signed-in session when the service has no test users or no sign-in request, needs a role it has no test user for, or needs an API key or token that doesn't come from signing in: "needs a login".
  • One where signing in as the role didn't work: "couldn't sign in as <role>". A sign-in that fails is never counted against the change.
  • One about particular records (a user, an order) that the criterion doesn't create and the response doesn't show: "needs data the preview database doesn't have". The preview database starts with only what the preview migrate command and the preview seed command create, so a missing record isn't a failure. A criterion about the response's status or shape — an empty list, a 404 for an unknown id — is still checked.
  • One that needs more of the response body than the first 8 KiB: "needs more of the response than QA reads".
  • One about a header CloudFront sets: "is about a header CloudFront sets". Every API preview is served through CloudFront, so Via, X-Cache, X-Amz-Cf-Pop, X-Amz-Cf-Id and Age are CloudFront's, and Transfer-Encoding, Content-Length and Connection describe CloudFront's framing, not the API's.
  • With more than one API preview in the Task, one that doesn't make clear which API it means: "doesn't say which backend it means".

What it builds

The preview QA checks is built from the change merged with the latest commit of the base branch, in a throwaway copy. Nothing is pushed, and the pull request gets no merge commit. That way QA checks what you'd get after merging, not a branch that may be behind.

If the change and the base branch don't merge cleanly, QA checks the branch as built and the pull request says why.

When a criterion fails

If a criterion fails, the agent gets one round to fix it. The fix is reviewed, and QA checks once more. Anything still failing is listed on the pull request.

In the pull request

The pull request's description has a line that sums up the result, one of:

  • "QA on a preview: <n> of <m> acceptance criteria passed", followed by " · <f> failed", " · <k> not checked" and " · <j> fixed before this PR" when they apply
  • "no acceptance criteria — checked the preview loads", followed by " · <p> problems found" (" · 1 problem found" for one) when QA found problems
  • "skipped — no static site or backend service in this change"
  • "couldn't run — <reason>"

Below it, a QA on a preview section lists the failed criteria and the problems found, with collapsed lists for Not checked, Fixed by QA and Observations. A line per repository says what QA checked:

  • "QA checked <repository> merged with <base branch> at <short commit>."
  • "QA checked <repository>'s branch as built: <reason>."

Choosing the QA model

QA uses the Task's QA model, which you can pick when you create, start or re-run the Task. By default it's the same as the reviewer's model.