Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 32 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,21 +16,17 @@ 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 ./

# 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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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"]