---
name: rtie-deploy
description: Deploy RTIE Workers and Astro sites to Cloudflare — wrangler deploy, environment secrets, HyperDrive, and multi-target CI.
version: "0.1.0"
---

# RTIE Deploy

RTIE is **Cloudflare-native**. All API workers deploy to Cloudflare Workers via `wrangler`. Marketing sites deploy to Cloudflare Pages via `wrangler pages deploy`.

**Never deploy to Railway, Vercel, or AWS.** These are not in the stack.

## Prerequisites

```bash
# Authenticate wrangler (one-time per developer)
bunx wrangler login

# Verify you're in the right account
bunx wrangler whoami
```

## Deploy the API worker

```bash
# Always source env vars first — Conductor worktrees don't inherit the shell
source ~/.zshrc && bunx wrangler deploy

# Deploy to staging environment
source ~/.zshrc && bunx wrangler deploy --env staging
```

The worker entry point is `apps/api/src/worker.ts`. `wrangler.toml` specifies the account, zone, and bindings.

## Deploy the MCP worker

```bash
cd apps/mcp
source ~/.zshrc && bunx wrangler deploy
```

## Deploy Astro sites (CF Pages)

```bash
# Build first
cd apps/site && bun run build

# Deploy to CF Pages
source ~/.zshrc && bunx wrangler pages deploy dist --project-name rtie-site
```

**Astro apps** (marketing, docs): `apps/site/`, `apps/docs/`, `verticals/vauc/site/`, `verticals/varc/site/`
**React apps** (console, buyer apps): `apps/console/`, `verticals/vauc/app/`

## Environment secrets

Secrets are stored in Cloudflare (not in `.env` or `wrangler.toml`). Set them once per environment:

```bash
source ~/.zshrc && bunx wrangler secret put SUPABASE_JWT_SECRET
source ~/.zshrc && bunx wrangler secret put STRIPE_SECRET_KEY
source ~/.zshrc && bunx wrangler secret put RESEND_API_KEY
```

List all secrets:
```bash
source ~/.zshrc && bunx wrangler secret list
```

Local dev values go in `.dev.vars` (gitignored):
```ini
# apps/api/.dev.vars
SUPABASE_JWT_SECRET=your_dev_jwt_secret
DATABASE_URL=postgresql://...
```

## HyperDrive binding

HyperDrive pools Supabase Postgres connections at the CF edge. It is already configured in `wrangler.toml`:

```toml
[[hyperdrive]]
binding = "HYPERDRIVE"
id = "<hyperdrive-id from wrangler hyperdrive list>"
```

In code: `env.HYPERDRIVE.connectionString` replaces `DATABASE_URL`.

If you need to create a new HyperDrive config (e.g. for a staging environment):
```bash
source ~/.zshrc && bunx wrangler hyperdrive create rtie-hyperdrive-staging \
  --connection-string="postgres://postgres.[staging-ref]:[password]@aws-0-us-east-1.pooler.supabase.com:6543/postgres"
```

Use the Supabase **pooler** URL (port 6543), not the direct connection (port 5432).

## Running migrations before deploy

Always apply Drizzle migrations before deploying schema-breaking changes:

```bash
source ~/.zshrc && bun db:migrate
# Then deploy
source ~/.zshrc && bunx wrangler deploy
```

## Local development

```bash
# API Worker with local Supabase Postgres via .dev.vars
cd apps/api && source ~/.zshrc && bunx wrangler dev

# Docs site
cd apps/docs && bun dev

# Console (React + Vite)
cd apps/console && bun dev

# MCP Worker (test tools locally)
cd apps/mcp && bunx wrangler dev
```

## Turborepo builds

Build only affected packages (CI uses this for fast builds):

```bash
# Build everything
bun run build

# Build only affected by changes since main
bunx turbo build --filter="...[main]"
```

## wrangler.toml structure

```toml
name = "rtie-api"
main = "src/worker.ts"
compatibility_date = "2025-01-01"

[[hyperdrive]]
binding = "HYPERDRIVE"
id = "abc123"

[[kv_namespaces]]
binding = "TENANT_CACHE"
id = "def456"

[env.staging]
name = "rtie-api-staging"
[[env.staging.hyperdrive]]
binding = "HYPERDRIVE"
id = "ghi789"
```

## GitHub Actions CI (Task 19)

Once CI is set up, deploys happen automatically on merge to main:

```yaml
- uses: cloudflare/wrangler-action@v3
  with:
    apiToken: ${{ secrets.CF_API_TOKEN }}
    command: deploy
```

Full docs: https://docs.rtie.ai/deploy
