|
| 1 | +# mux server Docker image |
| 2 | +# Multi-stage build for minimal runtime image size |
| 3 | +# |
| 4 | +# Build: docker build -t mux-server . |
| 5 | +# Run: docker run -p 3000:3000 -v ~/.mux:/root/.mux mux-server |
| 6 | +# |
| 7 | +# See docker-compose.yml for easier orchestration |
| 8 | + |
| 9 | +# ============================================================================== |
| 10 | +# Stage 1: Build |
| 11 | +# ============================================================================== |
| 12 | +FROM node:22-slim AS builder |
| 13 | + |
| 14 | +WORKDIR /app |
| 15 | + |
| 16 | +# Install bun (used for package management and build tooling) |
| 17 | +RUN npm install -g bun@1.2 |
| 18 | + |
| 19 | +# Install git (needed for version generation) |
| 20 | +RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* |
| 21 | + |
| 22 | +# Copy package files first for better layer caching |
| 23 | +COPY package.json bun.lock bunfig.toml ./ |
| 24 | + |
| 25 | +# Copy postinstall script (needed by bun install) |
| 26 | +COPY scripts/postinstall.sh scripts/ |
| 27 | + |
| 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 |
| 33 | +RUN bun install --frozen-lockfile |
| 34 | + |
| 35 | +# Copy source files needed for build |
| 36 | +COPY src/ src/ |
| 37 | +COPY tsconfig.json tsconfig.main.json ./ |
| 38 | +COPY scripts/generate-version.sh scripts/ |
| 39 | +COPY index.html terminal.html vite.config.ts ./ |
| 40 | +COPY public/ public/ |
| 41 | +COPY static/ static/ |
| 42 | + |
| 43 | +# Remove test files (they import from tests/ which is outside rootDir) |
| 44 | +RUN find src -name '*.test.ts' -delete |
| 45 | + |
| 46 | +# Initialize git for version script (uses placeholder if not a real repo) |
| 47 | +RUN git init && \ |
| 48 | + git config user.email "docker@build" && \ |
| 49 | + git config user.name "Docker Build" && \ |
| 50 | + git add -A && \ |
| 51 | + git commit -m "docker build" --allow-empty || true |
| 52 | + |
| 53 | +# Generate version info |
| 54 | +RUN ./scripts/generate-version.sh |
| 55 | + |
| 56 | +# Build main process (server + backend) |
| 57 | +RUN NODE_ENV=production bun x tsc -p tsconfig.main.json && \ |
| 58 | + NODE_ENV=production bun x tsc-alias -p tsconfig.main.json |
| 59 | + |
| 60 | +# Build renderer (frontend) |
| 61 | +RUN bun x vite build |
| 62 | + |
| 63 | +# Copy static assets |
| 64 | +RUN mkdir -p dist/static && cp -r static/* dist/static/ 2>/dev/null || true |
| 65 | + |
| 66 | +# ============================================================================== |
| 67 | +# Stage 2: Runtime |
| 68 | +# ============================================================================== |
| 69 | +FROM node:22-slim |
| 70 | + |
| 71 | +WORKDIR /app |
| 72 | + |
| 73 | +# Install runtime dependencies |
| 74 | +# - git: required for workspace operations (clone, worktree, etc.) |
| 75 | +# - openssh-client: required for SSH runtime support |
| 76 | +RUN apt-get update && \ |
| 77 | + apt-get install -y git openssh-client && \ |
| 78 | + rm -rf /var/lib/apt/lists/* |
| 79 | + |
| 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 ./ |
| 84 | + |
| 85 | +# Create mux data directory |
| 86 | +RUN mkdir -p /root/.mux |
| 87 | + |
| 88 | +# Default environment variables |
| 89 | +ENV NODE_ENV=production |
| 90 | +ENV MUX_HOME=/root/.mux |
| 91 | + |
| 92 | +# Expose server port |
| 93 | +EXPOSE 3000 |
| 94 | + |
| 95 | +# Health check |
| 96 | +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
| 97 | + CMD node -e "fetch('http://localhost:3000/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))" |
| 98 | + |
| 99 | +# Run mux server |
| 100 | +# --host 0.0.0.0: bind to all interfaces (required for Docker networking) |
| 101 | +# --port 3000: default port (can be remapped via docker run -p) |
| 102 | +ENTRYPOINT ["node", "dist/cli/index.js", "server"] |
| 103 | +CMD ["--host", "0.0.0.0", "--port", "3000"] |
0 commit comments