Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Fix server image crash: materialize @rybbit/shared symlink in builder

Bill Yang00a52750416b
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 000000000..d4cad6fb6
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,10 @@
+# Keep host-side artifacts out of image builds: node_modules are installed
+# inside the Dockerfiles (host copies are platform-mismatched on macOS),
+# dist/.next are rebuilt inside, and stale *.tsbuildinfo can make tsc skip
+# emitting into a dist the context no longer carries.
+.git
+**/node_modules
+**/*.tsbuildinfo
+client/.next
+server/dist
+shared/dist
diff --git a/server/Dockerfile b/server/Dockerfile
index 079ea738b..910842374 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -17,6 +17,15 @@ RUN npm ci --legacy-peer-deps
# Copy server source code
COPY server/ .
+# npm installs the file:../shared dependency as a relative symlink
+# (node_modules/@rybbit/shared -> ../../../shared). The runtime stage re-homes
+# node_modules from /app/server to /app, which leaves that link pointing at
+# /shared — outside the image. Materialize it into a real directory so the
+# copied node_modules is location-independent.
+RUN rm -rf node_modules/@rybbit/shared \
+ && mkdir -p node_modules/@rybbit/shared \
+ && cp -r /app/shared/package.json /app/shared/dist node_modules/@rybbit/shared/
+
# Build the application
RUN npm run build
@@ -50,7 +59,6 @@ COPY --from=builder /app/server/drizzle.config.ts ./drizzle.config.ts
COPY --from=builder /app/server/drizzle ./drizzle
COPY --from=builder /app/server/public ./public
COPY --from=builder /app/server/src ./src
-COPY --from=builder /app/shared ./shared
# Make the entrypoint executable
RUN chmod +x /docker-entrypoint.sh