legends810 commited on
Commit
08caf6b
Β·
verified Β·
1 Parent(s): 8788edb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +47 -52
Dockerfile CHANGED
@@ -1,9 +1,8 @@
1
  ###############################################################################
2
- # n8n for Hugging Face Spaces – gzip compression fully disabled (Complete Fix)
3
  ###############################################################################
4
  FROM docker.n8n.io/n8nio/n8n:latest
5
 
6
- #################### Runtime env vars #########################################
7
  ENV N8N_HOST=0.0.0.0 \
8
  N8N_PROTOCOL=http \
9
  DB_TYPE=sqlite \
@@ -16,74 +15,70 @@ ENV N8N_HOST=0.0.0.0 \
16
  N8N_LOG_LEVEL=debug \
17
  N8N_CUSTOM_EXTENSIONS=/home/node/n8n-custom
18
 
19
- #################### Disable compression via custom extension ##################
 
 
20
  USER node
21
- RUN mkdir -p /home/node/n8n-custom && \
22
- echo 'module.exports = {' > /home/node/n8n-custom/disableGzip.js && \
23
- echo ' init(app) {' >> /home/node/n8n-custom/disableGzip.js && \
24
- echo ' if (app?._router?.stack) {' >> /home/node/n8n-custom/disableGzip.js && \
25
- echo ' app._router.stack = app._router.stack.filter(' >> /home/node/n8n-custom/disableGzip.js && \
26
- echo ' (layer) => !(layer.handle && layer.handle.name === "compression")' >> /home/node/n8n-custom/disableGzip.js && \
27
- echo ' );' >> /home/node/n8n-custom/disableGzip.js && \
28
- echo ' }' >> /home/node/n8n-custom/disableGzip.js && \
29
- echo ' app.use((_req, res, next) => {' >> /home/node/n8n-custom/disableGzip.js && \
30
- echo ' res.removeHeader("Content-Encoding");' >> /home/node/n8n-custom/disableGzip.js && \
31
- echo ' res.setHeader("Cache-Control", "no-transform");' >> /home/node/n8n-custom/disableGzip.js && \
32
- echo ' next();' >> /home/node/n8n-custom/disableGzip.js && \
33
- echo ' });' >> /home/node/n8n-custom/disableGzip.js && \
34
- echo ' console.log("πŸ—œοΈ gzip compression completely disabled");' >> /home/node/n8n-custom/disableGzip.js && \
35
- echo ' },' >> /home/node/n8n-custom/disableGzip.js && \
36
- echo '};' >> /home/node/n8n-custom/disableGzip.js
 
 
 
 
 
 
 
37
 
38
- #################### Start script #############################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  USER root
40
- RUN set -e; \
41
- cat >/usr/local/bin/start.sh <<'SH' && \
42
- chmod +x /usr/local/bin/start.sh
43
- #!/bin/sh
44
  set -eu
45
-
46
- # HF reverse-proxy sets $PORT (local fallback 7860)
47
  N8N_PORT="${PORT:-7860}"
48
  export N8N_PORT
49
 
50
- # ---- build public URL ------------------------------------------------------
51
  if [ -n "${SPACE_ID:-}" ]; then
52
- # convert "user/repo" β†’ "user-repo"
53
- SPACE_SLUG=$(printf '%s' "$SPACE_ID" | tr '/_' '-')
54
- APP_URL="https://${SPACE_SLUG}.hf.space"
55
- elif [ -n "${SPACE_HOST:-}" ]; then # legacy var
56
- APP_URL="https://${SPACE_HOST}"
57
- elif [ -n "${HOSTNAME:-}" ] && echo "$HOSTNAME" | grep -q '\.hf\.space'; then
58
- APP_URL="https://${HOSTNAME}"
59
  else
60
- APP_URL="http://localhost:${N8N_PORT}"
61
  fi
62
 
63
- # No trailing slash to prevent double-slash issues
64
  export N8N_BASE_URL="${APP_URL}"
65
  export WEBHOOK_URL="${APP_URL}"
66
  export N8N_EDITOR_BASE_URL="${APP_URL}"
67
 
68
- echo "πŸš€ n8n starting on port ${N8N_PORT}"
69
- echo "🌐 Public URL : ${APP_URL}"
70
- echo "πŸ“š DB : SQLite"
71
- echo "πŸ”’ Authentication : disabled"
72
- echo "πŸ“¦ Community packages: enabled"
73
- echo "πŸ—œοΈ Compression : disabled (main + webhook + extension)"
74
- echo
75
-
76
  exec n8n start
77
  SH
78
- USER node
79
 
80
- #################### expose port ###################################
81
  EXPOSE 7860
82
-
83
- #################### health-check #############################################
84
- HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \
85
- CMD sh -c 'curl -f http://localhost:${PORT:-7860}/healthz || exit 1'
86
-
87
- #################### entrypoint ################################################
88
  ENTRYPOINT ["tini", "--"]
89
  CMD ["start.sh"]
 
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 \
 
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(
41
+ (layer) => !(layer.handle && layer.handle.name === 'compression')
42
+ );
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');
50
+ next();
51
+ });
52
+
53
+ console.log('βœ… Custom extension loaded β†’ gzip disabled globally');
54
+ },
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
 
 
82
  EXPOSE 7860
 
 
 
 
 
 
83
  ENTRYPOINT ["tini", "--"]
84
  CMD ["start.sh"]