From 3de953223afaeca64fa01f8c5e446551a32b560b Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Tue, 14 Apr 2026 00:32:35 +0700 Subject: [PATCH] fix: API copy Prisma from pnpm store, AI drop Rust/maturin approach - API: copy @prisma/client + .prisma from build stage pnpm store glob (pnpm deploy --prod doesn't include generated Prisma client) - AI: remove Rust toolchain, install underthesea 6.8.0 with fallback to 6.3.4 (underthesea-core maturin build too complex for Kaniko) Co-Authored-By: Claude Opus 4 (1M context) --- apps/api/Dockerfile | 14 ++++++-------- libs/ai-services/Dockerfile | 20 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 6fb19ae..448e89e 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -35,13 +35,8 @@ RUN npx prisma generate \ && cd apps/api && npx nest build # Use pnpm deploy to produce a flat, production-only node_modules -# Then install prisma + generate client in pruned dir (pnpm deploy strips dev deps) -RUN pnpm deploy --legacy --filter @goodgo/api --prod /app/pruned \ - && cd /app/pruned \ - && cp -r /app/prisma ./prisma \ - && npm install --no-save prisma @prisma/client \ - && npx prisma generate \ - && npm remove --no-save prisma +# Copy generated Prisma client from build stage (pnpm deploy doesn't carry it) +RUN pnpm deploy --legacy --filter @goodgo/api --prod /app/pruned # ---- Production ---- FROM node:22-slim AS production @@ -60,12 +55,15 @@ WORKDIR /app ENV NODE_ENV=production -# Copy pruned production node_modules from pnpm deploy (includes Prisma) +# Copy pruned production node_modules COPY --from=build --chown=node:node /app/pruned/node_modules ./node_modules # Copy compiled application COPY --from=build --chown=node:node /app/apps/api/dist ./dist # Prisma schema + migrations (needed for runtime client & migrate deploy) COPY --from=build --chown=node:node /app/prisma ./prisma +# Copy generated Prisma client from build stage (not from pruned) +COPY --from=build --chown=node:node /app/node_modules/.pnpm/@prisma+client@*/node_modules/@prisma/client ./node_modules/@prisma/client +COPY --from=build --chown=node:node /app/node_modules/.pnpm/@prisma+client@*/node_modules/.prisma ./node_modules/.prisma # Package metadata COPY --from=build --chown=node:node /app/apps/api/package.json ./package.json # Entrypoint script diff --git a/libs/ai-services/Dockerfile b/libs/ai-services/Dockerfile index d0f2d16..ff605d4 100644 --- a/libs/ai-services/Dockerfile +++ b/libs/ai-services/Dockerfile @@ -2,20 +2,14 @@ FROM python:3.12-slim WORKDIR /app -# Install system deps for underthesea / numpy + dumb-init + Rust toolchain for maturin +# Install system deps for underthesea / numpy + dumb-init RUN apt-get update && \ - apt-get install -y --no-install-recommends gcc g++ dumb-init curl && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal && \ - rm -rf /var/lib/apt/lists/* && \ - echo 'export PATH="/root/.cargo/bin:$PATH"' >> /etc/profile.d/cargo.sh -ENV PATH="/root/.cargo/bin:${PATH}" + apt-get install -y --no-install-recommends gcc g++ dumb-init && \ + rm -rf /var/lib/apt/lists/* COPY pyproject.toml . -# Install maturin first, then deps with --no-build-isolation for packages needing Rust -RUN /root/.cargo/bin/cargo --version && \ - pip install --no-cache-dir maturin setuptools wheel && \ - pip install --no-cache-dir --no-build-isolation "underthesea==6.8.0" && \ - (pip install --no-cache-dir . 2>/dev/null || pip install --no-cache-dir \ +# Install deps in order: core deps first, then underthesea (may need build tools) +RUN pip install --no-cache-dir \ "fastapi==0.115.0" \ "uvicorn[standard]==0.32.0" \ "xgboost==2.1.0" \ @@ -23,7 +17,9 @@ RUN /root/.cargo/bin/cargo --version && \ "pydantic==2.9.0" \ "pydantic-settings==2.5.0" \ "httpx==0.27.0" \ - "slowapi==0.1.9") + "slowapi==0.1.9" && \ + pip install --no-cache-dir "underthesea==6.8.0" || \ + pip install --no-cache-dir "underthesea==6.3.4" COPY app/ ./app/