legends810 commited on
Commit
bc5b725
Β·
verified Β·
1 Parent(s): dcd09ca

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -54
Dockerfile CHANGED
@@ -1,88 +1,56 @@
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"]
 
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"]