19 lines
899 B
Docker
19 lines
899 B
Docker
FROM node:20-alpine AS builder
|
|
WORKDIR /app
|
|
COPY backend/package*.json backend/
|
|
# Install all dependencies (including dev) in builder so tools like tsc are available for build
|
|
RUN sh -c 'if [ -f backend/package-lock.json ] || [ -f backend/npm-shrinkwrap.json ]; then npm ci --prefix backend --no-audit --no-fund --prefer-offline --no-progress; else npm install --prefix backend --no-audit --no-fund --prefer-offline --no-progress; fi'
|
|
COPY backend/ backend/
|
|
RUN sh -c 'NODE_OPTIONS="--max_old_space_size=512" npm run build --prefix backend'
|
|
## Prune dev dependencies to shrink runtime layer
|
|
RUN npm prune --omit=dev --prefix backend && rm -rf /root/.npm /tmp/*
|
|
|
|
FROM node:20-alpine
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
COPY --from=builder /app/backend/dist ./dist
|
|
COPY --from=builder /app/backend/node_modules ./node_modules
|
|
COPY backend/package*.json ./
|
|
EXPOSE 4000
|
|
CMD ["node", "./dist/index.js"]
|