|
1 | | -# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile |
2 | | -FROM node:18-alpine AS release |
| 1 | +# Multi-stage build for optimized production image |
| 2 | +FROM node:18-alpine AS builder |
3 | 3 |
|
4 | | -# Create app directory |
| 4 | +# Set working directory |
5 | 5 | WORKDIR /app |
6 | 6 |
|
7 | | -# Copy package files |
8 | | -COPY package*.json tsconfig.json ./ |
| 7 | +# Copy package files for dependency installation |
| 8 | +COPY package.json package-lock.json ./ |
| 9 | + |
| 10 | +# Install dependencies with cache optimization |
| 11 | +RUN --mount=type=cache,target=/root/.npm \ |
| 12 | + npm ci |
| 13 | + |
| 14 | +# Copy TypeScript configuration and source code |
| 15 | +COPY tsconfig.json ./ |
| 16 | +COPY src ./src |
| 17 | + |
| 18 | +# Build the project |
| 19 | +RUN npm run build |
9 | 20 |
|
10 | | -# Install dependencies with caching |
11 | | -RUN --mount=type=cache,target=/root/.npm npm install |
| 21 | +# Production stage with minimal dependencies |
| 22 | +FROM node:18-alpine AS production |
12 | 23 |
|
13 | | -# Copy the rest of the project source |
14 | | -COPY . . |
| 24 | +# Set working directory |
| 25 | +WORKDIR /app |
15 | 26 |
|
16 | 27 | # Set production environment |
17 | 28 | ENV NODE_ENV=production |
18 | 29 |
|
19 | | -# Build the project |
20 | | -RUN npm run build |
| 30 | +# Copy package files |
| 31 | +COPY package.json package-lock.json ./ |
| 32 | + |
| 33 | +# Install production dependencies only |
| 34 | +RUN --mount=type=cache,target=/root/.npm \ |
| 35 | + npm ci --omit=dev |
| 36 | + |
| 37 | +# Copy built application from builder stage |
| 38 | +COPY --from=builder /app/build ./build |
21 | 39 |
|
22 | | -# Set the user to non-root |
23 | | -USER node |
| 40 | +# Create a non-root user to run the app |
| 41 | +RUN addgroup -g 1001 -S nodejs && \ |
| 42 | + adduser -S nodejs -u 1001 -G nodejs |
24 | 43 |
|
25 | | -# Expose WebSocket port, default 8090 |
| 44 | +# Set ownership to the non-root user |
| 45 | +RUN chown -R nodejs:nodejs /app |
| 46 | + |
| 47 | +# Switch to non-root user |
| 48 | +USER nodejs |
| 49 | + |
| 50 | +# Expose WebSocket port |
26 | 51 | EXPOSE 8090 |
27 | 52 |
|
28 | | -# Command to run the MCP server. Use ENTRYPOINT instead of CMD for better compatibility |
| 53 | +# Health check to ensure the application is running |
| 54 | +HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ |
| 55 | + CMD wget --no-verbose --tries=1 --spider http://localhost:8090/health || exit 1 |
| 56 | + |
| 57 | +# Command to run the MCP server |
29 | 58 | ENTRYPOINT ["node", "build/index.js"] |
0 commit comments