Skip to content

Revival runbook

The production deployment is gone. This page is the sequenced plan for bringing TowitLinks back up on a temporary domain, and the record of what was verified while writing it.

Read this before the remediation plan. That plan assumes a running system; this one gets you to a running system. Several remediation items are prerequisites here and are called out where they are.

Where things stand

As of 2026-10-16, every production hostname is gone. Queried authoritatively against the zone's own Cloudflare nameservers (bjorn.ns.cloudflare.com, stephane.ns.cloudflare.com):

Hostname A record
towitlinks.com zone exists, no A record
www.towitlinks.com NXDOMAIN
app.towitlinks.com NXDOMAIN
staging.towitlinks.com NXDOMAIN
chat.towitlinks.com NXDOMAIN
links.towithouston.com NXDOMAIN
minios3.towithouston.com NXDOMAIN
towithouston.com 172.67.205.238
portainer.towithouston.com 172.67.205.238

app.towitlinks.com is not only a configuration value — it is hardcoded in the landing source at landing/src/routes/+page.server.ts:9 and landing/src/lib/components/landing/desktop/Header.svelte:20. Those references have to change too.

The decisions taken for the revival:

  • Temporary domain: tacocars.com. It is already on Cloudflare nameservers (justin.ns.cloudflare.com, serenity.ns.cloudflare.com).
  • Scope: backend and the agent console. The marketing landing is deferred.
  • Database: fresh. manage.py migrate against an empty Postgres. No production data is being restored.
  • Backend host: the existing Docker Swarm, managed through Portainer.
  • Console host: Cloudflare Pages, the same account that already serves the documentation.

A wildcard already covers tacocars.com

www.tacocars.com answers 301 to https://www-demo.nitza.dev/, and app., api. and voip. all resolve to the same pair of Cloudflare IPs — so a wildcard record, plus a redirect rule, currently catches every subdomain. A specific DNS record wins over a wildcard record, but a Cloudflare Redirect Rule matching *tacocars.com/* will still fire on the new hostnames and send API traffic to the demo site. Narrow that rule's hostname matcher, or add an exclusion for app. and api., before anything else. This will otherwise look like a backend outage.

What was verified locally

Rather than reasoning about whether the code still runs, it was run. Environment: Python 3.11.2, PostgreSQL 15.19, a generated throwaway service-account JSON, and placeholder values for all 45 settings that backend/settings/settings.py reads without a default.

Check Result
pip install -r requirements.txt Fails — see blocker 1
Same, with Wave removed Succeeds
manage.py check Passes — one warning, staticfiles.W004, missing backend/static
manage.py migrate --noinput Succeeds — 219 migrations, 0 pending, 60 tables
uvicorn settings.asgi:application Serves
GET /admin/login/ 200
GET /api/v1/messages 401 — JWT enforced
POST /webhooks/twilio/call/new 401 — IsTwilio rejects an unsigned request
POST /webhooks/twilio/sms/receive 401 — same
GET /google/hooks/reminders 405 — route live, and no authentication at all
pnpm install (console) Succeeds — peer-dependency warnings only
pnpm run build:app Succeeds — 29 MB in frontend/build, built in 1m30s

The headline is good news: the application code is sound and runs unmodified on current dependency versions. What is broken is the packaging and the infrastructure around it.

Note that pip, with the file unpinned, resolved Django 5.2.18 and pandas 3.0.6. The code was written against Django 4.x and passes checks and migrations on 5.2 anyway. Do not read that as permission to stay unpinned — it is luck, and remediation 3.1 still applies. Pin whatever this revival actually deploys.

Blockers to clear before deploying

1. requirements.txt cannot be installed

backend/requirements.txt:26 lists Wave. There is no such third-party package worth having — wave is in the Python standard library, and the only consumer, backend/calls/hooks/features/transcript.py:2, does import wave and gets the stdlib module. The PyPI package of that name is Python 2 era and its build fails immediately:

ModuleNotFoundError: No module named 'ConfigParser'
ERROR: Failed to build 'Wave' when getting requirements to build wheel

Delete the line.

2. The backend image cannot be built

