48 lines
873 B
Docker
48 lines
873 B
Docker
# -----------------------
|
|
# Base image
|
|
# -----------------------
|
|
FROM node:18-alpine AS base
|
|
WORKDIR /app
|
|
|
|
# -----------------------
|
|
# Install dependencies
|
|
# -----------------------
|
|
FROM base AS deps
|
|
WORKDIR /deps
|
|
|
|
COPY package*.json ./
|
|
RUN npm ci
|
|
|
|
# -----------------------
|
|
# Build stage
|
|
# -----------------------
|
|
FROM base AS builder
|
|
WORKDIR /build
|
|
|
|
COPY . .
|
|
|
|
# copy deps only (faster + deterministic)
|
|
COPY --from=deps /deps/node_modules ./node_modules
|
|
|
|
RUN npm run build
|
|
|
|
# -----------------------
|
|
# Production runtime
|
|
# -----------------------
|
|
FROM node:18-alpine AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
# create non-root user
|
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
|
|
# only copy what is needed at runtime
|
|
COPY --from=builder /build/.output ./.output
|
|
COPY package*.json ./
|
|
|
|
USER appuser
|
|
|
|
ENV NODE_ENV=production
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", ".output/server/index.mjs"] |