diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85b02738f..f3708765f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -225,8 +225,8 @@ jobs: echo "Version check failed: missing mode=server" exit 1 fi - if ! echo "$response" | grep -q '"version"'; then - echo "Version check failed: missing version field" + if ! echo "$response" | grep -q '"git_describe"'; then + echo "Version check failed: missing git_describe field" exit 1 fi diff --git a/Dockerfile b/Dockerfile index 8bff9dcbb..d96b627ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # mux server Docker image -# Multi-stage build for minimal runtime image size +# Multi-stage build with esbuild bundling for minimal runtime image # # Build: docker build -t mux-server . # Run: docker run -p 3000:3000 -v ~/.mux:/root/.mux mux-server @@ -16,8 +16,9 @@ WORKDIR /app # Install bun (used for package management and build tooling) RUN npm install -g bun@1.2 -# Install git (needed for version generation) -RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* +# Install git (needed for version generation) and build tools for native modules +# bzip2 is required for lzma-native to extract its bundled xz source tarball +RUN apt-get update && apt-get install -y git python3 make g++ bzip2 && rm -rf /var/lib/apt/lists/* # Copy package files first for better layer caching COPY package.json bun.lock bunfig.toml ./ @@ -25,12 +26,7 @@ COPY package.json bun.lock bunfig.toml ./ # Copy postinstall script (needed by bun install) COPY scripts/postinstall.sh scripts/ -# Install build tools needed for native modules -# bzip2 is required for lzma-native to extract its bundled xz source tarball -RUN apt-get update && apt-get install -y python3 make g++ bzip2 && rm -rf /var/lib/apt/lists/* - -# Install dependencies (postinstall detects server mode and skips Electron rebuild) -# Note: node-pty is in optionalDependencies and will be built for Node.js +# Install dependencies RUN bun install --frozen-lockfile # Copy source files needed for build @@ -62,6 +58,21 @@ RUN NODE_ENV=production bun run node_modules/@typescript/native-preview/bin/tsgo # Build renderer (frontend) RUN bun x vite build +# Bundle server with esbuild (reduces ~2GB node_modules to ~10MB bundle) +# External: native modules that can't be bundled +# Alias: use ESM version of jsonc-parser to avoid UMD bundling issues +RUN bun x esbuild dist/cli/server.js \ + --bundle \ + --platform=node \ + --target=node22 \ + --format=cjs \ + --outfile=dist/server-bundle.js \ + --external:@lydell/node-pty \ + --external:node-pty \ + --external:electron \ + --alias:jsonc-parser=jsonc-parser/lib/esm/main.js \ + --minify + # Copy static assets RUN mkdir -p dist/static && cp -r static/* dist/static/ 2>/dev/null || true @@ -79,10 +90,16 @@ RUN apt-get update && \ apt-get install -y git openssh-client && \ rm -rf /var/lib/apt/lists/* -# Copy built artifacts from builder -COPY --from=builder /app/dist ./dist -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./ +# Copy bundled server and frontend assets +# Vite outputs JS/CSS/HTML directly to dist/ (assetsDir: ".") +COPY --from=builder /app/dist/server-bundle.js ./dist/ +COPY --from=builder /app/dist/*.html ./dist/ +COPY --from=builder /app/dist/*.js ./dist/ +COPY --from=builder /app/dist/*.css ./dist/ +COPY --from=builder /app/dist/static ./dist/static + +# Copy only native modules needed at runtime (node-pty for terminal support) +COPY --from=builder /app/node_modules/@lydell ./node_modules/@lydell # Create mux data directory RUN mkdir -p /root/.mux @@ -98,8 +115,8 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node -e "fetch('http://localhost:3000/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))" -# Run mux server +# Run bundled mux server # --host 0.0.0.0: bind to all interfaces (required for Docker networking) # --port 3000: default port (can be remapped via docker run -p) -ENTRYPOINT ["node", "dist/cli/index.js", "server"] +ENTRYPOINT ["node", "dist/server-bundle.js"] CMD ["--host", "0.0.0.0", "--port", "3000"]