Update Dockerfile
This commit is contained in:
58
Dockerfile
58
Dockerfile
@@ -1,50 +1,78 @@
|
|||||||
# syntax=docker/dockerfile:1.7
|
# syntax=docker/dockerfile:1.7
|
||||||
# Ultra-optimized Dockerfile for Railway deployment of n8n-mcp
|
# Railway-compatible Dockerfile for n8n-mcp
|
||||||
|
|
||||||
# --- Stage 1: Builder ---
|
# --- Stage 1: Builder ---
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY tsconfig.json ./
|
# Install system dependencies for native modules
|
||||||
RUN --mount=type=cache,id=npm-cache-builder \
|
RUN apk add --no-cache python3 make g++ && \
|
||||||
echo '{}' > package.json && \
|
rm -rf /var/cache/apk/*
|
||||||
npm install --no-save typescript@^5.8.3 @types/node@^22.15.30 @types/express@^5.0.3 \
|
|
||||||
@modelcontextprotocol/sdk@^1.12.1 dotenv@^16.5.0 express@^5.1.0 axios@^1.10.0 \
|
|
||||||
n8n-workflow@^1.96.0 uuid@^11.0.5 @types/uuid@^10.0.0
|
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json tsconfig.json ./
|
||||||
|
|
||||||
|
# Install all dependencies (including devDependencies for build)
|
||||||
|
RUN npm ci --no-audit --no-fund
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
RUN npx tsc
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
# --- Stage 2: Runtime ---
|
# --- Stage 2: Runtime ---
|
||||||
FROM node:20-alpine AS runtime
|
FROM node:20-alpine AS runtime
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache curl && rm -rf /var/cache/apk/*
|
# Install system dependencies
|
||||||
|
RUN apk add --no-cache curl python3 make g++ && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
COPY package.runtime.json package.json
|
# Copy package files
|
||||||
RUN --mount=type=cache,id=npm-cache-runtime \
|
COPY package*.json ./
|
||||||
npm install --production --no-audit --no-fund
|
|
||||||
|
|
||||||
|
# Install only production dependencies
|
||||||
|
RUN npm ci --only=production --no-audit --no-fund && \
|
||||||
|
npm cache clean --force
|
||||||
|
|
||||||
|
# Copy built application from builder stage
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY data/nodes.db ./data/
|
|
||||||
COPY src/database/schema-optimized.sql ./src/database/
|
# Copy necessary data and configuration files
|
||||||
|
COPY data/ ./data/
|
||||||
|
COPY src/database/schema-optimized.sql ./src/database/schema-optimized.sql
|
||||||
COPY .env.example ./
|
COPY .env.example ./
|
||||||
|
|
||||||
|
# Create data directory if it doesn't exist and set permissions
|
||||||
|
RUN mkdir -p ./data && \
|
||||||
|
chmod 755 ./data
|
||||||
|
|
||||||
|
# Add metadata labels
|
||||||
LABEL org.opencontainers.image.source="https://github.com/czlonkowski/n8n-mcp"
|
LABEL org.opencontainers.image.source="https://github.com/czlonkowski/n8n-mcp"
|
||||||
LABEL org.opencontainers.image.description="n8n MCP Server - Runtime Only"
|
LABEL org.opencontainers.image.description="n8n MCP Server - Integration between n8n workflow automation and Model Context Protocol"
|
||||||
LABEL org.opencontainers.image.licenses="MIT"
|
LABEL org.opencontainers.image.licenses="MIT"
|
||||||
LABEL org.opencontainers.image.title="n8n-mcp"
|
LABEL org.opencontainers.image.title="n8n-mcp"
|
||||||
|
LABEL org.opencontainers.image.version="2.7.13"
|
||||||
|
|
||||||
|
# Create non-root user for security
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
RUN addgroup -g 1001 -S nodejs && \
|
||||||
adduser -S nodejs -u 1001 && \
|
adduser -S nodejs -u 1001 && \
|
||||||
chown -R nodejs:nodejs /app
|
chown -R nodejs:nodejs /app
|
||||||
USER nodejs
|
USER nodejs
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
ENV NODE_ENV=production
|
||||||
ENV IS_DOCKER=true
|
ENV IS_DOCKER=true
|
||||||
|
ENV MCP_MODE=http
|
||||||
|
ENV USE_FIXED_HTTP=true
|
||||||
|
|
||||||
|
# Expose port (Railway will set PORT automatically)
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
CMD curl -f http://127.0.0.1:${PORT:-3000}/health || exit 1
|
CMD curl -f http://127.0.0.1:${PORT:-3000}/health || exit 1
|
||||||
|
|
||||||
|
# Start the application in HTTP mode
|
||||||
CMD ["node", "dist/mcp/index.js", "--http"]
|
CMD ["node", "dist/mcp/index.js", "--http"]
|
||||||
|
|||||||
Reference in New Issue
Block a user