Terraform
Start from the Terraform stack of hosted ctxpipe, on Railway and Neon.
The repository has a Terraform stack in infra/. It is the deployment of
hosted ctxpipe. It uses Railway for the services, Neon for Postgres, and Vercel
Sandbox for chat. It is not a reusable module yet. Fork it and change it
for your own deployment.
Change the hosted values before you apply
The stack names the accounts and settings of hosted ctxpipe. These are:
the Railway workspace and project, the Neon organization and region, the
GitHub App, the email sender, the custom domains, the Vercel team and project,
and the telemetry endpoint. Replace each of them with your own values in infra/ and
infra/module/ctxpipe/ before you run terraform apply.
What the stack manages
| Area | Terraform shape |
|---|---|
| App platform | The Railway project, the production environment, the services, their variables, and the codesearch and FalkorDB volumes |
| Database | A Neon PostgreSQL 17 project, its branch, endpoint, database, and owner role, and the ctxpipe_app password |
| App images | ghcr.io/ctxpipe-ai/backend, worker, ui, and codesearch, tagged with the commit SHA |
| Graph database | A FalkorDB service on Railway, pinned to one version |
| Secrets | Not in Terraform. Your CI writes them to the Railway service variables. |
Initialize the state
infra/backend.tf uses an S3-compatible state backend. Give the backend
settings when you initialize. Keep the credentials out of the repository.
infra/README.md shows an example for Cloudflare R2:
terraform -chdir=infra init \
-backend-config="bucket=<bucket>" \
-backend-config="key=ctxpipe/production/terraform.tfstate" \
-backend-config="endpoints={s3=https://<account-id>.r2.cloudflarestorage.com}" \
-backend-config="access_key=<access-key-id>" \
-backend-config="secret_key=<secret-access-key>"Plan and apply
The stack has no secret input, so its state holds no app secret.
terraform -chdir=infra plan
terraform -chdir=infra applyApply only when the plan matches the environment that you expect.
Secrets
Keep each app secret in the secret store of your CI. Before the images start,
the deploy writes the secrets to the Railway service variables with
scripts/railway-sync-variables.mjs. That script lists each secret and the
services that get it. A connector such as Slack, Linear, or PagerDuty is on when
you set its secrets. Each provider also needs its own app, callback, and
webhook. See the source connector pages.
Roll out a new version
Terraform sets the first image of each service. After that, it ignores image and region changes, because of limits in the Railway provider. Roll out a new version with the scripts:
scripts/railway-set-images.sh, withIMAGE_TAG=<commit-sha>, deploys that tag to the backend, worker, UI, and codesearch services;scripts/railway-set-regions.shchanges the region. Railway copies the codesearch and FalkorDB volumes, and those services stop during the copy.
Change the project settings of Railway, such as its name, in the Railway UI.
Terraform ignores them. The production environment must be the oldest
environment of the project, or the plan stops.
Database roles
Terraform generates the ctxpipe_app password, and migrate creates the role
in SQL with it. Do not use a role that the Neon API creates for the app. It is a
member of neon_superuser, which bypasses row-level security. migrate
therefore refuses it.
The backend, worker, and codesearch use the pooler URL of ctxpipe_app as
DATABASE_URL. migrate uses the owner URL. Keep these two identities
separate.
Chat sandboxes and observability
- Workspace chat runs in Vercel Sandbox (
SANDBOX_PROVIDER=vercel). The deploy writesVERCEL_TOKENfrom your CI secrets. Set your own Vercel team and project. See Chat sandboxes. - The module sets
OTEL_EXPORTER_OTLP_*fromotel_otlp_endpoint, which points to the collector of hosted ctxpipe by default. Set your own endpoint and headers, or removeotel_shared_envfrom the module to turn export off. See Observability.