From 1f21fbfe169bc9195bfcd5798d8a579f206a28f4 Mon Sep 17 00:00:00 2001 From: Jafeng <2998840497@qq.com> Date: Thu, 13 Nov 2025 15:27:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96docker=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 37 +++++++++++++++++++++++++++++++++++++ Dockerfile | 1 - docker-compose.yml | 15 +++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ed9266b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,37 @@ +# Speed up docker build by shrinking context and avoiding host artifacts +.git +.gitignore +node_modules +pnpm-debug.log +npm-debug.log +yarn-debug.log +yarn-error.log +.DS_Store +**/.DS_Store + +# Monorepo: ignore nested installs and build outputs +apps/**/node_modules +apps/**/dist +apps/**/.next +apps/**/.nuxt +apps/**/build +apps/**/.cache + +# Editor/OS noise +.vscode +.idea +*.swp +*.swo +Thumbs.db + +# Docker +Dockerfile* +!Dockerfile +docker-compose*.yml +!.dockerignore + +# Tests and coverage +coverage +**/coverage +*.lcov + diff --git a/Dockerfile b/Dockerfile index d5192fc..a806e09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,6 @@ RUN pnpm --filter backend build FROM base AS runtime WORKDIR /app -RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/* COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY apps/backend/package.json ./apps/backend/ # Copy node_modules from deps stage and prune to production to avoid network diff --git a/docker-compose.yml b/docker-compose.yml index 799e5e8..733470c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,14 +10,23 @@ services: MONGO_INITDB_DATABASE: ai-bill volumes: - mongo-data:/data/db + healthcheck: + test: ["CMD-SHELL", "mongosh --quiet --eval 'db.runCommand({ ping: 1 }).ok' | grep 1"] + interval: 10s + timeout: 5s + retries: 10 backend: build: context: . dockerfile: Dockerfile + args: + # 可根据网络情况切换为国内镜像源 + NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.npmjs.org/} container_name: ai-bill-backend depends_on: - - mongo + mongo: + condition: service_healthy environment: NODE_ENV: production HOST: 0.0.0.0 @@ -30,8 +39,10 @@ services: ports: - "4010:4000" restart: unless-stopped + stop_signal: SIGTERM + stop_grace_period: 20s healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:4000/api/health"] + test: ["CMD", "node", "-e", "fetch('http://localhost:4000/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"] interval: 30s timeout: 5s retries: 5