diff --git a/apps/docker/Dockerfile b/apps/docker/Dockerfile index a866df89..b0b2205f 100644 --- a/apps/docker/Dockerfile +++ b/apps/docker/Dockerfile @@ -1,36 +1,43 @@ -FROM node:20-slim +FROM oven/bun:1-slim AS builder -# Update dependencies -RUN apt-get update +WORKDIR /app -# Install dependencies -RUN apt-get install -y \ +# Copy the monorepo source code +COPY . . + +# Install dependencies and build +RUN bun install +RUN bun run build + +FROM oven/bun:1-slim AS runner +WORKDIR /app + +# Install system dependencies that might be needed by MCP servers +RUN apt-get update && apt-get install -y \ curl \ git \ python3-pip \ - pipx + python3-venv \ + pipx \ + && rm -rf /var/lib/apt/lists/* -# Used by many MCP servers +# Install uv for Python MCP servers using pipx RUN pipx install uv - -# Add pipx bin directory to PATH so uvx is available ENV PATH="/root/.local/bin:${PATH}" -# Create director directory for volume mounting +# Create director directory RUN mkdir -p /root/.director -# Install Director CLI globally -RUN npm install -g @director.run/cli@latest +# Copy built files and dependencies from builder +COPY --from=builder /app /app -# Set default port ENV GATEWAY_PORT=8080 - -# Expose the gateway port EXPOSE ${GATEWAY_PORT} -# Create a simple healthcheck -# HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ -# CMD curl -f http://localhost:${GATEWAY_PORT}/health || exit 1 +# Create a wrapper script for the director executable +RUN echo '#!/bin/sh' > /usr/local/bin/director && \ + echo 'exec bun run /app/apps/cli/bin/cli.ts "$@"' >> /usr/local/bin/director && \ + chmod +x /usr/local/bin/director -# Run director serve -CMD ["sh", "-c", "director serve"] \ No newline at end of file +# Run the gateway server +CMD ["bun", "run", "/app/apps/gateway/bin/server.ts"] \ No newline at end of file diff --git a/apps/gateway/src/auth.ts b/apps/gateway/src/auth.ts index 1596bd84..a61e1bab 100644 --- a/apps/gateway/src/auth.ts +++ b/apps/gateway/src/auth.ts @@ -48,6 +48,14 @@ export const auth = betterAuth({ databaseHooks: { user: { create: { + before: async (user) => { + if (env.DISABLE_SIGNUPS) { + throw new Error("Signups are disabled on this instance"); + } + return { + data: user, + }; + }, after: async (user) => { // Create a default API key for the new user and store encrypted try { diff --git a/apps/gateway/src/env.ts b/apps/gateway/src/env.ts index fd52f747..f62ff73c 100644 --- a/apps/gateway/src/env.ts +++ b/apps/gateway/src/env.ts @@ -62,6 +62,10 @@ export const env = createEnv({ .string() .default("false") .transform((s) => s === "true"), + DISABLE_SIGNUPS: z + .string() + .default("false") + .transform((s) => s === "true"), // API key rate limiting configuration API_KEY_RATE_LIMIT_WINDOW_SECONDS: z .string() diff --git a/apps/gateway/src/routers/trpc/index.ts b/apps/gateway/src/routers/trpc/index.ts index 416ffd2d..1467c4f0 100644 --- a/apps/gateway/src/routers/trpc/index.ts +++ b/apps/gateway/src/routers/trpc/index.ts @@ -55,6 +55,10 @@ export function createAppRouter() { store: createPlaybookStoreRouter(), tools: createToolsRouter(), settings: createSettingsRouter(), + authCheck: publicProcedure.query(({ ctx }) => { + const context = ctx as GatewayContext; + return { userId: context.userId, headers: "Check console" }; + }), }); } @@ -75,6 +79,9 @@ export function createTRPCExpressMiddleware({ headers: req.headers as Record, }); + console.log("TRPC createContext req.headers:", req.headers); + console.log("TRPC createContext session:", session); + if (session) { userId = session.user.id; // Get user status from the session user object diff --git a/packages/utilities/src/logger.ts b/packages/utilities/src/logger.ts index 48d49c98..323fe8a9 100644 --- a/packages/utilities/src/logger.ts +++ b/packages/utilities/src/logger.ts @@ -10,6 +10,17 @@ const LOG_ERROR_STACK = process.env.LOG_ERROR_STACK === "true"; export type Logger = pino.Logger; +const stream = LOG_PRETTY + ? pinoPretty({ + colorize: true, + translateTime: "HH:MM:ss", + ignore: "pid,hostname", + destination: 2, + // uncomment to hide json objects for any level other than trace or debug + // hideObject: !["trace", "debug"].includes(LOG_LEVEL.toLowerCase()), + }) + : pino.destination(2); + const logger = pino( { level: LOG_LEVEL.toLowerCase(), @@ -39,15 +50,7 @@ const logger = pino( }, }, }, - LOG_PRETTY - ? pinoPretty({ - colorize: true, - translateTime: "HH:MM:ss", - ignore: "pid,hostname", - // uncomment to hide json objects for any level other than trace or debug - // hideObject: !["trace", "debug"].includes(LOG_LEVEL.toLowerCase()), - }) - : undefined, + stream ); export const getLogger = (name: string): Logger => logger.child({ name });