File size: 2,578 Bytes
08e0270
cb3a997
 
 
 
 
 
 
 
 
 
 
 
08e0270
cb3a997
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

# ─────────────────────────────────────────────────────────────
# HF Docker Space β€” Ollama + Claude Code (web terminal)
# Exposed port : 7860  (only port HF Spaces forwards)
# Web terminal : ttyd  (full interactive Claude CLI in browser)
# Model        : gpt-oss:20b via Ollama Anthropic-compat API
# ─────────────────────────────────────────────────────────────
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# ── System packages ──────────────────────────────────────────
RUN apt-get update && apt-get install -y \
        curl wget git ca-certificates gnupg zstd \
    && \
    # Node.js 20 LTS (needed by Claude Code CLI)
    curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs && \
    # Ollama
    curl -fsSL https://ollama.com/install.sh | sh && \
    # ttyd β€” browser-based terminal  (static binary, no extra deps)
    wget -q -O /usr/local/bin/ttyd \
        https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 && \
    chmod +x /usr/local/bin/ttyd && \
    rm -rf /var/lib/apt/lists/*

# ── Claude Code CLI (global npm install as root) ─────────────
RUN npm install -g @anthropic-ai/claude-code

# ── HF Spaces requires UID 1000 ──────────────────────────────
RUN useradd -m -u 1000 user

# Switch to user 1000 for all runtime operations
USER user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:/usr/local/bin:$PATH

# ── Point Claude Code at local Ollama (no Anthropic key needed)
ENV ANTHROPIC_AUTH_TOKEN=ollama
ENV ANTHROPIC_API_KEY=ollama
ENV ANTHROPIC_BASE_URL=http://localhost:11434

# Ollama: listen on all interfaces so internal health-checks work
ENV OLLAMA_HOST=0.0.0.0:11434
# Store models under user home (writable at runtime)
ENV OLLAMA_MODELS=/home/user/.ollama/models

# Skip Claude Code's first-run login wizard
ENV CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

WORKDIR /home/user

# Copy startup script
COPY --chown=user entrypoint.sh /home/user/entrypoint.sh
RUN chmod +x /home/user/entrypoint.sh

# ── Only one port is forwarded by HF Spaces ──────────────────
EXPOSE 7860

CMD ["/home/user/entrypoint.sh"]