backend/Dockerfile:2 is FROM python:3.11.4-slim-buster. Debian buster is end-of-life and its repositories are gone — https://deb.debian.org/debian/dists/buster/Release returns 404 — so RUN apt-get update on line 13 fails and the build stops there.

Line 14 installs gcc libasound-dev libportaudio2 libportaudiocpp0 portaudio19-dev. Nothing in the repository imports pyaudio, sounddevice or any other PortAudio binding, and psycopg2-binary, Pillow, pandas and numpy all ship wheels. The whole apt-get step is unnecessary.

Fix both at once:

FROM python:3.11-slim

WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1

COPY ./requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt

Removing the apt-get layers also cuts the image substantially.

3. The entrypoint demands 54 Swarm secrets

backend/entrypoint.sh makes 54 load_secret calls. Each one reads /run/secrets/TWTLNKPROD_<NAME> and, if the file is absent, calls log_error — which exit 1s under set -e. A fresh Swarm has none of them, so the container dies on first boot until all 54 exist.

For a revival on a new host, creating 54 individual Docker secrets by hand is the wrong trade. Two reasonable options:

  • Make load_secret tolerant. Change the missing-file branch from log_error to a warning, so an environment variable supplied by the stack file satisfies the same name. The function already prefers an existing environment variable; this only stops it from dying when neither source has the value and the setting has a usable default.
  • Keep secrets for secrets only. Twilio, Stripe, Firebase, the database password and SECRET_KEY stay Docker secrets; everything else moves to plain stack environment variables.

Either way, remediation 1.1 and 1.2 should land first, because they delete CELERY_BROKER, CHANNELS_RABBIT, CHANNELS_REDIS_HOST, CHANNELS_REDIS_PORT and WEBSOCKET_DOMAIN from this list outright.

4. Firestore is initialised at import time, and opens a live listener

backend/settings/firebase/__init__.py runs credentials.Certificate(...), firebase_admin.initialize_app(cred) and firestore.client() as module-level code. The module is reached transitively from the root URLconf, so every manage.py invocation initialises Firebase — check, migrate, collectstatic, shell.

Worse, backend/voip/messages/infrastructure/rep_imp_message.py:29 (_init_realtime) opens a Firestore snapshot listener at construction. With invalid credentials the local run printed ### hello / Real time sms listener and then repeated, indefinitely:

google.auth.exceptions.RefreshError: ('invalid_grant: Invalid grant: account not found', ...)

The process survives — migrate completed and reported OK — but every management command in every container opens a Firestore listener it does not need, and a credential problem shows up as an endless error loop rather than a clean failure.

Make it lazy before deploying:

  • Give settings/firebase/firebase_firestore.py:get_firestore() a module-level cache and move initialize_app into it, so Firebase is initialised on first use rather than on import.
  • Do not call _init_realtime() from __init__; start the listener from the ASGI startup path only, so one-shot management commands never open it.
  • Delete settings/firebase/firebase_init.py — its initialize_firebase() begins with a bare return and has never done anything.

Target topology

Component Where Hostname
Agent console (SvelteKit, adapter-static) Cloudflare Pages app.tacocars.com
Django API, admin, Twilio webhooks Docker Swarm, behind Cloudflare api.tacocars.com
PostgreSQL existing Swarm service on postgres-public postgres, internal only
Object storage Cloudflare R2 <account_id>.r2.cloudflarestorage.com
Documentation Cloudflare Pages, already live voip-docs.pages.dev
Component library (Storybook) Cloudflare Pages voip-storybook.pages.dev
Marketing landing deferred —

The console is adapter-static (frontend/svelte.config.js:1), so Cloudflare Pages serves it directly with no adapter change. The landing is adapter-node and would need adapter-cloudflare or a container; that is one reason it is deferred.

CORS_ALLOW_ALL_ORIGINS = True is hardcoded at backend/settings/settings.py:51, so the console on Pages can call the API on the Swarm without further configuration. That is also too permissive for a public API — narrow it to the console origin once the hostnames are fixed.

Runbook

Step 1 — Clear the Cloudflare redirect rule

Confirm app.tacocars.com and api.tacocars.com are not swallowed by the existing wildcard redirect to www-demo.nitza.dev. Everything after this step will look broken if they are.

Step 2 — Land the code fixes

One pull request, no deployment yet. Each change below is stated exactly.

2.1 backend/requirements.txt

Remove the lines that cannot install or are no longer used:

 twilio
 stripe
 pandas
-channels
-channels-rabbitmq
-channels-redis
 vobject
 Pillow
 uvicorn
-websockets
-websocket-client
-Wave
 dateutils
 whitenoise
-celery
 django-graylog[all]
 python-decouple
-daphne
 psycopg2-binary

Wave is the blocker; the rest go with the Celery and Channels removal. websockets and websocket-client are kept out because nothing imports either — confirm with a grep before deleting.

Then pin everything, from a pip freeze of the image built in 2.2. The versions pip resolves today are: Django 5.2.18, djangorestframework 3.18.3, djangorestframework-simplejwt 5.5.1, twilio 9.12.0, stripe 16.0.0, firebase-admin 7.7.0, uvicorn 0.54.0, pandas 3.0.6, psycopg2-binary 2.9.13, python-decouple 3.8, whitenoise 6.12.0.

2.2 backend/Dockerfile

Replace lines 1–16. The base image moves off end-of-life buster, and the entire apt-get step goes — nothing in the repository imports pyaudio or any other PortAudio binding, and every remaining dependency ships a wheel.

-FROM python:3.11.4-slim-buster
+FROM python:3.11-slim

 WORKDIR /usr/src/app

-ENV PYTHONDONTWRITEBYTECODE 1
-ENV PYTHONUNBUFFERED 1
+ENV PYTHONDONTWRITEBYTECODE=1 \
+    PYTHONUNBUFFERED=1

-RUN pip install --upgrade pip
-RUN apt-get update
-RUN apt-get install gcc libasound-dev libportaudio2 libportaudiocpp0 portaudio19-dev -y
 COPY ./requirements.txt .
-RUN pip install -r requirements.txt
+RUN pip install --no-cache-dir --upgrade pip \
+ && pip install --no-cache-dir -r requirements.txt

The rest of the file is unchanged. Add --proxy-headers to the CMD so uvicorn trusts the headers Traefik sets:

-CMD ["uvicorn", "settings.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--access-log", "--use-colors", "--log-level", "trace"]
+CMD ["uvicorn", "settings.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips", "*", "--access-log", "--log-level", "info"]

--log-level trace in production is a mistake worth fixing in the same line: it logs every request body, which means Twilio payloads and JWTs land in the container logs.

2.3 Make Firebase lazy

This is the subtlest change, so here is the actual chain as it stands:

settings/__init__.py:5 imports settings.firebase.firebase_init. Importing that submodule executes the package settings/firebase/__init__.py, which calls credentials.Certificate(...), initialize_app(...) and firestore.client() at module level. settings/__init__.py:8 then calls initialize_firebase(), which begins with a bare return and does nothing. So Firebase is initialised as an import side effect of calling a dead function — on every manage.py invocation, because settings is the Django project package.

Separately, voip/messages/module.py:3 constructs MngMessage() at module level, mng_messages.py:26 constructs RepImpMessage(), and its __init__ calls _init_realtime() (rep_imp_message.py:27), which opens a Firestore on_snapshot listener. module.py is imported from voip/messages/urls_wh.py:3, which is in the URLconf — so loading URLs opens a live listener.

Three edits:

--- a/backend/settings/__init__.py
+++ b/backend/settings/__init__.py
 import os

 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
-
-from settings.firebase.firebase_init import initialize_firebase
-
-print("### hello")
-initialize_firebase()

Delete backend/settings/firebase/firebase_init.py entirely — initialize_firebase() has never executed a statement.

--- a/backend/settings/firebase/firebase_firestore.py
+++ b/backend/settings/firebase/firebase_firestore.py
-from firebase_admin import firestore
+import firebase_admin
+from django.conf import settings
+from firebase_admin import credentials, firestore
 from google.cloud.firestore import Client

-from settings.firebase import FIRESTORE_DB
-
+_client: Client | None = None
+

 def get_firestore() -> Client:
