Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +22 -54
Dockerfile
CHANGED
|
@@ -1,88 +1,56 @@
|
|
| 1 |
###############################################################################
|
| 2 |
-
# n8n
|
| 3 |
###############################################################################
|
| 4 |
FROM docker.n8n.io/n8nio/n8n:latest
|
| 5 |
|
| 6 |
-
# Base environment variables
|
| 7 |
ENV N8N_HOST=0.0.0.0 \
|
| 8 |
N8N_PROTOCOL=http \
|
| 9 |
DB_TYPE=sqlite \
|
| 10 |
-
DB_SQLITE_DATABASE=/home/node/.n8n/database.sqlite \
|
| 11 |
N8N_DISABLE_PRODUCTION_MAIN_PROCESS_RESPONSE_COMPRESSION=true \
|
| 12 |
N8N_DISABLE_PRODUCTION_WEBHOOK_RESPONSE_COMPRESSION=true \
|
| 13 |
-
|
| 14 |
-
N8N_USER_MANAGEMENT_DISABLED=true \
|
| 15 |
-
N8N_LOG_LEVEL=debug \
|
| 16 |
-
N8N_CUSTOM_EXTENSIONS=/home/node/n8n-custom # <-- Crucial for loading extensions
|
| 17 |
|
| 18 |
-
|
| 19 |
USER node
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
if (app?._router?.stack) {
|
| 33 |
-
const initialStackLength = app._router.stack.length;
|
| 34 |
-
app._router.stack = app._router.stack.filter(
|
| 35 |
-
(layer) => !(layer.handle && layer.handle.name === 'compression')
|
| 36 |
-
);
|
| 37 |
-
console.log(`ποΈ Removed compression middleware β’ stack ${initialStackLength} β ${app._router.stack.length}`);
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
// Globally ensure no Content-Encoding header is set and prevent proxy transformation
|
| 41 |
-
app.use((_req, res, next) => {
|
| 42 |
-
res.removeHeader('Content-Encoding');
|
| 43 |
-
res.setHeader('Cache-Control', 'no-transform'); // Important for proxies
|
| 44 |
-
next();
|
| 45 |
-
});
|
| 46 |
-
|
| 47 |
-
console.log('β
Custom extension loaded β gzip disabled globally');
|
| 48 |
-
},
|
| 49 |
};
|
|
|
|
| 50 |
JS
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
USER root
|
| 54 |
-
# Create and make the start script executable
|
| 55 |
RUN cat >/usr/local/bin/start.sh <<'SH' && chmod +x /usr/local/bin/start.sh
|
| 56 |
#!/usr/bin/env sh
|
| 57 |
set -eu
|
|
|
|
| 58 |
|
| 59 |
-
# Set the port, defaulting to 7860 if not provided by HF
|
| 60 |
-
N8N_PORT="${PORT:-7860}"
|
| 61 |
-
export N8N_PORT
|
| 62 |
-
|
| 63 |
-
# Determine the public URL for Hugging Face Spaces
|
| 64 |
if [ -n "${SPACE_ID:-}" ]; then
|
| 65 |
-
|
| 66 |
-
SPACE_SLUG=$(printf '%s' "$SPACE_ID" | tr '/_' '-')
|
| 67 |
-
APP_URL="https://${SPACE_SLUG}.hf.space"
|
| 68 |
else
|
| 69 |
-
# Fallback for local testing or environments without SPACE_ID
|
| 70 |
APP_URL="http://localhost:${N8N_PORT}"
|
| 71 |
fi
|
| 72 |
|
| 73 |
-
# Export necessary URLs for n8n
|
| 74 |
export N8N_BASE_URL="$APP_URL"
|
| 75 |
export WEBHOOK_URL="$APP_URL"
|
| 76 |
export N8N_EDITOR_BASE_URL="$APP_URL"
|
| 77 |
|
| 78 |
-
echo "π n8n starting
|
| 79 |
-
echo "ποΈ gzip disabled via N8N_CUSTOM_EXTENSIONS" # Log indicating the method used
|
| 80 |
exec n8n start
|
| 81 |
SH
|
| 82 |
|
| 83 |
-
# Expose the default n8n port
|
| 84 |
EXPOSE 7860
|
| 85 |
-
|
| 86 |
-
# Set the entrypoint and default command
|
| 87 |
ENTRYPOINT ["tini", "--"]
|
| 88 |
CMD ["start.sh"]
|
|
|
|
| 1 |
###############################################################################
|
| 2 |
+
# n8n for Hugging-Face Spaces β FORCE DISABLE GZIP (no external deps)
|
| 3 |
###############################################################################
|
| 4 |
FROM docker.n8n.io/n8nio/n8n:latest
|
| 5 |
|
|
|
|
| 6 |
ENV N8N_HOST=0.0.0.0 \
|
| 7 |
N8N_PROTOCOL=http \
|
| 8 |
DB_TYPE=sqlite \
|
|
|
|
| 9 |
N8N_DISABLE_PRODUCTION_MAIN_PROCESS_RESPONSE_COMPRESSION=true \
|
| 10 |
N8N_DISABLE_PRODUCTION_WEBHOOK_RESPONSE_COMPRESSION=true \
|
| 11 |
+
N8N_LOG_LEVEL=debug
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
################# 1βββpreload script: stub compression() #######################
|
| 14 |
USER node
|
| 15 |
+
RUN cat >/home/node/disable-gzip-preload.js <<'JS'
|
| 16 |
+
/**
|
| 17 |
+
* When any module does require('compression')
|
| 18 |
+
* we return a dummy middleware that just calls next().
|
| 19 |
+
*/
|
| 20 |
+
const Module = require('module');
|
| 21 |
+
const realLoad = Module._load;
|
| 22 |
+
Module._load = function (request, parent, isMain) {
|
| 23 |
+
if (request === 'compression') {
|
| 24 |
+
return () => (_req, _res, next) => next();
|
| 25 |
+
}
|
| 26 |
+
return realLoad.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
};
|
| 28 |
+
console.log('ποΈ compression module stubbed β gzip disabled');
|
| 29 |
JS
|
| 30 |
|
| 31 |
+
ENV NODE_OPTIONS="--require=/home/node/disable-gzip-preload.js"
|
| 32 |
+
|
| 33 |
+
################# 2βββstart script: build HF public URL ########################
|
| 34 |
USER root
|
|
|
|
| 35 |
RUN cat >/usr/local/bin/start.sh <<'SH' && chmod +x /usr/local/bin/start.sh
|
| 36 |
#!/usr/bin/env sh
|
| 37 |
set -eu
|
| 38 |
+
export N8N_PORT="${PORT:-7860}"
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if [ -n "${SPACE_ID:-}" ]; then
|
| 41 |
+
APP_URL="https://$(echo "$SPACE_ID" | tr '/_' '-').hf.space"
|
|
|
|
|
|
|
| 42 |
else
|
|
|
|
| 43 |
APP_URL="http://localhost:${N8N_PORT}"
|
| 44 |
fi
|
| 45 |
|
|
|
|
| 46 |
export N8N_BASE_URL="$APP_URL"
|
| 47 |
export WEBHOOK_URL="$APP_URL"
|
| 48 |
export N8N_EDITOR_BASE_URL="$APP_URL"
|
| 49 |
|
| 50 |
+
echo "π n8n starting on $N8N_PORT β’ Public URL: $APP_URL"
|
|
|
|
| 51 |
exec n8n start
|
| 52 |
SH
|
| 53 |
|
|
|
|
| 54 |
EXPOSE 7860
|
|
|
|
|
|
|
| 55 |
ENTRYPOINT ["tini", "--"]
|
| 56 |
CMD ["start.sh"]
|