GTO-Custom-AI commited on
Commit
933cfdd
·
verified ·
1 Parent(s): b8cc449

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -53
Dockerfile CHANGED
@@ -1,43 +1,14 @@
1
- # ==============================================================================
2
- # Dockerfile – n8n on Hugging Face Spaces
3
- #
4
- # Solves:
5
- # 1. "Command not found" → uses alpine base with a real shell
6
- # 2. "Permissions too wide" → start.sh fixes perms before dropping to uid 1000
7
- # 3. Port 7860 → HF Spaces requirement
8
- # 4. Persistence → /data/.n8n backed by HF persistent storage
9
- # ==============================================================================
10
-
11
- # --------------- Stage 1: Build on Alpine with shell --------------------------
12
- FROM alpine:3.19 AS base
13
 
14
- # Install Node.js LTS, npm, and runtime dependencies n8n needs
 
15
  RUN apk add --no-cache \
16
  nodejs=~20 \
17
  npm \
18
- su-exec \
19
- tini \
20
- bash \
21
- curl \
22
- git \
23
- openssh-client \
24
- ca-certificates \
25
- tzdata \
26
  python3 \
27
  make \
28
- g++
29
-
30
- # Install n8n globally
31
- RUN npm install -g n8n@latest && \
32
- npm cache clean --force
33
-
34
- # --------------- Stage 2: Runtime image --------------------------------------
35
- FROM alpine:3.19
36
-
37
- # Re-install only runtime dependencies (no build toolchain)
38
- RUN apk add --no-cache \
39
- nodejs=~20 \
40
- npm \
41
  su-exec \
42
  tini \
43
  bash \
@@ -47,33 +18,32 @@ RUN apk add --no-cache \
47
  ca-certificates \
48
  tzdata
49
 
50
- # Copy the globally-installed n8n from the build stage
51
- COPY --from=base /usr/lib/node_modules /usr/lib/node_modules
52
- COPY --from=base /usr/local/lib/node_modules /usr/local/lib/node_modules
53
- # Symlink the n8n binary so it's on PATH
54
- RUN ln -sf /usr/local/lib/node_modules/n8n/bin/n8n /usr/local/bin/n8n
55
-
56
- # Create the non-root user that n8n will run as (uid/gid 1000)
57
- RUN addgroup -g 1000 n8n && \
58
- adduser -u 1000 -G n8n -s /bin/bash -D n8n
59
 
60
- # ---------- Environment -------------------------------------------------------
61
  ENV N8N_PORT=7860 \
62
  N8N_PROTOCOL=https \
63
  N8N_USER_FOLDER=/data/.n8n \
64
- N8N_DIAGNOSTICS_ENABLED=false \
65
- N8N_HIRING_BANNER_ENABLED=false \
66
- N8N_PERSONALIZATION_ENABLED=false \
67
- NODE_ENV=production \
68
- GENERIC_TIMEZONE=UTC
 
 
 
 
 
 
69
 
70
- # Expose the HF-required port
71
  EXPOSE 7860
72
 
73
- # ---------- Entrypoint --------------------------------------------------------
74
- COPY start.sh /start.sh
75
  RUN chmod +x /start.sh
76
 
77
- # Use tini as PID 1 to reap zombies and forward signals
78
  ENTRYPOINT ["/sbin/tini", "--"]
79
  CMD ["/start.sh"]
 
1
+ # Use Alpine as the base
2
+ FROM alpine:3.19
 
 
 
 
 
 
 
 
 
 
3
 
4
+ # 1. Install all dependencies and build tools in one layer
5
+ # We include python3, make, and g++ because n8n's native modules need them to compile
6
  RUN apk add --no-cache \
7
  nodejs=~20 \
8
  npm \
 
 
 
 
 
 
 
 
9
  python3 \
10
  make \
11
+ g++ \
 
 
 
 
 
 
 
 
 
 
 
 
12
  su-exec \
13
  tini \
14
  bash \
 
18
  ca-certificates \
19
  tzdata
20
 
21
+ # 2. Install n8n globally and clean up the npm cache to keep image size down
22
+ RUN npm install -g n8n@latest && npm cache clean --force
 
 
 
 
 
 
 
23
 
24
+ # 3. HF Spaces requirements
25
  ENV N8N_PORT=7860 \
26
  N8N_PROTOCOL=https \
27
  N8N_USER_FOLDER=/data/.n8n \
28
+ NODE_ENV=production
29
+
30
+ # 4. Setup permissions for the persistent bucket
31
+ USER root
32
+ RUN mkdir -p /data/.n8n && chown -R 1000:1000 /data/.n8n
33
+
34
+ # 5. Create the n8n user (uid 1000)
35
+ RUN addgroup -g 1000 n8n && \
36
+ adduser -u 1000 -G n8n -s /bin/bash -D n8n
37
+
38
+ USER 1000
39
 
40
+ # Expose HF port
41
  EXPOSE 7860
42
 
43
+ # Copy and prep the startup script
44
+ COPY --chown=1000:1000 start.sh /start.sh
45
  RUN chmod +x /start.sh
46
 
47
+ # Use tini as PID 1 to handle signals and zombies correctly
48
  ENTRYPOINT ["/sbin/tini", "--"]
49
  CMD ["/start.sh"]