Extract deploy bundle inside Dockerfile so server needs no tar command
Server workflow is only git pull and docker compose up --build; env still comes from .env. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+5
-15
@@ -1,16 +1,6 @@
|
||||
node_modules
|
||||
coverage
|
||||
.git
|
||||
.gitignore
|
||||
.env
|
||||
.env.*
|
||||
# فقط باندل و فایلهای لازم برای بیلد ایمیج
|
||||
*
|
||||
!deploy-bundle.tar.gz
|
||||
!Dockerfile
|
||||
!docker-compose.yml
|
||||
!.env.example
|
||||
*.md
|
||||
.vscode
|
||||
.idea
|
||||
test
|
||||
*.spec.ts
|
||||
.pgdata
|
||||
.tools
|
||||
dist-docker
|
||||
src
|
||||
|
||||
+6
-47
@@ -1,54 +1,13 @@
|
||||
# میرور کامل و سازگار با ساختار registry.npmjs.org
|
||||
# (mirror.iranserver.com/npm ناقص است و خیلی پکیجها 404 میدهد)
|
||||
ARG NPM_REGISTRY=https://registry.npmmirror.com
|
||||
|
||||
FROM node:22-alpine AS builder
|
||||
ARG NPM_REGISTRY=https://registry.npmmirror.com
|
||||
WORKDIR /app
|
||||
|
||||
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# npm ci از URLهای resolved داخل lockfile استفاده میکند
|
||||
RUN set -eux; \
|
||||
mirror="$(echo "${NPM_REGISTRY}" | sed 's:/*$::')"; \
|
||||
sed -i \
|
||||
-e "s|https://registry.npmjs.org|${mirror}|g" \
|
||||
-e "s|https://mirror.iranserver.com/npm|${mirror}|g" \
|
||||
package-lock.json; \
|
||||
npm config set registry "${mirror}"; \
|
||||
npm config set fetch-retries 5; \
|
||||
npm config set fetch-retry-mintimeout 20000; \
|
||||
npm config set fetch-retry-maxtimeout 120000; \
|
||||
echo "Using npm registry: ${mirror}"; \
|
||||
npm ci --no-audit --no-fund; \
|
||||
echo "npm ci done"
|
||||
|
||||
COPY prisma ./prisma
|
||||
COPY prisma.config.ts ./
|
||||
COPY tsconfig.json tsconfig.build.json nest-cli.json ./
|
||||
COPY src ./src
|
||||
|
||||
RUN npx prisma generate \
|
||||
&& npm run build \
|
||||
&& npm prune --omit=dev \
|
||||
&& npm install prisma ts-node typescript --no-save --no-audit --no-fund --registry=${NPM_REGISTRY}
|
||||
|
||||
FROM node:22-alpine AS runner
|
||||
# باندل از گیت میآید؛ داخل ایمیج باز میشود — روی سرور tar لازم نیست
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
COPY --from=builder /app/package.json /app/package-lock.json ./
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
COPY --from=builder /app/prisma.config.ts ./
|
||||
COPY docker-entrypoint.sh ./
|
||||
|
||||
RUN chmod +x docker-entrypoint.sh
|
||||
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 \
|
||||
&& chmod +x /app/docker-entrypoint.sh
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
|
||||
@@ -23,8 +23,6 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.npmmirror.com}
|
||||
container_name: fabric_trade_api
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# روی سرور: یک دستور
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
git pull --no-rebase
|
||||
docker compose up -d --build
|
||||
docker compose ps
|
||||
echo "health: curl -s http://127.0.0.1:3000/api/health"
|
||||
Reference in New Issue
Block a user