legends810 commited on
Commit
8f42094
Β·
verified Β·
1 Parent(s): 08caf6b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -25
Dockerfile CHANGED
@@ -1,13 +1,13 @@
1
  ###############################################################################
2
- # n8n for HF Spaces – gzip HARD-OFF with proper custom extension packaging
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
  DB_SQLITE_DATABASE=/home/node/.n8n/database.sqlite \
10
- N8N_COMMUNITY_PACKAGES_ENABLED=true \
11
  N8N_DISABLE_PRODUCTION_MAIN_PROCESS_RESPONSE_COMPRESSION=true \
12
  N8N_DISABLE_PRODUCTION_WEBHOOK_RESPONSE_COMPRESSION=true \
13
  N8N_BASIC_AUTH_ACTIVE=false \
@@ -15,26 +15,19 @@ ENV N8N_HOST=0.0.0.0 \
15
  N8N_LOG_LEVEL=debug \
16
  N8N_CUSTOM_EXTENSIONS=/home/node/n8n-custom
17
 
18
- ###############################################################################
19
- # 1. build a proper extension package (folder + package.json + index.js)
20
- ###############################################################################
21
  USER node
22
  RUN mkdir -p /home/node/n8n-custom/disable-gzip
23
 
24
- # ---------- package.json ----------
25
- RUN cat >/home/node/n8n-custom/disable-gzip/package.json <<'JSON'
26
- {
27
- "name": "disable-gzip",
28
- "version": "1.0.0",
29
- "main": "index.js"
30
- }
31
- JSON
32
 
33
- # ---------- index.js (actual logic) ----------
34
  RUN cat >/home/node/n8n-custom/disable-gzip/index.js <<'JS'
35
  module.exports = {
36
  init(app) {
37
- // 1β€Šβ€“β€Šremove compression middleware layer if present
38
  if (app?._router?.stack) {
39
  const before = app._router.stack.length;
40
  app._router.stack = app._router.stack.filter(
@@ -43,7 +36,7 @@ module.exports = {
43
  console.log(`πŸ—œοΈ Removed compression middleware β€’ stack ${before}β†’${app._router.stack.length}`);
44
  }
45
 
46
- // 2β€Šβ€“β€Šstrip any Content-Encoding header that sneaks in
47
  app.use((_req, res, next) => {
48
  res.removeHeader('Content-Encoding');
49
  res.setHeader('Cache-Control', 'no-transform');
@@ -55,27 +48,28 @@ module.exports = {
55
  };
56
  JS
57
 
58
- ###############################################################################
59
- # 2. start-script that sets correct public URL for HF
60
- ###############################################################################
61
  USER root
62
  RUN cat >/usr/local/bin/start.sh <<'SH' && chmod +x /usr/local/bin/start.sh
63
  #!/usr/bin/env sh
64
  set -eu
 
65
  N8N_PORT="${PORT:-7860}"
66
  export N8N_PORT
67
 
 
68
  if [ -n "${SPACE_ID:-}" ]; then
69
- APP_URL="https://$(echo "$SPACE_ID" | tr '/_' '-')\.hf\.space"
 
70
  else
71
- APP_URL="https://${HOSTNAME:-localhost}:${N8N_PORT}"
72
  fi
73
 
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 on ${N8N_PORT} β€’ Public: ${APP_URL}"
79
  exec n8n start
80
  SH
81
 
 
1
  ###############################################################################
2
+ # n8n on Hugging-Face πŸ”Ή gzip compression HARD-OFF
3
  ###############################################################################
4
  FROM docker.n8n.io/n8nio/n8n:latest
5
 
6
+ # ────────────────────── base env vars ──────────────────────
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 \
 
15
  N8N_LOG_LEVEL=debug \
16
  N8N_CUSTOM_EXTENSIONS=/home/node/n8n-custom
17
 
18
+ # ────────────────────── 1. custom extension ──────────────────────
 
 
19
  USER node
20
  RUN mkdir -p /home/node/n8n-custom/disable-gzip
21
 
22
+ # package.json (loader ΰ€•ΰ₯‹ package ΰ€¦ΰ€Ώΰ€–ΰ€Ύΰ€¨ΰ€Ύ ΰ€œΰ€Όΰ€°ΰ₯‚ΰ€°ΰ₯€ ΰ€Ήΰ₯ˆ)
23
+ RUN printf '{\n "name": "disable-gzip","version": "1.0.0","main": "index.js"\n}\n' \
24
+ > /home/node/n8n-custom/disable-gzip/package.json
 
 
 
 
 
25
 
26
+ # index.js β†’ compression layer ΰ€Ήΰ€Ÿΰ€Ύΰ€¨ΰ€Ύ + header strip
27
  RUN cat >/home/node/n8n-custom/disable-gzip/index.js <<'JS'
28
  module.exports = {
29
  init(app) {
30
+ // compression middleware remove
31
  if (app?._router?.stack) {
32
  const before = app._router.stack.length;
33
  app._router.stack = app._router.stack.filter(
 
36
  console.log(`πŸ—œοΈ Removed compression middleware β€’ stack ${before}β†’${app._router.stack.length}`);
37
  }
38
 
39
+ // always unset Content-Encoding + stop proxy transform
40
  app.use((_req, res, next) => {
41
  res.removeHeader('Content-Encoding');
42
  res.setHeader('Cache-Control', 'no-transform');
 
48
  };
49
  JS
50
 
51
+ # ────────────────────── 2. start-script ──────────────────────
 
 
52
  USER root
53
  RUN cat >/usr/local/bin/start.sh <<'SH' && chmod +x /usr/local/bin/start.sh
54
  #!/usr/bin/env sh
55
  set -eu
56
+
57
  N8N_PORT="${PORT:-7860}"
58
  export N8N_PORT
59
 
60
+ # build HF public URL (user/repo -> user-repo.hf.space)
61
  if [ -n "${SPACE_ID:-}" ]; then
62
+ SPACE_SLUG=$(printf '%s' "$SPACE_ID" | tr '/_' '-')
63
+ APP_URL="https://${SPACE_SLUG}.hf.space"
64
  else
65
+ APP_URL="http://localhost:${N8N_PORT}"
66
  fi
67
 
68
+ export N8N_BASE_URL="$APP_URL"
69
+ export WEBHOOK_URL="$APP_URL"
70
+ export N8N_EDITOR_BASE_URL="$APP_URL"
71
 
72
+ echo "πŸš€ n8n on $N8N_PORT β€’ Public: $APP_URL"
73
  exec n8n start
74
  SH
75