Add offline deploy bundle with dist and production node_modules

Allow shipping a tarball so the server Docker image only copies files and never runs npm.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 21:43:59 +03:30
co-authored by Cursor
parent 44f030bc06
commit b620dd0015
4 changed files with 115 additions and 0 deletions
+2
View File
@@ -4,6 +4,8 @@
/node_modules /node_modules
/build /build
/generated /generated
.deploy-pack
deploy-bundle.tar.gz
# logs # logs
logs logs
+17
View File
@@ -0,0 +1,17 @@
# فقط کپی فایل‌های آماده‌شده — بدون npm
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package.json package-lock.json ./
COPY node_modules ./node_modules
COPY prisma ./prisma
COPY prisma.config.ts ./
COPY dist ./dist
COPY docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"]
+40
View File
@@ -0,0 +1,40 @@
services:
postgres:
image: postgres:16-alpine
container_name: fabric_trade_db
restart: unless-stopped
env_file:
- .env
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
container_name: fabric_trade_api
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
env_file:
- .env
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-fabric}:${POSTGRES_PASSWORD:-fabric123}@postgres:5432/${POSTGRES_DB:-fabric_trade}?schema=public
PORT: ${PORT:-3000}
ports:
- '127.0.0.1:${API_PORT:-3000}:3000'
volumes:
fabric_pg_data:
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
MIRROR="${NPM_REGISTRY:-https://registry.npmmirror.com}"
OUT="deploy-bundle.tar.gz"
PACK=".deploy-pack"
echo "==> بیلد + بسته‌بندی کامل (dist + node_modules)"
echo "==> بعداً روی سرور دیگر npm زده نمی‌شود"
npm config set registry "$MIRROR"
npm ci --no-audit --no-fund
npx prisma generate
rm -rf dist tsconfig.build.tsbuildinfo
npx nest build
test -f dist/main.js
rm -rf "$PACK" /tmp/fabric-prod-pack
mkdir -p "$PACK" /tmp/fabric-prod-pack
cp package.json package-lock.json /tmp/fabric-prod-pack/
(
cd /tmp/fabric-prod-pack
sed -i "s|https://registry.npmjs.org|${MIRROR}|g" package-lock.json || true
npm ci --omit=dev --no-audit --no-fund --registry="$MIRROR"
npm install prisma ts-node typescript --no-save --no-audit --no-fund --registry="$MIRROR"
npx prisma generate
)
cp package.json package-lock.json "$PACK/"
cp -a prisma "$PACK/"
cp prisma.config.ts docker-entrypoint.sh "$PACK/"
cp -a dist "$PACK/"
cp -a /tmp/fabric-prod-pack/node_modules "$PACK/"
cp Dockerfile.bundle "$PACK/Dockerfile"
cp docker-compose.bundle.yml "$PACK/docker-compose.yml"
cp .env.example "$PACK/"
# dockerignore داخل باندل: چیزی را حذف نکند
cat > "$PACK/.dockerignore" <<'EOF'
.git
.env
*.md
EOF
tar -czf "$OUT" -C "$PACK" .
ls -lh "$OUT"
echo ""
echo "scp $OUT root@SERVER:/opt/parche/"
echo "روی سرور:"
echo " mkdir -p /opt/parche/app && tar -xzf /opt/parche/deploy-bundle.tar.gz -C /opt/parche/app"
echo " cd /opt/parche/app && cp -n .env.example .env && nano .env"
echo " RUN_SEED=true docker compose up -d --build"
echo " # بیلد Docker فقط COPY است؛ npm ندارد"