Update Dockerfile

rolled back to original
This commit is contained in:
moonwalk
2025-07-16 13:03:11 +02:00
committed by GitHub
parent 4366cde528
commit 3efd28d3ff

View File

@@ -1,67 +1,78 @@
# syntax=docker/dockerfile:1.7 # syntax=docker/dockerfile:1.7
# Ultra-optimized Dockerfile - minimal runtime dependencies (no n8n packages)
# Stage 1: Builder (TypeScript compilation only)
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Install build dependencies for native modules # Copy tsconfig for TypeScript compilation
RUN apk add --no-cache python3 make g++ COPY tsconfig.json ./
# Copy package files and tsconfig # Create minimal package.json and install ONLY build dependencies
COPY package*.json tsconfig.json ./ RUN --mount=type=cache,target=/root/.npm \
echo '{}' > package.json && \
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
# Install all dependencies for building (including devDependencies) # Copy source and build
RUN npm ci --no-audit --no-fund
# Copy source code
COPY src ./src COPY src ./src
# Note: src/n8n contains TypeScript types needed for compilation
# These will be compiled but not included in runtime
RUN npx tsc
# Build the app (transpile TypeScript) # Stage 2: Runtime (minimal dependencies)
RUN npm run build
# --- Final minimal image ---
FROM node:20-alpine AS runtime FROM node:20-alpine AS runtime
WORKDIR /app WORKDIR /app
# Install runtime-only OS deps # Install only essential runtime tools
RUN apk add --no-cache curl && \ RUN apk add --no-cache curl && \
rm -rf /var/cache/apk/* rm -rf /var/cache/apk/*
# Copy only the prod package.json (edit as needed for your setup) # Copy runtime-only package.json
COPY package*.json ./ COPY package.runtime.json package.json
# Install *production* node_modules only # Install runtime dependencies with cache mount
RUN npm ci --only=production --no-audit --no-fund RUN --mount=type=cache,target=/root/.npm \
npm install --production --no-audit --no-fund
# Copy built files from builder # Copy built application
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
# Copy assets, configs, and needed files # Copy pre-built database and required files
COPY data/ ./data/ # Cache bust: 2025-07-06-trigger-fix-v3 - includes is_trigger=true for webhook,cron,interval,emailReadImap
COPY data/nodes.db ./data/
COPY src/database/schema-optimized.sql ./src/database/ COPY src/database/schema-optimized.sql ./src/database/
COPY .env.example ./ COPY .env.example ./
# Entrypoint script if you use one: # Copy entrypoint script
# COPY docker/docker-entrypoint.sh /usr/local/bin/ COPY docker/docker-entrypoint.sh /usr/local/bin/
# RUN chmod +x /usr/local/bin/docker-entrypoint.sh RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Metadata # Add container 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" LABEL org.opencontainers.image.description="n8n MCP Server - Runtime Only"
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"
# Non-root user (optional, best practice) # Create non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001 && chown -R nodejs:nodejs /app RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs USER nodejs
# Env # Set Docker environment flag
ENV NODE_ENV=production
ENV IS_DOCKER=true ENV IS_DOCKER=true
# Expose HTTP port
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:3000/health || exit 1 CMD curl -f http://127.0.0.1:3000/health || exit 1
# Optimized entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["node", "dist/mcp/index.js"] CMD ["node", "dist/mcp/index.js"]