Files
danak 2e91361d47 Update Dockerfile
comment docker
2026-06-10 10:40:15 +00:00

51 lines
1.4 KiB
Docker

# Stage 1: Base
FROM node:22-alpine AS base
# Change Alpine repo
# RUN sed -i 's|https://dl-cdn.alpinelinux.org/alpine|https://mirror.de.velop.ir/alpine|g' /etc/apk/repositories
# Configure npm registry mirror (Liara)
# ENV NPM_CONFIG_REGISTRY=https://package-mirror.liara.ir/repository/npm/
# RUN npm config set registry https://package-mirror.liara.ir/repository/npm/
# Timezone (Node 22 respects TZ without needing tzdata installed)
ENV TZ=Asia/Tehran
WORKDIR /app
# Stage 2: Dependencies (single install — reused for build and production)
FROM base AS deps
WORKDIR /temp-deps
COPY package*.json ./
ENV NODE_OPTIONS=--max-old-space-size=4096
RUN npm ci --ignore-scripts
# Stage 3: Production node_modules (prune dev deps instead of a second npm ci)
FROM deps AS prod-deps
WORKDIR /temp-prod-deps
COPY package*.json ./
COPY --from=deps /temp-deps/node_modules ./node_modules
RUN npm prune --omit=dev --ignore-scripts
# Stage 4: Build
FROM base AS builder
WORKDIR /build
COPY package*.json ./
COPY --from=deps /temp-deps/node_modules ./node_modules
COPY . ./
RUN npm run build
# Stage 5: Runner
FROM base AS runner
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=builder --chown=appuser:appgroup /build/ ./
COPY --from=prod-deps --chown=appuser:appgroup /temp-prod-deps/node_modules ./node_modules
USER appuser
ENV NODE_ENV=production
EXPOSE 4000
CMD ["node", "--max-old-space-size=2048", "dist/src/main"]