stack/docker/server/Dockerfile
Moritz Schneider ab81ad14e1
Implement Model Context Protocol server poc (#552)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Introduces a new Model Context Protocol server with OpenAPI
integration, updates build configurations, and adds necessary files for
initial release.
> 
>   - **New MCP Server**:
> - Implements MCP server in `src/index.ts` using
`@modelcontextprotocol/sdk`.
> - Handles tool requests with `ListToolsRequestSchema` and
`CallToolRequestSchema`.
>     - Supports 40 endpoints, defined in `operationIDs`.
>   - **OpenAPI Integration**:
> - Generates OpenAPI schema in `generate-openapi.ts` and writes to
`mcp-server/openapi`.
> - Converts OpenAPI parameters to JSON schema in
`openapi-to-jsonschema.ts`.
>   - **Configuration and Build**:
> - Adds `package.json` for MCP server with dependencies and scripts.
>     - Configures ESLint in `.eslintrc.cjs`.
> - Updates `Dockerfile` and `turbo.json` to include MCP server in build
process.
>   - **Miscellaneous**:
>     - Adds `.gitignore` for OpenAPI JSON files.
>     - Initial release noted in `CHANGELOG.md`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for d0970c4059. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-03-19 18:49:39 +00:00

99 lines
2.7 KiB
Docker

ARG NODE_VERSION=22.9.0
# Base
FROM node:${NODE_VERSION} AS base
WORKDIR /app
RUN apt-get update && \
apt-get upgrade -y && \
rm -rf /var/lib/apt/lists
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
RUN corepack enable
RUN corepack prepare pnpm@10.0.0 --activate
RUN pnpm add -g turbo
RUN pnpm add -g tsx
# Prune stage
FROM base AS pruner
COPY . .
RUN tsx ./scripts/generate-sdks.ts
# https://turbo.build/repo/docs/guides/tools/docker
RUN turbo prune --scope=@stackframe/stack-backend --scope=@stackframe/stack-dashboard --scope=@stackframe/mcp-server --docker
# Build stage
FROM base AS builder
# copy over package.json files and install dependencies
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml .
COPY .gitignore .
COPY pnpm-workspace.yaml .
COPY turbo.json .
RUN cat ./pnpm-lock.yaml
RUN --mount=type=cache,id=pnpm,target=/pnpm/store STACK_SKIP_TEMPLATE_GENERATION=true pnpm install --frozen-lockfile
# copy over the rest of the code for the build
COPY --from=pruner /app/out/full/ .
# docs are currently required for the NextJS backend build, but won't exist in the final image
COPY docs ./docs
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV NEXT_CONFIG_OUTPUT=standalone
# Build the backend NextJS app
RUN pnpm turbo run docker-build --filter=@stackframe/stack-backend... --filter=@stackframe/stack-dashboard...
# Build the self-host seed script
RUN cd apps/backend && pnpm build-self-host-seed-script
# Final image
FROM node:${NODE_VERSION}-slim
WORKDIR /app
# Install packages needed for deployment
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y openssl socat && \
rm -rf /var/lib/apt/lists
# Install Prisma CLI globally so we can run migrations on startup
RUN npm i -g prisma
# Copy built backend
COPY --from=builder --chown=node:node /app/apps/backend/.next/standalone ./
COPY --from=builder --chown=node:node /app/apps/backend/.next/static ./apps/backend/.next/static
COPY --from=builder --chown=node:node /app/apps/backend/prisma ./apps/backend/prisma
COPY --from=builder --chown=node:node /app/apps/backend/dist/seed.js ./apps/backend
# Copy built dashboard
COPY --from=builder --chown=node:node /app/apps/dashboard/.next/standalone ./
COPY --from=builder --chown=node:node /app/apps/dashboard/.next/static ./apps/dashboard/.next/static
COPY --from=builder --chown=node:node /app/apps/dashboard/public ./apps/dashboard/public
# Add the entrypoint script
COPY ./docker/server/entrypoint.sh .
RUN chmod +x entrypoint.sh
WORKDIR /app
# Define environment variables for both services
ENV NODE_ENV=production
ENV BACKEND_PORT=8102
ENV DASHBOARD_PORT=8101
USER node
# Set entrypoint to run both backend and dashboard
ENTRYPOINT ["./entrypoint.sh"]