Dream-MachineProcurementList/docker/Dockerfile.prod

56 lines
1.6 KiB
Text
Raw Normal View History

######
# Multi-stage production image that builds EVERYTHING inside containers
######
# ---------- Frontend builder ----------
FROM node:20-bullseye-slim AS frontend-builder
ENV npm_config_registry=https://registry.npmmirror.com
WORKDIR /app
# Install frontend deps and build (root project)
COPY package.json ./
COPY pnpm-lock.yaml ./
RUN npm install --no-audit --no-fund --legacy-peer-deps
COPY . .
RUN npm run build
# ---------- Server builder ----------
FROM node:20-bullseye-slim AS server-builder
ENV npm_config_registry=https://registry.npmmirror.com
ENV npm_config_build_from_source=true
# Build prerequisites for native modules (better-sqlite3)
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app/server
COPY server/package.json ./package.json
RUN npm install --no-audit --no-fund --build-from-source
COPY server/tsconfig.json ./tsconfig.json
COPY server/src ./src
RUN npm run build
# Prune dev deps after build; keep native modules compiled for runtime
RUN npm prune --omit=dev
# ---------- Runtime ----------
FROM node:20-bullseye-slim
ENV npm_config_registry=https://registry.npmmirror.com
WORKDIR /app
ENV PORT=3004
ENV DB_PATH=/data/purchase.db
# Server runtime
COPY --from=server-builder /app/server/dist ./server/dist
COPY --from=server-builder /app/server/node_modules ./server/node_modules
COPY server/package.json ./server/package.json
# Prebuilt frontend (from frontend-builder)
COPY --from=frontend-builder /app/dist ./frontend
EXPOSE 3004
CMD ["node", "server/dist/index.js"]