Yuki Takei 3 недель назад
Родитель
Сommit
5cf06e35d6
3 измененных файлов с 33 добавлено и 25 удалено
  1. 2 13
      .github/workflows/reusable-app-prod.yml
  2. 30 0
      apps/app/bin/assemble-prod.sh
  3. 1 12
      apps/app/docker/Dockerfile

+ 2 - 13
.github/workflows/reusable-app-prod.yml

@@ -57,19 +57,8 @@ jobs:
       env:
         ANALYZE: 1
 
-    - name: Assembling all dependencies
-      run: |
-        rm -rf out
-        pnpm deploy out --prod --legacy --filter @growi/app
-        rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
-
-    - name: Resolve .next/node_modules symlinks
-      run: |
-        if [ -d apps/app/.next/node_modules ]; then
-          cp -rL apps/app/.next/node_modules apps/app/.next/node_modules_resolved
-          rm -rf apps/app/.next/node_modules
-          mv apps/app/.next/node_modules_resolved apps/app/.next/node_modules
-        fi
+    - name: Assemble production artifacts
+      run: bash apps/app/bin/assemble-prod.sh
 
     - name: Archive production files
       id: archive-prod-files

+ 30 - 0
apps/app/bin/assemble-prod.sh

@@ -0,0 +1,30 @@
+#!/bin/bash
+# Assemble production artifacts for GROWI app.
+# Run from the workspace root.
+set -euo pipefail
+
+# Deploy production dependencies into out/, then replace apps/app/node_modules/.
+rm -rf out
+pnpm deploy out --prod --legacy --filter @growi/app
+rm -rf apps/app/node_modules
+mv out/node_modules apps/app/node_modules
+
+# Redirect .next/node_modules/ symlinks from workspace root to deployed apps/app/node_modules/.pnpm/.
+# Turbopack generates symlinks pointing to ../../../../node_modules/.pnpm/ (workspace root),
+# which will not exist in production environments.
+# Rewriting to ../../node_modules/.pnpm/ (apps/app/) uses the pnpm deploy output instead,
+# preserving pnpm's isolated structure so transitive deps remain resolvable.
+if [ -d apps/app/.next/node_modules ]; then
+  find apps/app/.next/node_modules -maxdepth 2 -type l | while read -r link; do
+    target=$(readlink "$link")
+    new_target=$(echo "$target" | sed 's|../../../../node_modules/\.pnpm/|../../node_modules/.pnpm/|')
+    [ "$target" != "$new_target" ] && ln -sfn "$new_target" "$link"
+  done
+fi
+
+# Remove build cache
+rm -rf apps/app/.next/cache
+
+# Remove next.config.ts to prevent Next.js from attempting to install TypeScript at server startup,
+# which would corrupt node_modules (e.g. @growi/core). The compiled next.config.js is used instead.
+rm -f apps/app/next.config.ts

+ 1 - 12
apps/app/docker/Dockerfile

@@ -91,18 +91,7 @@ RUN turbo run clean
 RUN turbo run build --filter @growi/app
 
 # Produce artifacts
-RUN pnpm deploy out --prod --legacy --filter @growi/app
-RUN rm -rf apps/app/node_modules && mv out/node_modules apps/app/node_modules
-RUN rm -rf apps/app/.next/cache
-
-# Resolve .next/node_modules symlinks to real files.
-# Turbopack generates symlinks pointing to the pnpm virtual store (node_modules/.pnpm/),
-# which will not exist in the release image.
-RUN if [ -d apps/app/.next/node_modules ]; then \
-      cp -rL apps/app/.next/node_modules apps/app/.next/node_modules_resolved && \
-      rm -rf apps/app/.next/node_modules && \
-      mv apps/app/.next/node_modules_resolved apps/app/.next/node_modules; \
-    fi
+RUN bash apps/app/bin/assemble-prod.sh
 
 # Stage artifacts into a clean directory for COPY --from
 RUN mkdir -p /tmp/release/apps/app && \