Files
tehran_tala/apps/api/Dockerfile
T

48 lines
1.3 KiB
Docker
Raw Normal View History

2026-09-10 00:18:53 +03:30
FROM node:20-bookworm AS base
2026-09-09 19:39:13 +03:30
2026-09-10 00:25:43 +03:30
# 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}
2026-09-09 19:39:13 +03:30
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
2026-09-10 00:25:43 +03:30
# Skip corepack (it fetches pnpm from npmjs/Cloudflare). Install from mirror instead.
RUN npm install -g pnpm@9.0.0 turbo@2.10.12 \
&& printf 'registry=%s\n' "${NPM_REGISTRY}" > /root/.npmrc
2026-09-09 19:39:13 +03:30
2026-09-10 00:13:03 +03:30
FROM base AS builder
2026-09-09 19:39:13 +03:30
WORKDIR /app
COPY . .
RUN turbo prune api --docker
2026-09-10 00:13:03 +03:30
FROM base AS installer
2026-09-09 19:39:13 +03:30
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
2026-09-10 00:25:43 +03:30
RUN pnpm install --frozen-lockfile
2026-09-09 19:39:13 +03:30
# Build the project and its dependencies
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
# Generate prisma client before building
RUN pnpm --filter api exec prisma generate
RUN pnpm turbo run build --filter=api...
2026-09-10 00:13:03 +03:30
FROM base AS runner
2026-09-09 19:39:13 +03:30
WORKDIR /app
# Don't run production as root
2026-09-10 00:13:03 +03:30
RUN groupadd --system --gid 1001 nodejs \
&& useradd --system --uid 1001 --gid nodejs nestjs
2026-09-09 19:39:13 +03:30
USER nestjs
COPY --from=installer /app .
WORKDIR /app/apps/api
EXPOSE 3000
CMD ["node", "dist/main.js"]