Skip to content

Commit 20b8404

Browse files
committed
fix: correct Docker smoke test version check and use esbuild bundling
- Fix version field check: use git_describe instead of version - Bundle server with esbuild (~8MB) instead of copying node_modules (~2GB) - Final image size reduced from ~2GB to ~365MB - Only copy native modules (@lydell/node-pty) needed at runtime
1 parent 30b1c08 commit 20b8404

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ jobs:
225225
echo "Version check failed: missing mode=server"
226226
exit 1
227227
fi
228-
if ! echo "$response" | grep -q '"version"'; then
229-
echo "Version check failed: missing version field"
228+
if ! echo "$response" | grep -q '"git_describe"'; then
229+
echo "Version check failed: missing git_describe field"
230230
exit 1
231231
fi
232232

Dockerfile

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mux server Docker image
2-
# Multi-stage build for minimal runtime image size
2+
# Multi-stage build with esbuild bundling for minimal runtime image
33
#
44
# Build: docker build -t mux-server .
55
# Run: docker run -p 3000:3000 -v ~/.mux:/root/.mux mux-server
@@ -16,20 +16,16 @@ WORKDIR /app
1616
# Install bun (used for package management and build tooling)
1717
RUN npm install -g bun@1.2
1818

19-
# Install git (needed for version generation)
20-
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
19+
# Install git (needed for version generation) and build tools for native modules
20+
RUN apt-get update && apt-get install -y git python3 make g++ && rm -rf /var/lib/apt/lists/*
2121

2222
# Copy package files first for better layer caching
2323
COPY package.json bun.lock bunfig.toml ./
2424

2525
# Copy postinstall script (needed by bun install)
2626
COPY scripts/postinstall.sh scripts/
2727

28-
# Install build tools needed for native modules
29-
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
30-
31-
# Install dependencies (postinstall detects server mode and skips Electron rebuild)
32-
# Note: node-pty is in optionalDependencies and will be built for Node.js
28+
# Install dependencies
3329
RUN bun install --frozen-lockfile
3430

3531
# Copy source files needed for build
@@ -60,6 +56,21 @@ RUN NODE_ENV=production bun x tsc -p tsconfig.main.json && \
6056
# Build renderer (frontend)
6157
RUN bun x vite build
6258

59+
# Bundle server with esbuild (reduces ~2GB node_modules to ~10MB bundle)
60+
# External: native modules that can't be bundled
61+
# Alias: use ESM version of jsonc-parser to avoid UMD bundling issues
62+
RUN bun x esbuild dist/cli/server.js \
63+
--bundle \
64+
--platform=node \
65+
--target=node22 \
66+
--format=cjs \
67+
--outfile=dist/server-bundle.js \
68+
--external:@lydell/node-pty \
69+
--external:node-pty \
70+
--external:electron \
71+
--alias:jsonc-parser=jsonc-parser/lib/esm/main.js \
72+
--minify
73+
6374
# Copy static assets
6475
RUN mkdir -p dist/static && cp -r static/* dist/static/ 2>/dev/null || true
6576

@@ -77,10 +88,16 @@ RUN apt-get update && \
7788
apt-get install -y git openssh-client && \
7889
rm -rf /var/lib/apt/lists/*
7990

80-
# Copy built artifacts from builder
81-
COPY --from=builder /app/dist ./dist
82-
COPY --from=builder /app/node_modules ./node_modules
83-
COPY --from=builder /app/package.json ./
91+
# Copy bundled server and frontend assets
92+
# Vite outputs JS/CSS/HTML directly to dist/ (assetsDir: ".")
93+
COPY --from=builder /app/dist/server-bundle.js ./dist/
94+
COPY --from=builder /app/dist/*.html ./dist/
95+
COPY --from=builder /app/dist/*.js ./dist/
96+
COPY --from=builder /app/dist/*.css ./dist/
97+
COPY --from=builder /app/dist/static ./dist/static
98+
99+
# Copy only native modules needed at runtime (node-pty for terminal support)
100+
COPY --from=builder /app/node_modules/@lydell ./node_modules/@lydell
84101

85102
# Create mux data directory
86103
RUN mkdir -p /root/.mux
@@ -96,8 +113,8 @@ EXPOSE 3000
96113
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
97114
CMD node -e "fetch('http://localhost:3000/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"
98115

99-
# Run mux server
116+
# Run bundled mux server
100117
# --host 0.0.0.0: bind to all interfaces (required for Docker networking)
101118
# --port 3000: default port (can be remapped via docker run -p)
102-
ENTRYPOINT ["node", "dist/cli/index.js", "server"]
119+
ENTRYPOINT ["node", "dist/server-bundle.js"]
103120
CMD ["--host", "0.0.0.0", "--port", "3000"]

0 commit comments

Comments
 (0)