Restore git-pull-only deploy: single compose path with schema from git

Deploy is back to the flow that worked: build dist locally, push, then on the
server only `git pull` + `docker compose up -d --build`. The Dockerfile now
also takes prisma/ and package.json from git and runs `prisma generate`, so
schema and migration changes ship without rebuilding the 120MB node_modules
bundle. Removes the prebuilt compose path, which could never work on a server
without npm.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-08 16:14:53 +03:30
co-authored by Cursor
parent a0da04e1ae
commit 811f671e78
6 changed files with 36 additions and 84 deletions
-11
View File
@@ -3,24 +3,13 @@
* *
!deploy-bundle.tar.gz !deploy-bundle.tar.gz
!Dockerfile !Dockerfile
!Dockerfile.prebuilt
!Dockerfile.bundle
!Dockerfile.dist
!docker-compose.yml !docker-compose.yml
!docker-compose.prebuilt.yml
!docker-compose.bundle.yml
!docker-compose.dist.yml
!docker-entrypoint.sh !docker-entrypoint.sh
!dist !dist
!dist/** !dist/**
# برای Dockerfile.prebuilt (بیلد لوکال + اجرا روی سرور)
!package.json !package.json
!package-lock.json !package-lock.json
!prisma !prisma
!prisma/** !prisma/**
!prisma.config.ts !prisma.config.ts
!node_modules
!node_modules/**
!.env.example !.env.example
+1
View File
@@ -5,6 +5,7 @@
/build /build
/generated /generated
.deploy-pack .deploy-pack
server-runtime.tgz
# logs # logs
logs logs
+10 -1
View File
@@ -9,10 +9,19 @@ COPY deploy-bundle.tar.gz /tmp/deploy-bundle.tar.gz
RUN tar -xzf /tmp/deploy-bundle.tar.gz -C /app \ RUN tar -xzf /tmp/deploy-bundle.tar.gz -C /app \
&& rm /tmp/deploy-bundle.tar.gz && rm /tmp/deploy-bundle.tar.gz
# dist و entrypoint از گیت — بدون بازسازی کل باندل # همه‌چیز جز node_modules از گیت می‌آید تا دیپلوی فقط با git pull انجام شود
COPY package.json package-lock.json prisma.config.ts /app/
COPY prisma /app/prisma
COPY dist /app/dist COPY dist /app/dist
COPY docker-entrypoint.sh /app/docker-entrypoint.sh COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh RUN chmod +x /app/docker-entrypoint.sh
# کلاینت Prisma باید با اسکیمای گیت هم‌خوان شود؛ آفلاین است چون engine در باندل هست
ENV CHECKPOINT_DISABLE=1
ENV PRISMA_HIDE_UPDATE_MESSAGE=1
# DATABASE_URL فقط برای بارگذاری prisma.config.ts لازم است، اتصالی برقرار نمی‌شود
RUN DATABASE_URL="postgresql://build:build@localhost:5432/build?schema=public" \
./node_modules/.bin/prisma generate
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"] ENTRYPOINT ["./docker-entrypoint.sh"]
-21
View File
@@ -1,21 +0,0 @@
# ایمیج prebuilt: dist و node_modules از قبل روی سرور هستند
# bookworm تا OpenSSL برای Prisma آماده باشد (alpine این را ندارد)
FROM node:22-bookworm
WORKDIR /app
ENV NODE_ENV=production
ENV TZ=Asia/Tehran
COPY package.json package-lock.json ./
COPY node_modules ./node_modules
COPY dist ./dist
COPY prisma ./prisma
COPY prisma.config.ts ./
COPY docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"]
+25 -12
View File
@@ -25,30 +25,43 @@ npm run prisma:seed
npm run start:dev npm run start:dev
``` ```
## دیپلوی با Docker Compose (پیشنهادی برای سرور) ## دیپلوی: بیلد روی سیستم خودت، اجرا روی سرور
روی سرور داخل `fabric_trade_server`: روی سرور هیچ `npm` یا دانلودی لازم نیست. `node_modules` از قبل داخل
`deploy-bundle.tar.gz` (روی گیت) است و `dist` هم روی گیت commit می‌شود.
**۱) روی سیستم خودت:**
```bash ```bash
# اولین بار با دیتای فیک: cd fabric_trade_server
RUN_SEED=true docker compose up -d --build npm run build
git add dist && git commit -m "..." && git push
```
# بعداً بدون seed: **۲) روی سرور:**
```bash
cd /opt/parche/server
git pull
docker compose up -d --build docker compose up -d --build
docker compose logs -f api
``` ```
اگر بیلد به‌خاطر رجیستری npm یا Alpine خطا داد (رایج روی سرورهای ایران): `Dockerfile` باندل را باز می‌کند، بعد `dist` و `prisma` و `package.json` را از
گیت روی آن می‌نویسد و `prisma generate` می‌زند؛ پس تغییر schema و مایگریشن
جدید هم فقط با `git pull` می‌رسد.
**فقط اگر پکیج npm جدید اضافه شد** باندل را دوباره بساز و push کن:
```bash ```bash
# پیش‌فرض Dockerfile از میرور npmmirror استفاده می‌کند. bash scripts/pack-bundle.sh
# در صورت نیاز: git add deploy-bundle.tar.gz && git commit -m "refresh deploy bundle" && git push
docker compose build --build-arg NPM_REGISTRY=https://registry.npmmirror.com
RUN_SEED=true docker compose up -d
``` ```
- API روی `127.0.0.1:3000` بالا می‌آید - `env` سرور از `.env` همان پوشه خوانده می‌شود (`env_file` در compose)
- API روی `127.0.0.1:${API_PORT}` بالا می‌آید (سرور: `8585`)
- مایگریشن موقع استارت کانتینر اجرا می‌شود - مایگریشن موقع استارت کانتینر اجرا می‌شود
- LiteSpeed را Reverse Proxy کنید به `http://127.0.0.1:3000` - LiteSpeed را Reverse Proxy کنید به `http://127.0.0.1:8585`
مثال مسیر LiteSpeed: `https://domain.com/api/` → `http://127.0.0.1:3000/api/` مثال مسیر LiteSpeed: `https://domain.com/api/` → `http://127.0.0.1:3000/api/`
-39
View File
@@ -1,39 +0,0 @@
services:
postgres:
image: postgres:16-alpine
container_name: fabric_trade_db
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-fabric}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-fabric123}
POSTGRES_DB: ${POSTGRES_DB:-fabric_trade}
ports:
- '${POSTGRES_PORT:-5432}:5432'
volumes:
- fabric_pg_data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB']
interval: 5s
timeout: 5s
retries: 10
api:
build:
context: .
dockerfile: Dockerfile.prebuilt
container_name: fabric_trade_api
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
env_file:
- .env
environment:
# داخل شبکهٔ Docker باید به سرویس postgres وصل شود، نه localhost
DATABASE_URL: postgresql://${POSTGRES_USER:-fabric}:${POSTGRES_PASSWORD:-fabric123}@postgres:5432/${POSTGRES_DB:-fabric_trade}?schema=public
PORT: 3000
ports:
- '127.0.0.1:${API_PORT:-3000}:3000'
volumes:
fabric_pg_data: