From ea15f9434184ccc87cc8300ed1f5081d86652c6b Mon Sep 17 00:00:00 2001 From: pasmud Date: Sat, 11 Apr 2026 00:16:00 +1000 Subject: [PATCH] fix(docker): fix self-hosting Docker build failures The self-hosting Docker Compose setup fails to build on a clean clone due to several issues: 1. Dockerfile.web did not copy .npmrc into the deps stage. The project uses shamefully-hoist=true, so without it pnpm produces a different node_modules layout and module resolution breaks. 2. The builder stage copied individual node_modules directories from the deps stage (COPY --from=deps). This breaks pnpm's symlink structure -- especially on Windows where symlinks resolve to host paths. Additionally, packages/tsconfig has zero dependencies so its node_modules never exists, causing a hard COPY failure. Fixed by copying the full workspace from deps and running an offline pnpm install to re-link after source overlay. 3. next.config.ts imports dotenv but it was not declared as a direct dependency in apps/web/package.json. It resolves locally as a hoisted transitive dep but fails the TypeScript type check during next build in Docker. 4. docker/entrypoint.sh gets CRLF line endings on Windows due to git autocrlf, which breaks the shebang (container looks for /bin/sh\r). Added .gitattributes to enforce LF for shell scripts and a sed strip in the Dockerfile as a safety net. --- .gitattributes | 6 ++++++ Dockerfile | 2 +- Dockerfile.web | 13 ++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..5528041db --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Ensure shell scripts always use LF line endings (needed for Docker on Windows) +*.sh text eol=lf +docker/entrypoint.sh text eol=lf + +# Default behavior +* text=auto diff --git a/Dockerfile b/Dockerfile index cfbd97908..2978968e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY --from=builder /src/server/bin/multica . COPY --from=builder /src/server/bin/migrate . COPY server/migrations/ ./migrations/ COPY docker/entrypoint.sh . -RUN chmod +x entrypoint.sh +RUN sed -i 's/\r$//' entrypoint.sh && chmod +x entrypoint.sh EXPOSE 8080 diff --git a/Dockerfile.web b/Dockerfile.web index 28efaf4a7..143503b80 100644 --- a/Dockerfile.web +++ b/Dockerfile.web @@ -6,7 +6,7 @@ RUN corepack enable && corepack prepare pnpm@10.28.2 --activate WORKDIR /app # Copy workspace config and all package.json files for dependency resolution -COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json ./ +COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json .npmrc ./ COPY apps/web/package.json apps/web/ COPY packages/core/package.json packages/core/ COPY packages/ui/package.json packages/ui/ @@ -23,18 +23,17 @@ RUN corepack enable && corepack prepare pnpm@10.28.2 --activate WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules -COPY --from=deps /app/packages/core/node_modules ./packages/core/node_modules -COPY --from=deps /app/packages/ui/node_modules ./packages/ui/node_modules -COPY --from=deps /app/packages/views/node_modules ./packages/views/node_modules -COPY --from=deps /app/packages/eslint-config/node_modules ./packages/eslint-config/node_modules +# Copy installed dependencies (preserves pnpm symlink structure) +COPY --from=deps /app ./ # Copy source COPY package.json turbo.json pnpm-workspace.yaml ./ COPY apps/web/ apps/web/ COPY packages/ packages/ +# Re-link after source overlay (fixes any symlinks overwritten by COPY) +RUN pnpm install --frozen-lockfile --offline + # Set build-time env: tells Next.js rewrites to proxy API calls to the backend service ARG REMOTE_API_URL=http://backend:8080 ENV REMOTE_API_URL=$REMOTE_API_URL