Files
dsc-api/Dockerfile
T
morteza 8f3fe97577
Build and Deploy Docker Images / build_and_deploy (push) Has been cancelled
comment mirrors
2026-06-25 16:24:29 +03:30

58 lines
1.7 KiB
Docker
Executable File

# Stage 1: Base — shared tooling and system config
FROM node:22-alpine AS base
ENV TZ=Asia/Tehran
# Runflare build hosts cannot reach registry.npmjs.org; use their npm mirror.
# RUN npm install -g pnpm@9.15.9 --registry=https://mirror-npm.runflare.com
RUN npm install -g pnpm@9.15.9
# Stage 2: Install all dependencies (including dev)
FROM base AS deps
WORKDIR /temp-deps
COPY package.json pnpm-lock.yaml ./
# Runflare injects NODE_ENV=production globally, which skips devDependencies.
# @nestjs/cli and typescript are required for the build step.
ENV NODE_ENV=development
# RUN pnpm install --frozen-lockfile --loglevel info \
# --registry=https://mirror-npm.runflare.com
RUN pnpm install --frozen-lockfile --loglevel info \
# Stage 3: Build
FROM base AS builder
WORKDIR /build
COPY . ./
COPY --from=deps /temp-deps/node_modules ./node_modules
RUN if grep -q '"build":' package.json; then pnpm run build; fi
# Stage 4: Production deps only
FROM base AS prod-deps
WORKDIR /temp-deps
COPY package.json pnpm-lock.yaml ./
# RUN pnpm install --prod --frozen-lockfile --loglevel info \
# --registry=https://mirror-npm.runflare.com
RUN pnpm install --prod --frozen-lockfile --loglevel info
# Stage 5: Runner
FROM base AS runner
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
# Copy only production node_modules, build output, and JWT keys
COPY --from=prod-deps --chown=appuser:appgroup /temp-deps/node_modules ./node_modules
COPY --from=builder --chown=appuser:appgroup /build/dist ./dist
COPY --from=builder --chown=appuser:appgroup /build/keys ./keys
COPY --chown=appuser:appgroup package.json ./
USER appuser
ENV NODE_ENV=production
EXPOSE 3500
CMD ["pnpm", "start"]