File size: 3,471 Bytes
c1c78f1
d3f76b5
c1c78f1
 
 
 
 
 
 
 
 
 
 
 
 
41bad43
c1c78f1
 
 
 
d3f76b5
39cd355
c1c78f1
d3f76b5
c1c78f1
 
 
 
 
 
d3f76b5
c1c78f1
 
 
 
 
 
 
d3f76b5
c1c78f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3f76b5
 
 
 
 
c1c78f1
d3f76b5
 
 
 
c1c78f1
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
ARG III_VERSION=0.11.2

# Pull the official iii engine binary
FROM iiidev/iii:${III_VERSION} AS iii-image

FROM node:22-slim

ARG AGENTMEMORY_VERSION=0.9.21
ARG III_VERSION=0.11.2
ARG III_SDK_VERSION=0.11.2

# Install Caddy + runtime deps
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       debian-keyring debian-archive-keyring apt-transport-https \
       curl gnupg openssl ca-certificates tini gosu python3 python3-pip \
    && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
       | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg \
    && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
       | tee /etc/apt/sources.list.d/caddy-stable.list \
    && apt-get update && apt-get install -y caddy \
    && pip3 install --break-system-packages huggingface_hub \
    && rm -rf /var/lib/apt/lists/*

# Copy iii binary from official image (avoids re-downloading on every boot)
COPY --from=iii-image /app/iii /usr/local/bin/iii

# Set up HF Spaces user (uid 1000 required)
RUN userdel -r node 2>/dev/null || true \
    && useradd -m -u 1000 user

# Install agentmemory with pinned iii-sdk to match engine version
WORKDIR /opt/agentmemory
RUN printf '{"name":"agentmemory-deploy","version":"1.0.0","private":true,"overrides":{"iii-sdk":"%s"}}\n' \
      "${III_SDK_VERSION}" > package.json \
    && npm install "@agentmemory/agentmemory@${AGENTMEMORY_VERSION}" \
       --omit=optional --no-fund --no-audit \
    && ln -s /opt/agentmemory/node_modules/.bin/agentmemory /usr/local/bin/agentmemory

# Override iii-config.yaml at build time:
# - bind 0.0.0.0 (not 127.0.0.1) so Caddy can reach it
# - use absolute /home/user/.agentmemory paths so data lands in our sync dir
RUN cat > /opt/agentmemory/node_modules/@agentmemory/agentmemory/dist/iii-config.yaml <<'EOF'
workers:
  - name: iii-http
    config:
      port: 3111
      host: 0.0.0.0
      default_timeout: 180000
      cors:
        allowed_origins:
          - "http://localhost:3111"
          - "http://localhost:3113"
          - "http://127.0.0.1:3111"
          - "http://127.0.0.1:3113"
        allowed_methods: [GET, POST, PUT, DELETE, OPTIONS]
  - name: iii-state
    config:
      adapter:
        name: kv
        config:
          store_method: file_based
          file_path: /home/user/.agentmemory/state_store.db
  - name: iii-queue
    config:
      adapter:
        name: builtin
  - name: iii-pubsub
    config:
      adapter:
        name: local
  - name: iii-cron
    config:
      adapter:
        name: kv
  - name: iii-stream
    config:
      port: 3112
      host: 0.0.0.0
      adapter:
        name: kv
        config:
          store_method: file_based
          file_path: /home/user/.agentmemory/stream_store
  - name: iii-observability
    config:
      enabled: true
      service_name: agentmemory
      exporter: memory
      sampling_ratio: 1.0
      metrics_enabled: true
      logs_enabled: true
      logs_console_output: true
EOF

# Give user 1000 ownership of everything it needs to write at runtime
RUN chown -R user:user /opt/agentmemory /home/user

ENV TINI_SUBREAPER=1 \
    HOME=/home/user

WORKDIR /app
RUN chown user:user /app

USER user

COPY --chown=user:user Caddyfile /app/Caddyfile
COPY --chown=user:user start.sh /app/start.sh
COPY --chown=user:user sync.py /app/sync.py
RUN chmod +x /app/start.sh

EXPOSE 7860

ENTRYPOINT ["/usr/bin/tini", "--", "/app/start.sh"]