# Penpot MCP Server - Multi-stage build for monorepo
FROM node:20-slim AS builder

WORKDIR /app

# Copy the entire monorepo
COPY package*.json ./
COPY common ./common
COPY mcp-server ./mcp-server
COPY penpot-plugin ./penpot-plugin

# Install dependencies for the monorepo
RUN npm ci

# Build common package first (dependency)
WORKDIR /app/common
RUN npm ci && npm run build

# Build mcp-server
WORKDIR /app/mcp-server
RUN npm ci && npm run build

# Production image
FROM node:20-slim

WORKDIR /app

# Copy built mcp-server and its dependencies
COPY --from=builder /app/mcp-server/dist ./dist
COPY --from=builder /app/mcp-server/data ./data
COPY --from=builder /app/mcp-server/node_modules ./node_modules
COPY --from=builder /app/common/dist ./node_modules/@penpot-mcp/common/dist
COPY --from=builder /app/common/package.json ./node_modules/@penpot-mcp/common/

# Set environment defaults
ENV PENPOT_URL=${PENPOT_URL:-https://design.penpot.app}

# Run the MCP server
CMD ["node", "dist/index.js"]
