Deploy from the command line

Set up your server with Wrangler and Terraform instead of the deploy button. Useful if you want to change the code, or manage everything as code.

You'll need

1. Get the code

git clone https://github.com/EchelonOne-io/echelon-inbox.git
cd echelon-inbox
pnpm install
cd apps/worker
pnpm exec wrangler login

2. Create the Cloudflare resources

pnpm exec wrangler d1 create echelon-inbox
pnpm exec wrangler queues create echelon-triage
pnpm exec wrangler r2 bucket create echelon-inbox-updates
pnpm exec wrangler vectorize create echelon-inbox-threads --dimensions=768 --metric=cosine

Put the database_id that d1 create prints into wrangler.jsonc. To skip AI search, remove the vectorize block instead of creating the index.

3. Set the secrets and deploy

pnpm exec wrangler secret put GOOGLE_CLIENT_ID
pnpm exec wrangler secret put GOOGLE_CLIENT_SECRET
pnpm exec wrangler secret put TOKEN_ENCRYPTION_KEY    # e.g. the output of: openssl rand -base64 32
pnpm exec wrangler secret put ALLOWED_EMAIL_DOMAINS   # e.g. example.com,[email protected]
pnpm run deploy

deploy applies database migrations, then deploys. Run it again after pulling a new version. Then follow step 3 to connect the app.

All the secrets are listed, with what they do, in apps/worker/.dev.vars.example. Optional ones include a default reply-drafting model (LLM_BASE_URL, LLM_MODEL, LLM_API_KEY).

4. Optional: instant new mail with Terraform

gcloud auth application-default login
cd ../../infra/gcp
cp terraform.tfvars.example terraform.tfvars

In terraform.tfvars, set project_id and push_endpoint = "https://<your-server>/push/gmail". Your project needs billing linked. Then:

terraform init
terraform apply

Set the two outputs as secrets on your server:

cd ../../apps/worker
pnpm exec wrangler secret put GMAIL_TOPIC            # the gmail_topic output
pnpm exec wrangler secret put PUSH_SERVICE_ACCOUNT   # the push_auth_service_account output

In a Google Workspace organization, if apply fails with a domain-restriction error, add allow_gmail_push_publisher = true to terraform.tfvars and apply again.