Skip to main content

Deployment

Dev-2 only

The deploy targets below include staging and production for completeness, but Mia is not deployed there yet. The only live Mia today is on pivot-dev-2. The other targets are how a Mia rollout will land when it's ready, not where it lives now.

Two artifacts ship per release: the Firebase Functions bundle (covers all modules under functions/modules/) and the Cloud Run image (functions/pivotAiAgent/).

Local dev — full MIA stack

One command:

make ai-local

What it starts:

  1. Firebase emulators (hub at :4400)
    • Auth :9099, RTDB :9000, Functions :5001, Pub/Sub :8085
  2. Temporal (Docker) — server :7233, Web UI :8233
  3. pivotAiAgent (Docker) — :3457, env .env.emulator
  4. React frontend (foreground) — :3000

Useful sub-targets:

TargetWhat it does
make emulators-upJust the Firebase emulators (background).
make temporal-upJust Temporal (docker-compose).
make ai-local-upEmulators + Temporal + pivotAiAgent Docker (no frontend).
make ai-local-frontendForeground React, points at :3457.
make ai-cloud-uppivotAiAgent Docker against real dev-2 RTDB (+ local Temporal). Risky — be sure you mean it.
make ai-deploygcloud run deploy pivot-ai-agent --source . to $PROJECT.

make ai-deploy requires a service account key at functions/pivotAiAgent/service-account.json (not committed).

Firebase function commands

From functions/:

CommandEffect
npm run buildLint + type-check + esbuild bundles per module.
npm run watchTypeScript watch mode.
npm run serveconcurrently watch + firebase serve --only functions.
npm run startfirebase use default && npm run generate-env && npm run serve.
npm run start-prodServes against production data. Don't use casually.
npm run start-allAll emulators (functions + auth + RTDB + pubsub).
npm run testJest.
npm run lint / npm run type-checkStandalone.
npm run cleanrm -rf lib/.
npm run generate-envLoads .env.<project-id> into the local shell via scripts/generate-env.ts.
npm run upload-secretsPushes local secrets to Firebase Secret Manager. Manual.
npm run migrateRTDB migrations (ts-node).
npm run migrate:pgPostgres migrations (future).

Deploy targets

Project aliases live in .firebaserc.

CommandTarget projectNotes
npm run deploy-devpivot-dev-59310Legacy, being phased out.
npm run deploy-dev-2pivot-dev-2Current dev target.
npm run deploy-stagingpivot-not-production-project
npm run deploypivot-incProduction. Be very careful.

Switch between projects:

firebase use pivot-dev-2
firebase use production

Environment configuration

FilePurpose
.env.emulatorFake credentials for the emulator stack.
.env.localDev-2 credentials + Temporal address.
.env.<project-id>Per-project config, auto-loaded by generate-env.ts at startup.

Secrets (API keys, signing keys) are not in .env files. They live in Firebase Secret Manager, declared via defineSecret() from firebase-functions/params and injected into function options:

import { defineSecret } from 'firebase-functions/params'
const ANTHROPIC_KEY = defineSecret('ANTHROPIC_KEY')

export const myFn = onRequest({ secrets: [ANTHROPIC_KEY] }, async (req, res) => {
// ANTHROPIC_KEY.value() available here
})

Build internals

functions/build.js orchestrates:

  1. Lint (npm run lint).
  2. Type-check (npm run type-check).
  3. esbuild — one bundle per module entry point:
    • functions/modules/<name>/endpoints/apis/router.tslib/<name>-api.js
    • functions/modules/<name>/endpoints/events/*.tslib/<name>-event-*.js
    • functions/modules/<name>/endpoints/scheduled/*.tslib/<name>-scheduled-*.js
    • functions/pivotAiAgent/index.ts → separate bundle for Cloud Run.

firebase deploy --only functions picks up the bundles in lib/.

Production Temporal — TBD

The dev-2 setup uses self-hosted Temporal at localhost:7233 (Docker). Production Temporal config (Cloud namespace, TLS, certs) isn't documented in the repo. See Reference: TODOs.