FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ # Use npm install (no lockfile required). Includes devDeps for tsc. RUN npm install COPY . . RUN npm run build # Prune devDependencies before copying to runner RUN npm prune --production # ── Production image ────────────────────────────────────────────────────────── FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production # Non-root user for HF container security RUN addgroup -S appgroup && adduser -S appuser -G appgroup COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json USER appuser # HF Spaces requires port 7860 EXPOSE 7860 HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ CMD wget -qO- http://localhost:7860/health || exit 1 CMD ["node", "dist/index.js"]