Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +56 -13
Dockerfile
CHANGED
|
@@ -1,45 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM docker.n8n.io/n8nio/n8n:latest
|
| 2 |
|
|
|
|
| 3 |
ENV N8N_HOST=0.0.0.0 \
|
| 4 |
N8N_PROTOCOL=http \
|
| 5 |
DB_TYPE=sqlite \
|
|
|
|
| 6 |
N8N_DISABLE_PRODUCTION_MAIN_PROCESS_RESPONSE_COMPRESSION=true \
|
| 7 |
N8N_DISABLE_PRODUCTION_WEBHOOK_RESPONSE_COMPRESSION=true \
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
USER node
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
Module._cache[require.resolve('compression')]={exports:()=>(_req,_res,next)=>next()};\
|
| 15 |
-
process.env.DISABLE_COMPRESSION_PATCH='loaded';" \
|
| 16 |
-
> /home/node/disable-gzip-preload.js
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
USER root
|
|
|
|
| 23 |
RUN cat >/usr/local/bin/start.sh <<'SH' && chmod +x /usr/local/bin/start.sh
|
| 24 |
#!/usr/bin/env sh
|
| 25 |
set -eu
|
| 26 |
-
export N8N_PORT="${PORT:-7860}"
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if [ -n "${SPACE_ID:-}" ]; then
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
else
|
|
|
|
| 31 |
APP_URL="http://localhost:${N8N_PORT}"
|
| 32 |
fi
|
| 33 |
|
|
|
|
| 34 |
export N8N_BASE_URL="$APP_URL"
|
| 35 |
export WEBHOOK_URL="$APP_URL"
|
| 36 |
export N8N_EDITOR_BASE_URL="$APP_URL"
|
| 37 |
|
| 38 |
echo "π n8n starting β’ public $APP_URL"
|
| 39 |
-
echo "ποΈ gzip disabled via
|
| 40 |
exec n8n start
|
| 41 |
SH
|
| 42 |
|
|
|
|
| 43 |
EXPOSE 7860
|
|
|
|
|
|
|
| 44 |
ENTRYPOINT ["tini", "--"]
|
| 45 |
CMD ["start.sh"]
|
|
|
|
| 1 |
+
###############################################################################
|
| 2 |
+
# n8n on Hugging-Face πΉ gzip compression HARD-OFF using Custom Extension
|
| 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 |
+
N8N_BASIC_AUTH_ACTIVE=false \
|
| 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 |
+
# ββββββββββββββββββββββ 1. Create Custom Extension Structure ββββββββββββββββββββββ
|
| 19 |
USER node
|
| 20 |
+
# Create the directory for custom extensions
|
| 21 |
+
RUN mkdir -p /home/node/n8n-custom/disable-gzip
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Create package.json file for the extension (n8n loader needs this)
|
| 24 |
+
RUN printf '{\n "name": "disable-gzip",\n "version": "1.0.0",\n "main": "index.js"\n}\n' \
|
| 25 |
+
> /home/node/n8n-custom/disable-gzip/package.json
|
| 26 |
|
| 27 |
+
# Create index.js file with the logic to disable compression
|
| 28 |
+
RUN cat >/home/node/n8n-custom/disable-gzip/index.js <<'JS'
|
| 29 |
+
module.exports = {
|
| 30 |
+
init(app) {
|
| 31 |
+
// Safely remove compression middleware from Express stack
|
| 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 |
+
# ββββββββββββββββββββββ 2. Configure start-script for Hugging Face Spaces ββββββββββββββββββββββ
|
| 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 |
+
# Convert "user/repo" to "user-repo.hf.space"
|
| 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 β’ public $APP_URL"
|
| 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"]
|