legends810 commited on
Commit
31e9076
Β·
verified Β·
1 Parent(s): 9ccab9e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -11
Dockerfile CHANGED
@@ -1,9 +1,9 @@
1
  ###############################################################################
2
- # n8n for Hugging Face Spaces – with correct URL generation
3
  ###############################################################################
4
  FROM docker.n8n.io/n8nio/n8n:latest
5
 
6
- #################### Runtime-level env vars ###################################
7
  ENV N8N_HOST=0.0.0.0 \
8
  N8N_PROTOCOL=http \
9
  DB_TYPE=sqlite \
@@ -14,7 +14,7 @@ ENV N8N_HOST=0.0.0.0 \
14
  N8N_USER_MANAGEMENT_DISABLED=true \
15
  N8N_LOG_LEVEL=info
16
 
17
- #################### Tiny start script ########################################
18
  USER root
19
  RUN set -e; \
20
  cat >/usr/local/bin/start.sh <<'SH' && \
@@ -22,17 +22,19 @@ RUN set -e; \
22
  #!/bin/sh
23
  set -eu
24
 
25
- # HF reverse-proxy sets $PORT; fallback 7860 for local runs
26
  N8N_PORT="${PORT:-7860}"
27
  export N8N_PORT
28
 
29
- # Hugging Face URL generation fix
30
  if [ -n "${SPACE_ID:-}" ]; then
31
- # SPACE_ID format: username/spacename
32
- # Convert to: username-spacename.hf.space
33
- APP_URL="https://$(echo "$SPACE_ID" | sed 's/\//-/').hf.space"
34
- elif [ -n "${SPACE_HOST:-}" ]; then
35
  APP_URL="https://${SPACE_HOST}"
 
 
36
  else
37
  APP_URL="http://localhost:${N8N_PORT}"
38
  fi
@@ -53,13 +55,13 @@ exec n8n start
53
  SH
54
  USER node
55
 
56
- #################### (optional) expose default port ###########################
57
  EXPOSE 7860
58
 
59
  #################### health-check #############################################
60
  HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \
61
  CMD sh -c 'curl -f http://localhost:${PORT:-7860}/healthz || exit 1'
62
 
63
- #################### container entrypoint #####################################
64
  ENTRYPOINT ["tini", "--"]
65
  CMD ["start.sh"]
 
1
  ###############################################################################
2
+ # n8n for Hugging Face Spaces – fixed public-URL handling (no bash needed)
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 \
 
14
  N8N_USER_MANAGEMENT_DISABLED=true \
15
  N8N_LOG_LEVEL=info
16
 
17
+ #################### Start script #############################################
18
  USER root
19
  RUN set -e; \
20
  cat >/usr/local/bin/start.sh <<'SH' && \
 
22
  #!/bin/sh
23
  set -eu
24
 
25
+ # HF reverse-proxy sets $PORT (local fallback 7860)
26
  N8N_PORT="${PORT:-7860}"
27
  export N8N_PORT
28
 
29
+ # ---- build public URL ------------------------------------------------------
30
  if [ -n "${SPACE_ID:-}" ]; then
31
+ # convert "user/repo" β†’ "user-repo"
32
+ SPACE_SLUG=$(printf '%s' "$SPACE_ID" | tr '/_' '-')
33
+ APP_URL="https://${SPACE_SLUG}.hf.space"
34
+ elif [ -n "${SPACE_HOST:-}" ]; then # legacy var
35
  APP_URL="https://${SPACE_HOST}"
36
+ elif [ -n "${HOSTNAME:-}" ] && echo "$HOSTNAME" | grep -q '\.hf\.space'; then
37
+ APP_URL="https://${HOSTNAME}"
38
  else
39
  APP_URL="http://localhost:${N8N_PORT}"
40
  fi
 
55
  SH
56
  USER node
57
 
58
+ #################### (optional) expose port ###################################
59
  EXPOSE 7860
60
 
61
  #################### health-check #############################################
62
  HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \
63
  CMD sh -c 'curl -f http://localhost:${PORT:-7860}/healthz || exit 1'
64
 
65
+ #################### entrypoint ################################################
66
  ENTRYPOINT ["tini", "--"]
67
  CMD ["start.sh"]