Optimize Dockerfile with multi-stage build
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 19m42s

- Added multi-stage build to reduce final image size
- Stage 1 (builder): Installs all deps, compiles TS, generates OpenAPI, builds HTML
- Stage 2 (production): Fresh base image with only production deps and compiled artifacts
- Final image no longer contains src/, tsconfig.json, or dev dependencies
- Added TDD test (dockerfile-build.test.ts) to verify build artifacts exist
- All 561 tests pass

Reduces image size by excluding TypeScript source, build tools, and dev dependencies.
This commit is contained in:
DocFast Dev 2026-03-08 11:05:59 +01:00
parent da57f57299
commit 921562750f
2 changed files with 73 additions and 17 deletions

View file

@ -0,0 +1,23 @@
import { describe, it, expect } from "vitest";
import { existsSync } from "fs";
import { resolve } from "path";
describe("Dockerfile Build Artifacts", () => {
it("should have compiled dist/index.js from TypeScript build", () => {
// This verifies that the TypeScript compilation step in the Dockerfile worked
const distPath = resolve(process.cwd(), "dist", "index.js");
expect(
existsSync(distPath),
"dist/index.js should exist after TypeScript compilation"
).toBe(true);
});
it("should have built public/index.html from build script", () => {
// This verifies that the HTML template build step in the Dockerfile worked
const publicPath = resolve(process.cwd(), "public", "index.html");
expect(
existsSync(publicPath),
"public/index.html should exist after build-html script runs"
).toBe(true);
});
});