-    return FIRESTORE_DB
-    return firestore.client()
+    global _client
+    if _client is None:
+        if not firebase_admin._apps:
+            cred = credentials.Certificate(settings.PUSH_NOTIFICATIONS_CREDENTIAL)
+            firebase_admin.initialize_app(cred)
+        _client = firestore.client()
+    return _client

backend/settings/firebase/__init__.py then drops to an empty module. Every current consumer already goes through get_firestore(), so no call site changes.

The listener is the remaining piece. RepImpMessage.__init__ must stop opening it:

--- a/backend/voip/messages/infrastructure/rep_imp_message.py
+++ b/backend/voip/messages/infrastructure/rep_imp_message.py
     def __init__(self) -> None:
         super().__init__()
         self._db = get_firestore()
         self._collection = self._db.collection(COLLECTION_MSG)
-        self._init_realtime()

and _init_realtime() must be called once from the ASGI startup path instead, so that migrate, collectstatic and shell never open it. Doing that properly means module.py can no longer construct MngMessage() at import time either.

This one needs a design decision, not a mechanical edit

Moving the listener to ASGI startup changes when message_manager exists, and voip/messages/urls_wh.py passes message_manager.api into .as_view() at URLconf import. The straightforward version is to make message_manager a lazily-initialised module-level singleton behind a function, and to start the listener from an ASGI lifespan handler. That is a real refactor of voip/messages/module.py and its importers, not a two-line change. If you want the revival unblocked first, the minimum viable version is to skip _init_realtime() when sys.argv indicates a management command, and do the refactor after the system is back up. Say which you prefer.

2.4 Relax backend/entrypoint.sh

     if [[ -z "${!var_name:-}" ]]; then
         if [[ -f "$secret_file" ]]; then
             value=$(cat "$secret_file")
             export "$var_name=$value"
         else
-            log_error "No se encontró el archivo de secreto: $secret_file"
+            echo "[WARN] Secret file not found, relying on the environment: $secret_file" >&2
         fi
     else

With this, a value supplied by the stack's environment: block satisfies the same name and the container no longer dies on the first missing secret. Delete these five lines outright, since the settings they feed are gone after the Celery and Channels removal:

-load_secret "WEBSOCKET_DOMAIN" "TWTLNKPROD_WEBSOCKET_DOMAIN"
-load_secret "CHANNELS_BACKEND" "TWTLNKPROD_CHANNELS_BACKEND"
-load_secret "CHANNELS_RABBIT" "TWTLNKPROD_CHANNELS_RABBIT"
-load_secret "CHANNELS_REDIS_HOST" "TWTLNKPROD_CHANNELS_REDIS_HOST"
-load_secret "CHANNELS_REDIS_PORT" "TWTLNKPROD_CHANNELS_REDIS_PORT"
-load_secret "CELERY_BROKER" "TWTLNKPROD_CELERY_BROKER"

settings.py reads 45 settings with no default. After the five deletions above, 41 remain, and entrypoint.sh covers all but two: DEBUG (settings.py:35, config("DEBUG", cast=bool) — a cast is not a default) and TWILIO_CALLER_ID. Both must come from the stack environment or the container cannot import settings.

2.5 Remove Channels from the ASGI application

--- a/backend/settings/asgi.py
+++ b/backend/settings/asgi.py
 import os

 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")

 from django.core.asgi import get_asgi_application

-# from settings.firebase.firebase_init import initialize_firebase
-
-# print("### hello")
-# initialize_firebase()
-django_asgi_app = get_asgi_application()
-
-from channels.routing import ProtocolTypeRouter
-
-from settings.ws_urls import ws_router
-
-application = ProtocolTypeRouter(
-    {
-        "http": django_asgi_app,
-        "https": django_asgi_app,
-        "websocket": ws_router,
-    }
-)
+application = get_asgi_application()

And in backend/settings/settings.py, delete "daphne" from INSTALLED_APPS (line 56) and the whole CHANNEL_LAYERS block (lines 109–138). Delete settings/ws_urls.py, voip/ws_urls.py, calls/ws_urls.py, the settings/ws_middlewares/ package and calls/hooks/streaming.py. The rest of the Channels removal is remediation 1.2, including the notify.py verification it describes.

Step 3 — Verify the third-party accounts

