Ship prebuilt Prisma client so the server never runs prisma generate

prisma generate needs over three minutes on the production host, which made
every deploy hang on that build step. The client is now generated on the dev
machine into prisma-client.tar.gz (tracked, 8.5MB) and the image just untars
it. Dropping the unused linux-musl engine target halves that payload.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-08 16:35:06 +03:30
co-authored by Cursor
parent aa9b3ee451
commit d5dfd6a0f0
7 changed files with 49 additions and 12 deletions
+9 -4
View File
@@ -9,15 +9,20 @@ COPY deploy-bundle.tar.gz /tmp/deploy-bundle.tar.gz
RUN tar -xzf /tmp/deploy-bundle.tar.gz -C /app \
&& rm /tmp/deploy-bundle.tar.gz
# هیچ دستور prisma یا npm روی سرور اجرا نمی‌شود؛ همه چیز از قبل ساخته آمده است
ENV CHECKPOINT_DISABLE=1
ENV DO_NOT_TRACK=1
ENV PRISMA_HIDE_UPDATE_MESSAGE=1
# اسکیما و generate قبل از dist بمانند تا لایه‌شان کش شود؛ generate روی سرور کند است
COPY package.json package-lock.json prisma.config.ts /app/
COPY prisma /app/prisma
# DATABASE_URL فقط برای بارگذاری prisma.config.ts لازم است، اتصالی برقرار نمی‌شود
RUN DATABASE_URL="postgresql://build:build@localhost:5432/build?schema=public" \
./node_modules/.bin/prisma generate
# کلاینت Prisma روی سیستم دولوپر با scripts/pack-prisma-client.sh ساخته می‌شود
COPY prisma-client.tar.gz /tmp/prisma-client.tar.gz
RUN rm -rf /app/node_modules/.prisma/client \
&& mkdir -p /app/node_modules/.prisma \
&& tar -xzf /tmp/prisma-client.tar.gz -C /app/node_modules/.prisma \
&& rm /tmp/prisma-client.tar.gz
# dist آخر باشد تا دیپلوی معمولی فقط همین لایه را دوباره بسازد
COPY dist /app/dist