Skip to content

feat: add Cloud Run support with scale-to-zero#9

Merged
enspyr-admin merged 1 commit intomainfrom
feat/cloud-run-migration
Mar 17, 2026
Merged

feat: add Cloud Run support with scale-to-zero#9
enspyr-admin merged 1 commit intomainfrom
feat/cloud-run-migration

Conversation

@maxwell-merge-slam
Copy link
Copy Markdown
Contributor

Summary

  • Add HTTP health server (server.ts) for Cloud Run container lifecycle
  • Add SIGTERM handler for graceful shutdown
  • Multi-stage Dockerfile builds TypeScript in-container (node:20 for livekit-rtc native binary)
  • BOT_NAME env var for configuring bot persona on Cloud Run

Test plan

  • PORT=8080 node dist/index.js start starts health server and LiveKit worker
  • curl localhost:8080 returns 200
  • Cloud Run deploy with BOT_NAME=clawd resolves correct config
  • SIGTERM triggers graceful shutdown log message

Stack: 2/3 — depends on #8

Generated with Claude Code

Copy link
Copy Markdown

@kelvin-bit-brawler kelvin-bit-brawler bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — PR #9

Summary: Adds Cloud Run infrastructure: HTTP health server, SIGTERM handler, multi-stage Dockerfile, and BOT_NAME env var support.

Changes reviewed:

  • src/server.ts — new minimal HTTP health-check server
  • src/index.ts — wires up health server and SIGTERM handler
  • Dockerfile — multi-stage build with separate build and runtime stages

Quality Assessment:

Aspect Status Notes
Code Quality pass Clean, well-documented, minimal footprint
Tests warning No tests in the project (pre-existing); health server is simple enough
Security pass No secrets exposed; health endpoint returns static "ok"
Performance pass Lightweight HTTP server, no overhead concern

Issues found:

  1. Dockerfile runtime image size (minor): The runtime stage uses node:20 (~1 GB) while the build stage uses node:20-slim (~200 MB). The PR description says this is intentional for livekit-rtc native binaries, which is a valid reason. However, worth confirming that node:20-slim truly fails at runtime — if it works, switching would cut ~800 MB from the deployed image.

  2. SIGTERM handler doesn't close the health server or LiveKit connection: The handler logs and calls process.exit(0), which is fine for Cloud Run's 10-second grace period since Node will forcibly close sockets on exit. But if you ever need a longer drain period (e.g., finishing a chat response in flight), you'd want server.close() and to signal the LiveKit worker to disconnect. Not blocking, just flagging for future consideration.

  3. Health server server variable is unused outside startHealthServer: If you later need to close the server (see above), you'd need to return or export it. The current fire-and-forget pattern is fine for now.

Suggestions:

  • Consider adding a /.well-known/ready or /healthz route distinction so you can differentiate Cloud Run startup probes from liveness checks in the future. Not needed now, but a common pattern.
  • The comment "no-op locally if PORT unset" in index.ts is slightly misleading — the server will start on port 8080 by default even locally (since PORT || "8080" always resolves). If the intent is truly no-op when running locally, you could gate on process.env.PORT being defined. Low priority since it's harmless.

Verdict: APPROVE

Clean, well-scoped PR. The health server is minimal, the SIGTERM handler covers the Cloud Run lifecycle, and the multi-stage Dockerfile is a good pattern. The minor items above are non-blocking suggestions for future iteration.

@nickmeinhold nickmeinhold force-pushed the feat/cloud-run-migration branch 3 times, most recently from c39b6ba to 2f9849e Compare March 17, 2026 13:10
@nickmeinhold nickmeinhold changed the base branch from refactor/dual-bot-support to main March 17, 2026 13:15
Add minimal HTTP health server (server.ts) for Cloud Run container
lifecycle — responds 200 to all requests for health checks and
wake-up pings. Add SIGTERM handler for graceful shutdown. Multi-stage
Dockerfile builds TypeScript in-container using node:20 (required for
livekit-rtc native binary). BOT_NAME env var configures bot persona
when CLI arg not present.

Co-Authored-By: Claude <noreply@anthropic.com>
@nickmeinhold nickmeinhold force-pushed the feat/cloud-run-migration branch from 2f9849e to 29ed8d1 Compare March 17, 2026 13:15
@enspyr-admin enspyr-admin merged commit 76bce08 into main Mar 17, 2026
1 check passed
@nickmeinhold nickmeinhold deleted the feat/cloud-run-migration branch March 17, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants