2025-08-21 16:47:05 +08:00
|
|
|
######
|
|
|
|
|
# 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
|
|
|
|
|
COPY . .
|
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
|
|
|
# ---------- Server builder ----------
|
|
|
|
|
FROM node:20-bullseye-slim AS server-builder
|
2025-08-21 14:46:11 +08:00
|
|
|
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/*
|
|
|
|
|
|
2025-08-21 16:47:05 +08:00
|
|
|
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
|
2025-08-21 14:46:11 +08:00
|
|
|
|
2025-08-21 16:47:05 +08:00
|
|
|
# ---------- Runtime ----------
|
|
|
|
|
FROM node:20-bullseye-slim
|
|
|
|
|
ENV npm_config_registry=https://registry.npmmirror.com
|
|
|
|
|
WORKDIR /app
|
2025-08-21 14:46:11 +08:00
|
|
|
|
2025-08-21 14:55:16 +08:00
|
|
|
ENV PORT=3004
|
2025-08-21 14:46:11 +08:00
|
|
|
ENV DB_PATH=/data/purchase.db
|
|
|
|
|
|
2025-08-21 16:47:05 +08:00
|
|
|
# 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
|
|
|
|
|
|
2025-08-21 14:55:16 +08:00
|
|
|
EXPOSE 3004
|
2025-08-21 14:46:11 +08:00
|
|
|
CMD ["node", "server/dist/index.js"]
|
|
|
|
|
|
|
|
|
|
|