44 lines
1.3 KiB
Text
44 lines
1.3 KiB
Text
######
|
|
# Multi-stage dev image that builds frontend and server inside container
|
|
######
|
|
|
|
# ---------- Frontend builder ----------
|
|
FROM node:20-bullseye-slim AS frontend-builder
|
|
ENV npm_config_registry=https://registry.npmmirror.com
|
|
WORKDIR /app
|
|
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
|
|
ENV npm_config_registry=https://registry.npmmirror.com
|
|
ENV npm_config_build_from_source=true
|
|
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
|
|
|
|
# ---------- 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
|
|
|
|
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
|
|
COPY --from=frontend-builder /app/dist ./frontend
|
|
|
|
EXPOSE 3004
|
|
CMD ["node", "server/dist/index.js"]
|
|
|
|
|