|
| 1 | +# Multi-stage build for mendix-widgets-mcp |
| 2 | +FROM node:22-alpine AS base |
| 3 | + |
| 4 | +# Install pnpm |
| 5 | +RUN corepack enable && corepack prepare pnpm@10.17.0 --activate |
| 6 | + |
| 7 | +# Set working directory |
| 8 | +WORKDIR /app |
| 9 | + |
| 10 | +# Stage 1: Install dependencies for the entire monorepo |
| 11 | +FROM base AS deps |
| 12 | + |
| 13 | +# Copy root package files |
| 14 | +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ |
| 15 | + |
| 16 | +# Copy pnpm configuration files (required for lockfile validation) |
| 17 | +COPY .pnpmfile.cjs .npmrc ./ |
| 18 | + |
| 19 | +# Copy patches directory (required by pnpm) |
| 20 | +COPY patches ./patches/ |
| 21 | + |
| 22 | +# Copy automation-utils dependency (complete structure) |
| 23 | +COPY automation/utils ./automation/utils/ |
| 24 | + |
| 25 | +# Copy MCP server package files |
| 26 | +COPY automation/mendix-widgets-mcp/package.json ./automation/mendix-widgets-mcp/ |
| 27 | + |
| 28 | +# Install all dependencies (ignore scripts to skip postinstall) |
| 29 | +RUN pnpm install --frozen-lockfile --filter @mendix/mendix-widgets-mcp... --ignore-scripts |
| 30 | + |
| 31 | +# Stage 2: Build the MCP server |
| 32 | +FROM deps AS builder |
| 33 | + |
| 34 | +# Copy entire automation directory |
| 35 | +COPY automation ./automation/ |
| 36 | + |
| 37 | +# Copy docs and packages directories (needed by MCP server at runtime) |
| 38 | +COPY docs ./docs/ |
| 39 | +COPY packages ./packages/ |
| 40 | + |
| 41 | +# Build the MCP server |
| 42 | +WORKDIR /app/automation/mendix-widgets-mcp |
| 43 | +RUN pnpm build |
| 44 | + |
| 45 | +# Stage 3: Production image |
| 46 | +FROM base AS runner |
| 47 | + |
| 48 | +# Copy root configuration files |
| 49 | +COPY --from=builder /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/ |
| 50 | +COPY --from=builder /app/.pnpmfile.cjs /app/.npmrc /app/ |
| 51 | + |
| 52 | +# Copy monorepo directories that MCP server needs to access |
| 53 | +COPY --from=builder /app/patches /app/patches/ |
| 54 | +COPY --from=builder /app/automation /app/automation/ |
| 55 | +COPY --from=builder /app/docs /app/docs/ |
| 56 | +COPY --from=builder /app/packages /app/packages/ |
| 57 | + |
| 58 | +# Install only production dependencies (ignore scripts to skip postinstall) |
| 59 | +WORKDIR /app |
| 60 | +RUN pnpm install --frozen-lockfile --filter @mendix/mendix-widgets-mcp... --prod --ignore-scripts |
| 61 | + |
| 62 | +# Environment variables |
| 63 | +ENV NODE_ENV=production |
| 64 | +ENV MX_PROJECT_PATH="" |
| 65 | +ENV REPO_ROOT=/app |
| 66 | + |
| 67 | +# Set working directory to app root |
| 68 | +# When running with volume mounts, REPO_ROOT will be overridden to /workspace |
| 69 | +WORKDIR /app |
| 70 | + |
| 71 | +# Run the MCP server |
| 72 | +# The server binary is at /app/automation/mendix-widgets-mcp/build/index.js |
| 73 | +# It will access repository files from REPO_ROOT (either /app or /workspace) |
| 74 | +CMD ["node", "/app/automation/mendix-widgets-mcp/build/index.js"] |
0 commit comments