---
title: "Previews"
description: "What a pull request preview contains, what it reuses from staging, and what it costs."
url: https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/previews
markdown: https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/previews.md
---

# Previews

Every non draft pull request from this repo gets a preview on The Keep, deployed by `.github/workflows/preview.yml` through the Dokploy api. One sticky comment on the PR lists everything. Closing the PR deletes it all (`preview-cleanup.yml`).

## What gets built

`turbo ls --affected` decides which apps changed against the base branch (a change in a shared package counts for every app that uses it).

| What changed | Deployed for the PR | Everything else |
| --- | --- | --- |
| nothing in the apps | nothing | the comment links to staging |
| only `web`, `dashboard` or `docs` | just those apps, pointed at the **staging api** | linked to staging |
| `api` (or a shared package it uses) | own postgres, `api`, `web` and `dashboard`, and `docs` if it changed | docs linked to staging |

Hostnames are `pr-<N>-<app>.preview-lehoetel.findmalek.engineer`, staging apps are `staging-lehoetel`, `app-staging-lehoetel`, `api-staging-lehoetel` and `docs-staging-lehoetel` on `findmalek.engineer`.

## What a PR with an api change gets

- its **own postgres** container (database `lehoetel`), removed when the PR closes
- `SEED=demo`, `MESSAGING_LIVE=false` (log only, nothing is ever sent), `DEPLOY_ENV=pr-<N>` so storage keys live under the `pr-<N>/` prefix and OpenObserve traces go to the stream `pr-<N>`
- demo logins in the comment: the hotel owner `owner.dar-zitouna@demo.le-hoetel.test` and the super admin, with a password derived per PR (fake data only)
- the database login for [WhoDB](https://whodb-lehoetel.findmalek.engineer), one shared container. The postgres host is internal, only WhoDB (same Dokploy network) can reach it
- links to OpenObserve, Umami and GlitchTip only when `OPENOBSERVE_PUBLIC_URL`, `UMAMI_URL` (with `UMAMI_API_TOKEN`) or `GLITCHTIP_URL` (with `GLITCHTIP_API_TOKEN`) are set in the repo, otherwise nothing is shown

## The tradeoff

Reusing staging is cheaper and faster (no build, no database) but not isolated.

- a frontend only PR shares the **staging database** with every other such PR. Sign ups, edits and test data from one PR show in the others
- the preview frontend talks to the staging api from another origin. The staging api needs `ALLOW_PREVIEW_ORIGINS=true`, which trusts `*.preview-lehoetel.findmalek.engineer` and `*.findmalek.engineer` for sign in. Never set it in production
- sign in redirects built by the api use the staging dashboard url, so after login you may land on staging instead of the preview. Open the preview url again, the session cookie belongs to the preview origin
- a PR that changes the api gets full isolation, so put the api change and the frontend change in the same PR when you need to test them together
- WhoDB can reach every database on the Dokploy network if you know its host and password. The preview password is derived and visible in the PR comment, which is fine for demo data and not for anything else

## Needed in the repo

Variables `DOKPLOY_URL`, `PREVIEW_DOMAIN`, `DOKPLOY_ENVIRONMENT_ID` and secret `DOKPLOY_TOKEN`. Optional secret `PREVIEW_APP_ENV` (extra env lines for every preview, for example the `S3_*` keys of a bucket) and the observability variables above. Without the required ones the job exits green with a note.

## CI cache

`ci.yml` caches `.turbo/cache` and `.next/cache` through GitHub Actions. The Docker builds accept `TURBO_API` and `TURBO_TEAM` build args plus a `turbo_token` secret for a remote cache. A self hosted cache on The Keep is the next step, see [the keep](https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/infrastructure/the-keep.md).
