Prajith04 commited on
Commit
83f71fe
·
verified ·
1 Parent(s): 5e72fb7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +66 -16
Dockerfile CHANGED
@@ -1,26 +1,76 @@
1
- # Use Node.js 22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  FROM node:22-bookworm-slim
3
 
4
- # Install system dependencies
5
- RUN apt-get update && apt-get install -y git curl && rm -rf /var/lib/apt/lists/*
 
 
 
6
 
7
- # Set working directory
8
  WORKDIR /app
9
 
10
- # Install OpenClaw globally
11
- RUN npm install -g openclaw@latest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # The 'node' user already exists with UID 1000 in this image.
14
- RUN chown -R node:node /app
15
 
16
- # Switch to the existing 'node' user
17
- USER node
18
 
19
- ENV HOME=/home/node
20
- ENV PATH=/home/node/.local/bin:$PATH
21
- ENV OPENCLAW_GATEWAY_TOKEN=openclaw-api
22
- # Expose the mandatory Hugging Face port
23
  EXPOSE 7860
24
 
25
- # Write config and start OpenClaw
26
- CMD ["sh", "-c", "mkdir -p /home/node/.openclaw && echo '{\"gateway\":{\"mode\":\"local\",\"bind\":\"custom\",\"customBindHost\":\"0.0.0.0\",\"port\":7860,\"trustedProxies\":[\"10.0.0.0/8\",\"172.16.0.0/12\",\"192.168.0.0/16\"],\"controlUi\":{\"dangerouslyAllowHostHeaderOriginFallback\":true}}}' > /home/node/.openclaw/openclaw.json && openclaw doctor --fix && echo '=== GATEWAY CONFIG ===' && cat /home/node/.openclaw/openclaw.json && echo '===================' && openclaw gateway run --allow-unconfigured"]
 
 
1
+ # ============================================================
2
+ # README.md must exist in the repo root with this YAML block:
3
+ # ---
4
+ # title: OpenClaw
5
+ # emoji: 🐾
6
+ # sdk: docker
7
+ # app_port: 7860
8
+ # ---
9
+ # ============================================================
10
+
11
+ # Stage 1: Ensure submodule source is available
12
+ FROM node:22-bookworm-slim AS source
13
+ RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*
14
+ WORKDIR /src
15
+ COPY . .
16
+ RUN if [ ! -f openclaw/package.json ]; then \
17
+ rm -rf openclaw && \
18
+ git clone --depth 1 -b affine-extension https://github.com/potnoodledev/openclaw.git openclaw; \
19
+ fi
20
+
21
+ # Stage 2: Build (full install + compile)
22
+ FROM node:22-bookworm AS builder
23
+ RUN curl -fsSL https://bun.sh/install | bash
24
+ ENV PATH="/root/.bun/bin:${PATH}"
25
+ RUN corepack enable
26
+ WORKDIR /app
27
+ COPY --from=source /src/openclaw/package.json /src/openclaw/pnpm-lock.yaml /src/openclaw/pnpm-workspace.yaml /src/openclaw/.npmrc ./
28
+ COPY --from=source /src/openclaw/ui/package.json ./ui/package.json
29
+ COPY --from=source /src/openclaw/extensions ./extensions
30
+ COPY --from=source /src/openclaw/patches ./patches
31
+ COPY --from=source /src/openclaw/scripts ./scripts
32
+ RUN pnpm install --frozen-lockfile
33
+ COPY --from=source /src/openclaw/ .
34
+ RUN pnpm build
35
+ ENV OPENCLAW_PREFER_PNPM=1
36
+ RUN pnpm ui:build
37
+ RUN CI=true pnpm prune --prod
38
+
39
+ # Stage 3: Runtime
40
  FROM node:22-bookworm-slim
41
 
42
+ RUN apt-get update && apt-get install -y --no-install-recommends git curl ca-certificates && rm -rf /var/lib/apt/lists/*
43
+ RUN corepack enable
44
+
45
+ # HF Spaces requires UID 1000
46
+ RUN useradd -m -u 1000 user
47
 
 
48
  WORKDIR /app
49
 
50
+ COPY --from=builder /app/dist ./dist
51
+ COPY --from=builder /app/openclaw.mjs ./openclaw.mjs
52
+ COPY --from=builder /app/node_modules ./node_modules
53
+ COPY --from=builder /app/package.json ./package.json
54
+ COPY --from=builder /app/pnpm-workspace.yaml ./pnpm-workspace.yaml
55
+ COPY --from=builder /app/.npmrc ./.npmrc
56
+ COPY --from=builder /app/extensions ./extensions
57
+ COPY --from=builder /app/packages ./packages
58
+ COPY --from=builder /app/patches ./patches
59
+ COPY --from=builder /app/docs ./docs
60
+
61
+ COPY --from=source /src/openclaw-config /openclaw-config
62
+
63
+ ENV NODE_ENV=production
64
+ ENV OPENCLAW_PREFER_PNPM=1
65
+ # HF Spaces: data persists only in /data (if persistent storage is enabled)
66
+ ENV HOME=/home/user
67
 
68
+ RUN chown -R user:user /app /openclaw-config
 
69
 
70
+ USER user
 
71
 
 
 
 
 
72
  EXPOSE 7860
73
 
74
+ # Run the entrypoint script, then start on port 7860 (HF Spaces requirement)
75
+ ENTRYPOINT ["/bin/sh", "/openclaw-config/entrypoint.sh"]
76
+ CMD ["node", "openclaw.mjs", "gateway", "--allow-unconfigured", "--bind", "0.0.0.0", "--port", "7860"]