FROM node:20-alpine AS builder WORKDIR /app COPY backend/package*.json backend/ # Use npm ci if a lockfile exists in backend, otherwise fall back to npm install RUN sh -c 'if [ -f backend/package-lock.json ] || [ -f backend/npm-shrinkwrap.json ]; then npm ci --prefix backend --production; else npm install --prefix backend --production; fi' COPY backend/ 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"]