29 lines
903 B
Docker

# Multi-stage Dockerfile for backend-api
# Build stage: install deps and compile
FROM node:20-bullseye-slim AS builder
WORKDIR /app
# Install build dependencies
COPY package.json package-lock.json* ./
# Try npm ci (fast & reproducible). If package-lock.json is missing, fallback to npm install
RUN apt-get update && apt-get install -y --no-install-recommends python3 build-essential ca-certificates && rm -rf /var/lib/apt/lists/* \
&& (npm ci --no-audit --no-fund || npm install --no-audit --no-fund)
# Copy source and build
COPY . .
RUN npm run build
# Production stage: copy built files and production deps
FROM node:20-bullseye-slim
WORKDIR /app
# Copy node_modules from builder (includes production deps)
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=4000
EXPOSE 4000
CMD ["node", "dist/index.js"]