Spaces:
Runtime error
Runtime error
File size: 3,472 Bytes
bef4e0a 9a13398 bef4e0a 9a13398 bef4e0a 9a13398 ddd4e99 9a13398 940abbb 9a13398 bef4e0a 7ed2746 bef4e0a 7ed2746 bef4e0a 7ed2746 bef4e0a 7ed2746 bef4e0a 7ed2746 bef4e0a 9a13398 bef4e0a 9a13398 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # 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"] |