# syntax = docker/dockerfile:1 ARG NODE_VERSION=20 FROM node:${NODE_VERSION}-slim AS base-node WORKDIR /app ENV NODE_ENV="production" # Install system dependencies for building native modules RUN apt-get update -qq && \ apt-get install --no-install-recommends -y \ build-essential \ node-gyp \ pkg-config \ python-is-python3 \ curl \ ca-certificates \ unzip && \ rm -rf /var/lib/apt/lists/* FROM base-node AS build-main # Copy package files COPY website/package.json website/package-lock.json* ./ RUN npm install --include=dev # Copy source files COPY website/. ./ # Build the application RUN npm run build # Debug: Check what directories were created RUN echo "=== Checking build output ===" && \ ls -la && \ echo "=== Contents of any build-related directories ===" && \ (ls -la build 2>/dev/null || echo "No build directory") && \ (ls -la dist 2>/dev/null || echo "No dist directory") && \ (ls -la .svelte-kit 2>/dev/null || echo "No .svelte-kit directory") && \ echo "=== End debug ===" # Remove dev dependencies RUN npm prune --omit=dev FROM base-node AS build-websocket WORKDIR /websocket # Install Bun RUN curl -fsSL https://bun.sh/install | bash ENV PATH="/root/.bun/bin:${PATH}" # Copy websocket package files COPY website/websocket/package.json website/websocket/bun.lock* ./ COPY website/websocket/tsconfig.json ./ # Install dependencies RUN bun install # Copy websocket source COPY website/websocket/src ./src/ # Build websocket RUN bun build src/main.ts --outdir dist --target bun FROM base-node AS production-main RUN --mount=from=build-main,source=/app/.svelte-kit/output,target=/debug \ echo "=== SvelteKit output structure ===" && \ find /debug -type f -name "*.js" | head -20 && \ echo "=== End debug ===" COPY --from=build-main --chown=node:node /app/.svelte-kit/output ./build COPY --from=build-main --chown=node:node /app/node_modules ./node_modules COPY --from=build-main --chown=node:node /app/package.json ./package.json RUN echo "=== Build directory contents ===" && \ find ./build -type f -name "*.js" | head -20 && \ echo "=== End debug ===" # Copy cluster server COPY cluster-server.js ./cluster-server.js USER node EXPOSE 3000 CMD ["sh", "-c", "echo '=== Build directory contents ==='; find ./build -type f | head -20; echo '=== Starting server ==='; node cluster-server.js"] FROM base-node AS production-websocket WORKDIR /websocket # Install Bun in production stage RUN curl -fsSL https://bun.sh/install | bash ENV PATH="/root/.bun/bin:${PATH}" # Copy built websocket from build stage COPY --from=build-websocket /websocket/dist ./dist COPY --from=build-websocket /websocket/package.json ./package.json EXPOSE 8080 CMD ["bun", "run", "dist/main.js"]