None of these is confirmed working. Each is a hard dependency, and finding out after the stack is up costs more than checking now.

Service What to confirm Consequence if dead
Twilio Account active, auth token valid, phone numbers still owned, TwiML app SID, SIP domains No calls and no SMS. Numbers may have to be repurchased, and a released number cannot be recovered
Stripe Secret key, webhook secret, the six price IDs in the settings Billing and usage registration fail
Firebase Project towitlinknotify still exists, a valid service-account key, Firestore enabled Real-time updates and push notifications fail, and the backend error-loops as above

The Google service-account key in the private copy is still the pre-rotation one from remediation 0.1. Rotate it as part of this step rather than deploying the leaked key to a new host.

Step 4 — Bring up the stack

The Swarm already runs Traefik on an external traefik-public network and PostgreSQL on an external postgres-public network, so the stack adds only the application. Create the database and role on the existing PostgreSQL first:

CREATE USER voip WITH PASSWORD '…';
CREATE DATABASE voip OWNER voip;

The stack, following the existing house pattern:

version: "3.8"

services:
  voip_backend:
    image: ${DOCKER_USERNAME}/towitlinks:voip-backend-${TAG}
    environment:
      # --- required, and NOT in entrypoint.sh: without these it cannot boot ---
      - DEBUG=False
      - TWILIO_CALLER_ID=+1XXXXXXXXXX
      # --- hostnames for the revival ---
      - ALLOWED_HOSTS=api.tacocars.com
      - CSRF_TRUSTED_ORIGINS=https://api.tacocars.com
      - FRONTEND_LINK=https://app.tacocars.com
      - TWILIO_WEB_HOOK_DOMAIN=https://api.tacocars.com
      # --- database on the shared postgres ---
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=voip
      - DB_USER=voip
      - TIME_ZONE=America/Chicago
      # --- object storage: Cloudflare R2, S3-compatible ---
      - S3_ENDPOINT=<account_id>.r2.cloudflarestorage.com
      - S3_BUCKET=voip
      - S3_USE_HTTPS=True
      # --- firebase: a PATH, not the key itself; see the note below ---
      - PUSH_NOTIFICATIONS_CREDENTIAL=/run/secrets/voip_firebase_sa
      # --- optional, listed so the values are visible rather than implicit ---
      - HEARTBEAT_TIMEOUT=60
      - GRAYLOG_ENDPOINT=
      # AUDIO_TRANSCRIPTION_SERVICE has no default: set it or drop transcription
      - AUDIO_TRANSCRIPTION_SERVICE=
    secrets:
      - voip_firebase_sa
      - TWTLNKPROD_SECRET_KEY
      - TWTLNKPROD_DB_PASSWORD
      - TWTLNKPROD_S3_ACCESS_KEY
      - TWTLNKPROD_S3_SECRET_KEY
      - TWTLNKPROD_TWILIO_ACCOUNT_SID
      - TWTLNKPROD_TWILIO_AUTH_TOKEN
      - TWTLNKPROD_TWILIO_API_KEY
      - TWTLNKPROD_TWILIO_API_SECRET
      - TWTLNKPROD_TWILIO_TWIML_APP_SID
      - TWTLNKPROD_TWILIO_CALL_QUEUE_NAME
      - TWTLNKPROD_TWILIO_CALL_QUEUE_SID
      - TWTLNKPROD_TWILIO_CLIENT_TOKEN_TIME
      - TWTLNKPROD_TWILIO_FCM_TOKEN
      - TWTLNKPROD_TWILIO_APN_TOKEN
      - TWTLNKPROD_STRIPE_SECRET_KEY
      - TWTLNKPROD_STRIPE_WEBHOOK_SECRET
      - TWTLNKPROD_EMAIL_HOST
      - TWTLNKPROD_EMAIL_PORT
      - TWTLNKPROD_EMAIL_HOST_USER
      - TWTLNKPROD_EMAIL_HOST_PASSWORD
      - TWTLNKPROD_DEFAULT_FROM_EMAIL
      - TWTLNKPROD_USER_RESET_PASS_TOKEN_TIME
      # plus the six PRODUCT_PRICE_ID_* and five STRIPE_EVENT_* secrets
    volumes:
      - 'voip_static:/usr/src/app/static'
    networks:
      - postgres-public
      - traefik-public
    deploy:
      replicas: 1
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.voip-api.rule=Host(`api.tacocars.com`)"
        - "traefik.http.routers.voip-api.entrypoints=websecure"
        - "traefik.http.routers.voip-api.tls=true"
        - "traefik.http.services.voip-api.loadbalancer.server.port=8000"
        - "traefik.docker.network=traefik-public"

