2026-07-30 12:14:24 +07:00
|
|
|
# ---- Builder stage: install deps + compile ----
|
|
|
|
|
FROM node:22-slim AS builder
|
|
|
|
|
|
|
|
|
|
WORKDIR /build
|
|
|
|
|
|
|
|
|
|
# Install pnpm and allow postinstall scripts for native addons
|
|
|
|
|
RUN npm install -g pnpm \
|
|
|
|
|
&& pnpm config set onlyBuiltDependencies '*' --location project
|
|
|
|
|
|
|
|
|
|
# Build-time system deps (python3 for node-gyp, g++ for native addons)
|
|
|
|
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
|
|
|
|
python3 make g++ \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Copy manifest files first for layer caching
|
|
|
|
|
COPY services/backend/package.json ./
|
|
|
|
|
COPY patches/ ./patches/
|
|
|
|
|
|
|
|
|
|
# Install all deps (devDeps included for build)
|
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm install --no-frozen-lockfile
|
|
|
|
|
|
|
|
|
|
# Copy source (shared code embedded in src/shared/)
|
|
|
|
|
COPY services/backend/ ./
|
|
|
|
|
|
|
|
|
|
# Build TypeScript
|
|
|
|
|
RUN pnpm run build
|
|
|
|
|
|
|
|
|
|
# Strip devDependencies — production runtime only
|
|
|
|
|
RUN pnpm prune --prod
|
|
|
|
|
|
|
|
|
|
# ---- Runtime stage: minimal ----
|
2026-07-02 04:07:18 +07:00
|
|
|
FROM node:22-slim
|
2026-06-01 21:44:29 +07:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2026-06-08 17:51:29 +07:00
|
|
|
# Create non-root user
|
2026-07-02 04:07:18 +07:00
|
|
|
RUN groupadd --system app && useradd --system -g app app
|
2026-06-08 17:51:29 +07:00
|
|
|
|
2026-07-30 12:14:24 +07:00
|
|
|
# Only production artifacts from builder
|
|
|
|
|
COPY --from=builder /build/dist ./dist
|
|
|
|
|
COPY --from=builder /build/node_modules ./node_modules
|
|
|
|
|
COPY --from=builder /build/package.json ./
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-06-08 17:51:29 +07:00
|
|
|
RUN chown -R app:app /app
|
|
|
|
|
USER app
|
|
|
|
|
|
|
|
|
|
EXPOSE 3000
|
|
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
|
|
|
|
CMD wget -qO- http://localhost:3000/api/health || exit 1
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-07-30 12:14:24 +07:00
|
|
|
CMD ["node", "dist/index.js"]
|