Files
mars3142 fe8f87602b
CI / test (push) Successful in 58s
CI / build-and-push (push) Successful in 18s
CI / deploy (push) Successful in 5s
Add HEALTHCHECK to Dockerfile
Matches findr-web's pattern: the image declares its own healthcheck
against /healthz, so Compose doesn't need to restate it.

Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
2026-09-04 15:39:46 +02:00

48 lines
2.1 KiB
Docker

# syntax=docker/dockerfile:1
# Two things this file works around:
# - NODE_ENV=production makes `npm ci` skip devDependencies, and the build
# needs tsup + typescript from there. So NODE_ENV is set in the runtime
# stage only, not globally.
# - The npm 10.9 that ships with node:22 aborts `npm ci` with EBADPLATFORM on
# esbuild's cross-platform optional packages (pulled in transitively via
# tsup). npm 11 handles them correctly.
FROM node:22-slim AS base
WORKDIR /app
RUN npm install -g npm@11
# ── install all deps (incl. dev) for the build ──────────────────────────────
FROM base AS deps
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci
# ── compile TS → dist/ ─────────────────────────────────────────────────────
FROM deps AS build
COPY . .
RUN npm run build
# ── prod-only deps ─────────────────────────────────────────────────────────
FROM base AS prod-deps
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev
# ── runtime ────────────────────────────────────────────────────────────────
FROM node:22-slim AS runtime
ENV NODE_ENV=production
WORKDIR /app
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/drizzle ./drizzle
COPY package.json ./
USER node
EXPOSE 3000
# node:*-slim ships no curl with a working TLS stack, so Node does the probing.
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD node -e "fetch('http://127.0.0.1:3000/healthz').then((r) => process.exit(r.status < 500 ? 0 : 1)).catch(() => process.exit(1))"
# Container runs migrations (DDL role) then serves — see src/index.ts.
CMD ["node", "dist/index.js"]