volumes:
  voip_static:

networks:
  postgres-public:
    external: true
  traefik-public:
    external: true

secrets:
  voip_firebase_sa:
    external: true
  TWTLNKPROD_SECRET_KEY:
    external: true
  # … one entry per secret listed above

Points worth checking before deploying this:

  • PUSH_NOTIFICATIONS_CREDENTIAL is a file path, not a key. settings/firebase passes it straight to credentials.Certificate(), which wants a path or a dict and rejects a JSON string. Because the variable is already defined in environment:, load_secret leaves it alone, and the Docker secret voip_firebase_sa supplies the actual JSON at that path. Do not create a secret named TWTLNKPROD_PUSH_NOTIFICATIONS_CREDENTIAL containing the key — load_secret would read the JSON content into the variable and credentials.Certificate() would fail.
  • Object storage is Cloudflare R2, so there is no storage service in the stack. See 4.1 below — R2 needs one settings change before it works.
  • depends_on is ignored by docker stack deploy. It is in the Moodle example and does nothing there either — harmless, but do not rely on ordering. entrypoint.sh runs migrate immediately, so if PostgreSQL is not reachable the container crashes and Swarm restarts it until it is. That is the intended behaviour, not a bug to work around.
  • No Celery, no RabbitMQ, no Redis services. After step 2 there is nothing to run in them.

entrypoint.sh runs collectstatic --noinput and migrate --noinput on every start, so the fresh database is populated on first boot — exactly what the from-scratch decision wants. Then:

docker exec -it $(docker ps -qf name=voip_backend) python manage.py createsuperuser

Confirm https://api.tacocars.com/admin/login/ returns 200 before moving on.

4.1 Cloudflare R2 in place of MinIO

Storage is django-minio-storage — DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage" (backend/settings/settings.py:324) driven by the S3_* variables. It talks to the MinIO Python SDK, which speaks the S3 API, so R2 works, but not with the settings as they stand.

R2 requires the region to be auto. django-minio-storage reads MINIO_STORAGE_REGION and defaults it to None, which makes the SDK sign with us-east-1 and R2 reject the request. Add:

--- a/backend/settings/settings.py
+++ b/backend/settings/settings.py
 MINIO_STORAGE_MEDIA_BUCKET_NAME = config("S3_BUCKET")
 MINIO_STORAGE_USE_HTTPS = config("S3_USE_HTTPS", cast=bool, default=True)
 MINIO_STORAGE_MEDIA_USE_PRESIGNED = True
+MINIO_STORAGE_REGION = config("S3_REGION", default="auto")
+MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS = True

ASSUME_MEDIA_BUCKET_EXISTS defaults to False, which makes the backend call bucket_exists() on every storage instantiation. R2 supports it, but skipping it removes a permission the R2 API token would otherwise need. MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET already defaults to False, so nothing tries to create the bucket — create voip in the R2 dashboard first.

Configuration:

  • S3_ENDPOINT=<account_id>.r2.cloudflarestorage.com — host only, no scheme, no bucket. The account ID is the same one the docs site deploys under.
  • S3_ACCESS_KEY / S3_SECRET_KEY — an R2 API token with Object Read & Write on that bucket, not a Cloudflare global API key.
  • S3_USE_HTTPS=True.

Check how media URLs come out

MEDIA_URL is built as {scheme}://{S3_ENDPOINT}/{S3_BUCKET}/ (settings.py:335), and MINIO_STORAGE_MEDIA_USE_PRESIGNED = True means the backend hands out presigned URLs, which R2 supports. What it does not give you is a stable public URL: the S3 endpoint is not publicly readable. If anything serves media without going through Django — the console rendering a recording, a voicemail link in an email — attach an R2 custom domain or the pub-<hash>.r2.dev domain and override the base with MINIO_STORAGE_MEDIA_URL, which django-minio-storage reads and which this project does not currently set. Verify a recording plays in the console before calling step 4 done.

