Charlie Roffe

Principal Architect & Engineering Director · Cloud & AI

Madrid, Spain · LinkedIn · GitHub

ADR-002: Containerization Strategy

Context

The portfolio must operate predictably across local development (Windows/macOS), staging, and Cloud Run production environments.

We need to build, test, and distribute a highly optimized web stack featuring React 19 on the client side and an Express.js backend on the server side, ensuring container image sizes are minimal to keep Artifact Registry transfer costs low and accelerate cold starts.

Decision

Implement a multi-stage Docker build that outputs a single unified container containing both the Express API and compiled Vite SPA static assets.

* Stage 1 (Builder): Uses full Node image to install dependencies, run linter/tests, and compile React/Vite assets.
* Stage 2 (Runner): Uses lightweight Node Alpine base, installs only production dependencies using BuildKit NPM cache mounts, and copies pre-compiled assets from the builder host.

Superseded: the Alpine runtime by ADR-022 (distroless image), and the single container serving both SPA and API by ADR-027 (Firebase Hosting serves the static assets at the edge and rewrites everything else to Cloud Run).

Consequences

Benefits:
* Bundles entire stack into a single lightweight deployment artifact (<200MB) for atomic releases.
* Accelerates Cloud Run cold-starts because minimal container sizes reduce image download and filesystem extraction latencies.
* Omit development dependencies from the runner container, reducing security vulnerabilities and attack surface.

Alternatives considered

1. Separate Frontend (Google Cloud Storage) and Backend API (Cloud Run): Rejected due to increased complexity in DNS routing, CORS configuration, and non-atomic deployment synchronization.
2. Monolithic VM Deployment: Rejected due to scaling latencies and high standby cost structures.

Architecture Decision Records