Add host-build deploy path for slow Docker npm installs

Install and build on the server host with npmmirror, then package a slim image without network during docker build.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 21:17:44 +03:30
co-authored by Cursor
parent ad236b7357
commit 56afc032d2
4 changed files with 92 additions and 2 deletions
-2
View File
@@ -1,5 +1,3 @@
node_modules
dist
coverage
.git
.gitignore
+20
View File
@@ -0,0 +1,20 @@
# ایمیج سبک: فرض می‌کند روی خود سرور قبلاً npm ci + build زده‌ای
# هیچ دانلودی داخل Docker انجام نمی‌شود (مناسب سرور ایران)
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
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"]
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
MIRROR="${NPM_REGISTRY:-https://registry.npmmirror.com}"
MIRROR="${MIRROR%/}"
echo "==> npm registry: $MIRROR"
npm config set registry "$MIRROR"
sed -i \
-e "s|https://registry.npmjs.org|${MIRROR}|g" \
-e "s|https://mirror.iranserver.com/npm|${MIRROR}|g" \
package-lock.json
echo "==> npm ci (روی خود سرور، خارج از Docker)..."
npm ci --no-audit --no-fund
echo "==> prisma generate + build..."
npx prisma generate
npm run build
# prisma CLI برای migrate داخل کانتینر لازم است
npm install prisma ts-node typescript --no-save --no-audit --no-fund --registry="$MIRROR"
echo "==> Docker up (بدون دانلود npm داخل بیلد)..."
export RUN_SEED="${RUN_SEED:-true}"
docker compose -f docker-compose.prebuilt.yml up -d --build
echo ""
echo "OK. health: curl http://127.0.0.1:3000/api/health"
echo "logs: docker compose -f docker-compose.prebuilt.yml logs -f api"
+41
View File
@@ -0,0 +1,41 @@
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
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-fabric}:${POSTGRES_PASSWORD:-fabric123}@postgres:5432/${POSTGRES_DB:-fabric_trade}?schema=public
JWT_SECRET: ${JWT_SECRET:-fabric-trade-dev-secret-change-me}
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-7d}
PORT: 3000
MOCK_OTP_CODE: ${MOCK_OTP_CODE:-123456}
OTP_TTL_MINUTES: ${OTP_TTL_MINUTES:-5}
RUN_SEED: ${RUN_SEED:-false}
ports:
- '127.0.0.1:${API_PORT:-3000}:3000'
volumes:
fabric_pg_data: