chore: add docker configuration

This commit is contained in:
s.esmaeili
2026-09-09 19:39:13 +03:30
parent 0ed6bed028
commit 78a68b3567
6 changed files with 201 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
FROM node:20-alpine AS alpine
RUN apk update
RUN apk add --no-cache libc6-compat openssl
# Setup pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable pnpm
FROM alpine AS builder
WORKDIR /app
RUN pnpm i -g turbo
COPY . .
RUN turbo prune api --docker
FROM alpine AS installer
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
# 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...
FROM alpine AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nestjs
USER nestjs
COPY --from=installer /app .
WORKDIR /app/apps/api
EXPOSE 3000
CMD ["node", "dist/main.js"]