Spaces:
Runtime error
Runtime error
| # Use official n8n Docker image instead of building from scratch | |
| FROM docker.n8n.io/n8nio/n8n:latest | |
| # Switch to root for configuration | |
| USER root | |
| # Install additional tools for Hugging Face Spaces | |
| RUN apk add --no-cache curl bash | |
| # Hugging Face Spaces specific settings | |
| ENV N8N_PORT=7860 | |
| ENV N8N_HOST=0.0.0.0 | |
| ENV N8N_PROTOCOL=https | |
| # Database configuration - Using SQLite for HF Spaces compatibility | |
| ENV DB_TYPE=sqlite | |
| ENV DB_SQLITE_DATABASE=/home/node/.n8n/database.sqlite | |
| # Community packages enable ΰ€ΰ€°ΰ₯ΰ€ | |
| ENV N8N_COMMUNITY_PACKAGES_ENABLED=true | |
| ENV N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true | |
| # MOST IMPORTANT: gzip compression disable ΰ€ΰ€°ΰ₯ΰ€ (ΰ€ΰ€ͺΰ€ΰ₯ main problem ΰ€ΰ€Ύ solution) | |
| ENV COMPRESSION_ENABLED=false | |
| ENV N8N_DISABLE_GZIP=true | |
| ENV N8N_DISABLE_PRODUCTION_MAIN_PROCESS_RESPONSE_COMPRESSION=true | |
| ENV DISABLE_COMPRESSION=true | |
| ENV NODE_OPTIONS="--max-old-space-size=4096" | |
| # NO AUTHENTICATION | |
| ENV N8N_BASIC_AUTH_ACTIVE=false | |
| ENV N8N_USER_MANAGEMENT_DISABLED=true | |
| # File permissions ΰ€ΰ€° encryption key settings | |
| ENV N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=false | |
| # Performance settings | |
| ENV N8N_LOG_LEVEL=info | |
| # Switch to node user and create directories | |
| USER node | |
| # Create user directories with proper permissions | |
| RUN mkdir -p /home/node/.n8n/database /home/node/.n8n/config /home/node/.n8n/workflows /home/node/.n8n/logs | |
| # Switch back to root for script creation | |
| USER root | |
| # Create startup script with URL display | |
| RUN echo '#!/bin/bash' > /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo 'echo "π ===== n8n Starting on Hugging Face Spaces ====="' >> /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo '# Dynamic URL detection' >> /start.sh && \ | |
| echo 'if [ -n "$SPACE_ID" ]; then' >> /start.sh && \ | |
| echo ' APP_URL="https://$SPACE_ID.hf.space"' >> /start.sh && \ | |
| echo 'elif [ -n "$SPACE_HOST" ]; then' >> /start.sh && \ | |
| echo ' APP_URL="https://$SPACE_HOST"' >> /start.sh && \ | |
| echo 'else' >> /start.sh && \ | |
| echo ' APP_URL="http://localhost:7860"' >> /start.sh && \ | |
| echo 'fi' >> /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo '# Set dynamic URLs' >> /start.sh && \ | |
| echo 'export N8N_BASE_URL="$APP_URL/"' >> /start.sh && \ | |
| echo 'export WEBHOOK_URL="$APP_URL/"' >> /start.sh && \ | |
| echo 'export N8N_EDITOR_BASE_URL="$APP_URL"' >> /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo 'echo "π n8n will be available at: $APP_URL"' >> /start.sh && \ | |
| echo 'echo "π Configuration:"' >> /start.sh && \ | |
| echo 'echo " - Port: $N8N_PORT"' >> /start.sh && \ | |
| echo 'echo " - Database: SQLite (local)"' >> /start.sh && \ | |
| echo 'echo " - Compression: DISABLED β "' >> /start.sh && \ | |
| echo 'echo " - Community Packages: ENABLED β "' >> /start.sh && \ | |
| echo 'echo " - Authentication: DISABLED β "' >> /start.sh && \ | |
| echo 'echo ""' >> /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo 'echo "π― Starting n8n server..."' >> /start.sh && \ | |
| echo '' >> /start.sh && \ | |
| echo '# Start n8n with proper user' >> /start.sh && \ | |
| echo 'su node -c "n8n start"' >> /start.sh | |
| # Make script executable | |
| RUN chmod +x /start.sh | |
| # Set working directory | |
| WORKDIR /home/node | |
| # Expose port for Hugging Face Spaces | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \ | |
| CMD curl -f http://localhost:7860/healthz || curl -f http://localhost:7860/ || exit 1 | |
| # Use custom startup script | |
| CMD ["/start.sh"] |