Skip to content

Commit fbf5aa9

Browse files
committed
fix(docker): hocuspocus production stage — install in-stage, do not copy node_modules
Bun symlinks in node_modules break when copied from base to production; rest-api and hocuspocus-server crashed with 'Cannot find package hono' / 'Cannot find module @hocuspocus/server'. Production stage now copies workspace layout from base, runs bun install and prisma generate, then flattens to /app for runtime. Made-with: Cursor
1 parent d395dad commit fbf5aa9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/hocuspocus.server/docker/Dockerfile.bun

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ RUN bun add -d prisma@^6.19.0 --no-save || true
4949

5050
# -----------------------------------------------------------------------------
5151
# Stage 2: Production - Minimal runtime image (flat /app = hocuspocus.server layout)
52+
# Do NOT copy node_modules from base: Bun symlinks break across stages (hono,
53+
# @hocuspocus/server etc. not found). Run bun install in this stage instead.
5254
# -----------------------------------------------------------------------------
5355
FROM oven/bun:1-slim AS production
5456
WORKDIR /app
@@ -64,16 +66,25 @@ RUN rm -rf /var/lib/apt/lists/* && \
6466
# Create non-root user for security
6567
RUN groupadd -r appuser && useradd -r -g appuser appuser
6668

67-
# Copy dependencies from base (hoisted node_modules includes email-templates + Prisma client)
68-
COPY --from=base /app/node_modules ./node_modules
69-
COPY --from=base /app/packages/hocuspocus.server/prisma ./prisma
69+
# Copy workspace layout from base (no node_modules)
70+
COPY --from=base /app/package.json /app/bun.lock* /app/bunfig.toml ./
71+
COPY --from=base /app/packages ./packages
7072

71-
# Copy entrypoint and app source (from base; no context COPY so Dockerfile works with context .)
72-
COPY --from=base /app/packages/hocuspocus.server/scripts/docker-entrypoint.sh /usr/local/bin/
73+
# Fresh install so node_modules is real (Bun symlinks from base would break here)
74+
RUN bun install --frozen-lockfile --production --ignore-scripts
75+
76+
# Prisma generate (schema in packages/hocuspocus.server/prisma)
77+
RUN cd packages/hocuspocus.server && bunx prisma@6 generate
78+
79+
# Copy entrypoint before we remove packages
80+
COPY --from=base /app/packages/hocuspocus.server/scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
7381
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
7482

75-
COPY --from=base /app/packages/hocuspocus.server/src ./src
76-
COPY --from=base /app/packages/hocuspocus.server/package.json ./package.json
83+
# Flat layout for runtime: /app/src, /app/prisma, /app/node_modules, /app/package.json
84+
RUN mv packages/hocuspocus.server/src . && \
85+
mv packages/hocuspocus.server/prisma . && \
86+
cp packages/hocuspocus.server/package.json . && \
87+
rm -rf packages
7788

7889
# Pre-download Prisma CLI for migrations
7990
RUN bunx --bun prisma@^6.19.0 --version || true

0 commit comments

Comments
 (0)