Twilio signature validation works behind Traefik

IsTwilio rebuilds the signed URL from X-Forwarded-Proto and X-Forwarded-Host and tries both schemes (settings/twilio/permissions/is_twilio.py:58-64), which Traefik sets. The only requirement is that ALLOWED_HOSTS contains api.tacocars.com, or Django rejects the request with 400 before the permission class ever runs.

Step 5 — Deploy the console to Cloudflare Pages

The console needs a SPA fallback, which it does not have today — there is no _redirects file in frontend/static/. The build prerenders one file per static route (calls.html, dashboard.html, settings.html and so on), which Pages serves correctly, but the dynamic routes are prerendered only for the single entry listed in frontend/svelte.config.js:13: the build contains contacts/0.html and messages/0.html and nothing else. /contacts/42 would therefore return 404 from Pages before the client router ever runs.

Add frontend/static/_redirects:

/*  /index.html  200

A 200 rewrite, not a redirect — the URL must stay intact for the client router to read it.

Then create a Pages project (voip-console) and a workflow mirroring .github/workflows/docs.yml, building with pnpm --dir frontend install --frozen-lockfile && pnpm --dir frontend run build:app and deploying frontend/build. The build needs these variables set in the Pages project, not committed:

VITE_API_URL=https://api.tacocars.com/api/v1
VITE_TWILIO_URL=https://api.tacocars.com/twilio/hooks
PUBLIC_FIREBASE_API_KEY=…
PUBLIC_FIREBASE_AUTH_DOMAIN=…
PUBLIC_FIREBASE_PROJECT_ID=…
PUBLIC_FIREBASE_STORAGE_BUCKET=…
PUBLIC_FIREBASE_MESSAGING_SENDER_ID=…
PUBLIC_FIREBASE_APP_ID=…
PUBLIC_FIREBASE_MEASUREMENT_ID=…

Note the two prefixes. The Firebase keys are read through $env/static/public in frontend/src/lib/actions/firebase/FirebaseApp.ts:16, so they must be PUBLIC_-prefixed; the API URLs are read through import.meta.env, so they must be VITE_-prefixed. frontend/.env.example gets this wrong and is one of the files remediation 3.2 fixes.

This replaces the old volume-rsync deployment entirely, which makes remediation 4.1 moot for the console — Pages deployments are atomic by construction.

Step 6 — Re-point Twilio

With TWILIO_WEB_HOOK_DOMAIN set and the backend reachable, every webhook URL derives from it: EndPointsURLS = Endpoints(settings.TWILIO_WEB_HOOK_DOMAIN) at backend/settings/twilio/endpoints.py:212. One run of set_webhook() (backend/calls/hooks/features/set_hook.py:36) rewrites the TwiML application and every incoming phone number.

backend/tools/set_webhooks.py hardcodes filter="8208420802", so it updates exactly one number. Call set_webhook() with no filter to cover them all, or parameterise the script.

Verify with backend/tools/show_webhooks.py before placing a test call.

Step 7 — Schedule the recurring jobs

The three endpoints under /google/hooks/ are the batch jobs. They have no authentication, and after step 4 they are reachable on the public internet. Do not leave step 7 for later — two of the three mutate billing state.

Add authentication per remediation 0.3, then create the Cloud Scheduler jobs with OIDC tokens. Because the database is fresh and the old scheduler configuration was never in version control, there is nothing to discover and nothing to preserve — this is the one place where the project dying made the work simpler. Commit the job definitions to the repository this time.

Still unanswered

  • Which Cloudflare and registrar accounts hold towitlinks.com and towithouston.com. Both zones are still on Cloudflare nameservers, so the accounts exist; recovering access matters if the product returns to its own domain.
  • Whether the Twilio, Stripe and Firebase accounts are alive — step 3.
  • Portainer URL and credentials for the Swarm.
  • Whether any Postgres backup of the old production database survived. The decision is to start fresh, but a dump is worth locating before the old host is decommissioned.