Merge pull request #9 from brave/dockerize-app

dockerize application
This commit is contained in:
Sampson authored and GitHub committed 2025-06-25 15:57:42 -05:00
commit bde68396e8
3 files changed
+40 -14

No files matched your search

+14 -8
View File
@@ -1,14 +1,18 @@
FROM node:22.16-alpine AS builder
# Must be entire project because `prepare` script is run during `npm install` and requires all files.
COPY src/ /app/src
COPY tsconfig.json /tsconfig.json
FROM node:22.16.0-bookworm-slim@sha256:048ed02c5fd52e86fda6fbd2f6a76cf0d4492fd6c6fee9e2c463ed5108da0e34 AS builder
WORKDIR /app
RUN --mount=type=cache,target=/root/.npm npm install
COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json
FROM node:22-alpine AS release
RUN npm ci --ignore-scripts
COPY ./src ./src
COPY ./tsconfig.json ./tsconfig.json
RUN npm run build
FROM node:22.16.0-bookworm-slim@sha256:048ed02c5fd52e86fda6fbd2f6a76cf0d4492fd6c6fee9e2c463ed5108da0e34 AS release
WORKDIR /app
@@ -20,4 +24,6 @@ ENV NODE_ENV=production
RUN npm ci --ignore-scripts --omit-dev
ENTRYPOINT ["node", "dist/index.js"]
USER node
CMD ["node", "dist/index.js"]
+19
View File
@@ -0,0 +1,19 @@
services:
mcp-server:
build: .
cap_drop:
- all
deploy:
restart_policy:
condition: any
delay: 5s
environment:
- BRAVE_API_KEY
- BRAVE_MCP_TRANSPORT=http
- BRAVE_MCP_PORT=8080
- BRAVE_MCP_HOST=0.0.0.0
init: true
ports:
- 8080:8080
security_opt:
- no-new-privileges:true
+7 -6
View File
@@ -19,14 +19,15 @@ if (!BRAVE_API_KEY) {
}
const program = new Command()
.option("--transport <stdio|http>", "transport type", "http")
.option("--port <number>", "desired port for HTTP transport", "3000")
.option("--transport <stdio|http>", "transport type", process.env.BRAVE_MCP_TRANSPORT ?? "stdio")
.option("--port <number>", "desired port for HTTP transport", process.env.BRAVE_MCP_PORT ?? "3000")
.option("--host <string>", "host address to bind to for HTTP transport", process.env.BRAVE_MCP_HOST ?? "0.0.0.0")
.allowUnknownOption()
.parse(process.argv);
const TRANSPORT_TYPES = ["stdio", "http"] as const;
const CLI_OPTIONS = program.opts<{ transport: "stdio" | "http"; port: string }>();
const CLI_OPTIONS = program.opts<{ transport: "stdio" | "http"; port: string; host: string }>();
if (!TRANSPORT_TYPES.includes(CLI_OPTIONS.transport)) {
console.error(`Invalid --transport value: '${CLI_OPTIONS.transport}'. Must be one of: ${TRANSPORT_TYPES.join(", ")}.`);
@@ -83,7 +84,7 @@ async function getHttpTransportForRequest(req: Request, transports: Map<string,
throw new Error('Invalid request - no session ID or not initialization request');
}
function startHttpServer(port: string, transports: Map<string, StreamableHTTPServerTransport>) {
function startHttpServer(port: string, host: string, transports: Map<string, StreamableHTTPServerTransport>) {
const app = express();
app.use(express.json());
@@ -102,7 +103,7 @@ function startHttpServer(port: string, transports: Map<string, StreamableHTTPSer
}
});
app.listen(port, () => console.error(`Server is running on http://localhost:${port}/mcp`));
app.listen(parseInt(port), host, () => console.error(`Server is running on http://${host}:${port}/mcp`));
}
async function startStdioServer() {
@@ -127,7 +128,7 @@ function main() {
const transports = new Map<string, StreamableHTTPServerTransport>();
if (CLI_OPTIONS.transport === "http") {
startHttpServer(CLI_OPTIONS.port, transports);
startHttpServer(CLI_OPTIONS.port, CLI_OPTIONS.host, transports);
} else {
startStdioServer();
}