FROM node:20-alpine AS builder WORKDIR /app COPY backend/package*.json ./ # Use npm ci if a lockfile exists, otherwise fall back to npm install RUN sh -c 'if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci --production; else npm install --production; fi' COPY backend/ ./ RUN npm run build --prefix backend FROM node:20-alpine WORKDIR /app COPY --from=builder /app/backend/dist ./dist COPY backend/package*.json ./ RUN npm ci --production --prefix /app EXPOSE 4000 CMD ["node", "./dist/index.js"]