Fix some for production

This commit is contained in:
mahmood
2026-09-10 12:17:47 +03:30
parent 78e148a6b5
commit cea3b808d8
121 changed files with 86493 additions and 211 deletions
+7 -45
View File
@@ -1,51 +1,13 @@
FROM node:20-bookworm AS base
FROM docker.arvancloud.ir/node:20-alpine
# Server often cannot reach registry.npmjs.org (Cloudflare). Override in Dokploy if needed.
ARG NPM_REGISTRY=https://mirror.kargadan.ir/repository/npm-group/
ENV npm_config_registry=${NPM_REGISTRY}
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# Skip corepack (it fetches pnpm from npmjs/Cloudflare). Install from mirror instead.
# Pin major only — Iranian mirrors often lag behind exact patch versions (e.g. 2.10.12).
RUN npm install -g pnpm@9 turbo@2 \
&& printf 'registry=%s\n' "${NPM_REGISTRY}" > /root/.npmrc
FROM base AS builder
WORKDIR /app
COPY . .
RUN turbo prune api --docker
FROM base AS installer
# Pre-built on the developer machine:
# pnpm --filter @gold-bank/shared-types build && pnpm --filter api build:release
WORKDIR /app
# First install dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install --frozen-lockfile
ENV NODE_ENV=production
# Build the project and its dependencies
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
COPY tsconfig.base.json tsconfig.base.json
# Re-link workspace after full source copy (pnpm symlinks)
RUN pnpm install --frozen-lockfile --offline || pnpm install --frozen-lockfile
# Generate prisma client before building
RUN pnpm --filter api exec prisma generate
RUN pnpm turbo run build --filter=api...
FROM base AS runner
WORKDIR /app
# Don't run production as root
RUN groupadd --system --gid 1001 nodejs \
&& useradd --system --uid 1001 --gid nodejs nestjs
USER nestjs
COPY --from=installer /app .
WORKDIR /app/apps/api
COPY release/ ./
EXPOSE 3000
CMD ["node", "dist/main.js"]
CMD ["node", "app.js"]