Repository navigation
Expand file tree
/
Copy pathDockerfile.server
More file actions
535 lines (506 loc) · 31 KB
/
Copy pathDockerfile.server
File metadata and controls
535 lines (506 loc) · 31 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# One application image: an immutable Server or KB composition.
# PostgreSQL and local models are standardized sibling services.
# aimee-server: the agent/memory broker. Owns DB1 through the PostgreSQL-backed
# aimee/postgres module pair and
# fronts the /v1 HTTP API; it reaches aimee-kb (KB_STORE + pgvector) over HTTP via
# AIMEE_KB_API_URL. Without that URL the kb-backed (shared/vector) features are
# simply unavailable, so this image also runs standalone (DB1-backed endpoints
# only). The legacy unix-socket kb transport + autostart were retired (#2747).
#
# WITH_RUNTIME_WEB bundles the browser UI (aimee-runtime-web). It is ON by default — the
# UI is a first-class surface. @rakuensoftware/smoothgui is vendored as a tarball
# under frontend/vendor/ (a file: dependency), so the frontend builds with NO
# registry token and NO credentials. Set --build-arg WITH_RUNTIME_WEB=0 to build the
# server-only image (skips the frontend + Go webchat stages entirely).
ARG WITH_RUNTIME_WEB=1
# WITH_VSCODE bundles code-server (full in-browser VSCode, Open-VSX only) for the
# webchat Projects/editor surface. ON by default — the editor is a first-class
# feature; build with --build-arg WITH_VSCODE=0 to omit it (saves ~100 MB).
ARG WITH_VSCODE=1
# Debian bookworm's SQLite 3.40 contains the WAL-reset corruption race.
# Use the fixed stable patch release for the audit ledger on both architectures.
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS audit-sqlite-build
RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
COPY scripts/build-audit-sqlite.sh /tmp/build-audit-sqlite.sh
RUN sh /tmp/build-audit-sqlite.sh /out
# The module runtime is a static multicall binary. The canonical process
# contracts decide which executable names are populated from it in the C build
# stage below, so Docker never carries a second language-selection list.
FROM golang:1.26.11-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 AS module-go-build
WORKDIR /src/server-go
COPY server-go/go.mod server-go/go.sum ./
RUN go mod download
COPY server-go/ ./
RUN CGO_ENABLED=0 go build -trimpath -o /out/aimee-module ./cmd/aimee-module \
&& CGO_ENABLED=0 go build -trimpath -o /out/aimee-module-config \
github.com/RakuenSoftware/aimee-module-config/runtime
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS build
# Both protocol hosts use current libpq headers; PostgreSQL itself is a sibling.
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
&& install -d /usr/share/postgresql-common/pgdg \
&& curl -fsSL --retry 5 --retry-all-errors --connect-timeout 30 --max-time 180 \
https://www.postgresql.org/media/keys/ACCC4CF8.asc \
-o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
&& echo 'deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main' > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
cmake \
ca-certificates \
cmake \
libpq-dev \
libp11-kit-dev \
git \
libsqlite3-dev \
libssl-dev \
libzstd-dev \
pkg-config \
python3 \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /src
COPY . .
COPY --from=module-go-build /out/aimee-module /tmp/aimee-module-go
COPY --from=module-go-build /out/aimee-module-config /tmp/aimee-module-config-go
ARG AIMEE_VERSION=""
# The CLI ships alongside the server. It is what gives a spawned provider-CLI
# delegate (the `claude` binary) any access to aimee at all: `aimee mcp serve` is
# the stdio MCP proxy that forwards tool calls to this server over /v1, and
# `aimee hooks pre` is the PreToolUse guard. Without the binary in the image a
# delegate has no aimee tools and no guard can run — it gets a bare shell and its
# own credentials, which is the opposite of the intent.
# Memory ships as a vendored binary bundle (vendor/aims-memory): prebuilt bridge
# archives that are linked into the Server and KB resources here, and the memory
# executables and provisioning scripts that go into the runtime image. The
# bundle is verified against this tree before use. Images are built for
# linux/amd64 only, the one platform the bundle exists for.
ARG TARGETARCH
RUN build_version="$AIMEE_VERSION" \
&& if [ -z "$build_version" ]; then build_version=$(cat src/core/VERSION); fi \
&& if [ "${TARGETARCH:-amd64}" != amd64 ]; then echo "aimee images are built for linux/amd64 only (TARGETARCH=${TARGETARCH})" >&2; exit 1; fi \
&& sh scripts/fetch-treesitter.sh \
&& memory_platform="linux-amd64" \
&& memory_make="" \
&& mkdir -p /memory-image \
&& python3 -I scripts/check_memory_bundle.py --platform "$memory_platform" --unpack /memory-bundle \
&& memory_make="-f Makefile -f /memory-bundle/link/overlay-link.mk AIMS_VENDOR=/memory-bundle" \
&& install -d /memory-image/source/src/modules /memory-image/source/tests/baselines/modules \
&& cp -a /memory-bundle/bin /memory-bundle/provision /memory-image/ \
&& cp /memory-bundle/MANIFEST.json /memory-image/MANIFEST.json \
&& cp src/modules/process-contracts.json /memory-image/source/src/modules/ \
&& cp tests/baselines/modules/canonical-inventory.yaml /memory-image/source/tests/baselines/modules/ \
&& make -C src $memory_make ../aimee-server ../aimee-kb ../aimee-kb-worm ../aimee ../aimee-forwarder -j"$(nproc)" \
AIMEE_TREESITTER=1 GIT_VERSION="v$build_version" \
&& cmake -S . -B /thinclient-build \
-DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/usr/local \
&& cmake --build /thinclient-build --target aimee-client -j"$(nproc)"
# Build the independently supervised same-container module adapters from the
# canonical contract. Every module process is Go: a copy of the static
# multicall runtime under its attested name.
RUN python3 scripts/export_c_repositories.py --runtime-bundle /module-runtime \
&& mkdir -p /module-runtime/bin \
&& while IFS= read -r module_id; do \
[ -n "$module_id" ] || continue; \
if [ "$module_id" = config ]; then module_bin=/tmp/aimee-module-config-go; \
else module_bin=/tmp/aimee-module-go; fi; \
install -m 0755 "$module_bin" "/module-runtime/bin/aimee-module-$module_id"; \
done < /module-runtime/go.modules
# --- webchat frontend: build the React SPA into a single index.html ---
# vite-plugin-singlefile inlines all JS/CSS, so the runtime image ships one file.
FROM node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 AS frontend-build
WORKDIR /frontend
# @rakuensoftware/smoothgui is vendored under frontend/vendor/ as a tarball and
# referenced via a file: dependency, so `npm ci` resolves it from the build
# context (no GitHub Packages token, no .npmrc, no BuildKit secret). The vendored
# tarball must be present before `npm ci` reads the lockfile.
COPY frontend/package.json frontend/package-lock.json ./
COPY frontend/vendor/ ./vendor/
RUN npm ci
COPY frontend/ ./
RUN npm run build
# --- webchat service: standalone Go browser server (cgo: legacy crypt migration + sqlite) ---
FROM golang:1.26.11-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 AS runtime-web-build
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libcrypt-dev \
libpam0g-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /thinclient-build/libaimee-client.so /usr/local/lib/libaimee-client.so
COPY --from=build /thinclient-build/aimee-client-install.pc /usr/local/lib/pkgconfig/aimee-client.pc
COPY --from=build /src/src/headers/cli_client.h /usr/local/include/aimee-client/cli_client.h
WORKDIR /src/runtime-web
COPY server-go/thinclient/ /src/server-go/thinclient/
COPY server-go/go.mod server-go/go.sum /src/server-go/
COPY server-go/modules/runtime-web/policy/ /src/server-go/modules/runtime-web/policy/
COPY server-go/ir/ /src/server-go/ir/
COPY runtime-web/go.mod runtime-web/go.sum ./
RUN go mod download
COPY runtime-web/ ./
RUN CGO_ENABLED=1 go build -o /out/aimee-runtime-web .
# Go owns the WFE control plane. It is built and run independently from the
# temporary C agent resource plane so a provider crash restarts both processes
# without putting C back in charge of workflow transitions. This is crash
# containment, not an OS security boundary: both processes currently share the
# appliance service identity for repository credentials and Unix-socket access.
FROM golang:1.26.11-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 AS wfe-build
WORKDIR /src/server-go
COPY server-go/go.mod server-go/go.sum ./
RUN go mod download
COPY server-go/ ./
RUN CGO_ENABLED=0 go build -trimpath -o /out/aimee-wfe ./cmd/aimee-server \
&& CGO_ENABLED=0 go build -trimpath -o /out/aimee-delegate-egress ./modules/delegates/cmd/aimee-delegate-egress
# Collect webchat artifacts into a uniform /runtime-web layout. The "1" variant pulls
# from the frontend + Go builds above (only in the build graph when
# WITH_RUNTIME_WEB=1 selects this stage). The "0" variant is empty → no webchat in the
# image (WITH_RUNTIME_WEB=0 opts the UI out of the build entirely).
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS runtime-web-stage-1
COPY --from=runtime-web-build /out/aimee-runtime-web /runtime-web/aimee-runtime-web
COPY --from=frontend-build /frontend/dist/index.html /runtime-web/index.html
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS runtime-web-stage-0
RUN mkdir -p /runtime-web
FROM runtime-web-stage-${WITH_RUNTIME_WEB} AS runtime-web-stage
# Optional code-server (full VSCode in the browser). The "1" variant fetches the
# pinned, arch-matched .deb and extracts it under /opt/codeserver (only in the
# build graph when WITH_VSCODE=1). The "0" variant is an empty /opt/codeserver/usr
# so the final COPY is a no-op — no download, no size, in the default/CI build.
# code-server bundles its own Node and defaults to the Open VSX registry.
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS code-server-stage-1
ARG TARGETARCH
ARG CODE_SERVER_VERSION=4.96.4
ARG CODE_SERVER_SHA256_amd64=9062963bfa22664a2fb443343fbaa3ae39b4d12817c2002e0f550bcf4f3ffb2c
# Release downloads go through GitHub/CDN edges that intermittently return 5xx
# (a 504 here failed the whole T3 e2e-docker topology). `curl -fsSL` alone turns
# that into a hard build failure, so retry with backoff. --retry-all-errors is
# required: -f makes an HTTP 504 exit 22, which plain --retry would NOT retry.
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& eval "want=\${CODE_SERVER_SHA256_${TARGETARCH}}" \
&& test -n "$want" \
&& curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors --retry-max-time 180 --connect-timeout 30 "https://github.com/coder/code-server/releases/download/v${CODE_SERVER_VERSION}/code-server_${CODE_SERVER_VERSION}_${TARGETARCH}.deb" -o /tmp/cs.deb \
&& echo "$want /tmp/cs.deb" | sha256sum -c - \
&& mkdir -p /opt/codeserver \
&& dpkg-deb -x /tmp/cs.deb /opt/codeserver \
&& rm /tmp/cs.deb \
&& rm -rf /var/lib/apt/lists/*
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171 AS code-server-stage-0
RUN mkdir -p /opt/codeserver/usr
FROM code-server-stage-${WITH_VSCODE} AS code-server-stage
FROM debian:bookworm-slim@sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b07ea4171
COPY --from=audit-sqlite-build /out/libsqlite3.so.0 /usr/local/lib/libsqlite3.so.0
RUN ldconfig
# Verification builds the KB sources too. They use PostgreSQL 17's asynchronous
# cancellation API, while Debian bookworm ships libpq 15 headers. Add the
# official PGDG repository and pin the verifier client/header family to the same
# current major used by the KB image without changing the production runtime's
# established Debian baseline.
ARG VERIFY_PG_MAJOR=18
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& install -d /usr/share/postgresql-common/pgdg \
&& for attempt in 1 2 3 4 5; do \
curl -fsS --connect-timeout 10 --max-time 60 \
-o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
https://www.postgresql.org/media/keys/ACCC4CF8.asc && break; \
echo "pgdg key fetch failed (attempt ${attempt}/5); backing off"; sleep $((attempt * 5)); \
done \
&& test -s /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
&& echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list \
&& rm -rf /var/lib/apt/lists/*
# Runtime shared libs the server links: libsqlite3 (the separate append-only
# audit WORM), libssl/libcrypto (crypto), libzstd + zlib (compression). DB1 is
# reached through the postgres module rather than linked into the server. The
# server reaches Postgres-backed KB_STORE
# only through aimee-kb, so it does not link libpq itself. curl is for the
# container HEALTHCHECK. libcrypt is retained only to verify a one-time migrated
# PAM hash; libpam0g remains in the Go binary's existing cgo link closure but no
# PAM login path is used. All current browser credentials live in Vault.
#
# The Go workflow engine runs repository verification after implementation.
# Keep the CI-equivalent native, Go, lint, and Python toolchain in the runtime
# image so repository verification does not fail merely because the
# control-plane image was slimmed after its own build stage.
#
# tmux + nodejs + npm are enablers for server-hosted OAuth CLI agents
# (`aimee agent add claude-oauth` / `codex-oauth`): the vendor CLI is installed on
# demand into the home-volume npm prefix (NPM_CONFIG_PREFIX below) and its OAuth
# login runs in a server-side tmux session. The vendor CLIs support the current
# Debian Node release (Node >= 18).
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
clang-format-19 \
curl \
git \
libcrypt1 \
libcurl4-openssl-dev \
libpam0g \
libpam0g-dev \
libp11-kit-dev \
libpq-dev \
libsqlite3-0 \
libsqlite3-dev \
libssl3 \
libssl-dev \
libzstd1 \
libzstd-dev \
nodejs \
npm \
openssh-client \
pkg-config \
"postgresql-client-${VERIFY_PG_MAJOR}" \
python3 \
python3-yaml \
ripgrep \
tini \
tmux \
zlib1g \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# `git verify` builds the repository's Go surfaces as well as its native ones.
# Copy the exact Go toolchain used for the WFE build instead of installing
# Debian bookworm's older golang-go package, which cannot load go 1.25 modules.
COPY --from=wfe-build /usr/local/go/ /usr/local/go/
# Docker CLI + compose plugin (static client binaries — no daemon). Lets
# aimee-server orchestrate the managed sibling service (aimee-kb)
# with `docker compose up -d` against a mounted host Docker socket, so
# the setup wizard can bring the stack up itself (server-orchestrated deploy). This
# is inert unless the deploy compose mounts /var/run/docker.sock and sets
# AIMEE_DEPLOY_ENABLED=1 (compose.server-managed.yaml); the plain image is
# unprivileged.
ARG TARGETARCH
ARG DOCKER_CLI_VERSION=27.5.1
ARG DOCKER_COMPOSE_VERSION=2.32.4
ARG DOCKER_CLI_SHA256_amd64=4f798b3ee1e0140eab5bf30b0edc4e84f4cdb53255a429dc3bbae9524845d640
ARG DOCKER_COMPOSE_SHA256_amd64=ed1917fb54db184192ea9d0717bcd59e3662ea79db48bff36d3475516c480a6b
RUN set -eux; \
case "${TARGETARCH:-amd64}" in \
amd64) darch=x86_64; carch=x86_64 ;; \
*) echo "unsupported TARGETARCH=${TARGETARCH}" >&2; exit 1 ;; \
esac; \
eval "docker_want=\${DOCKER_CLI_SHA256_${TARGETARCH:-amd64}}"; \
eval "compose_want=\${DOCKER_COMPOSE_SHA256_${TARGETARCH:-amd64}}"; \
curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors --retry-max-time 180 --connect-timeout 30 "https://download.docker.com/linux/static/stable/${darch}/docker-${DOCKER_CLI_VERSION}.tgz" -o /tmp/docker.tgz; \
echo "${docker_want} /tmp/docker.tgz" | sha256sum -c -; \
tar -xzf /tmp/docker.tgz -C /tmp docker/docker; \
install -m0755 /tmp/docker/docker /usr/local/bin/docker; \
rm -rf /tmp/docker; \
mkdir -p /usr/local/lib/docker/cli-plugins; \
curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors --retry-max-time 180 --connect-timeout 30 "https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${carch}" \
-o /usr/local/lib/docker/cli-plugins/docker-compose; \
echo "${compose_want} /usr/local/lib/docker/cli-plugins/docker-compose" | sha256sum -c -; \
chmod 0755 /usr/local/lib/docker/cli-plugins/docker-compose; \
docker --version; docker compose version
# GitHub CLI — backs the wizard's zero-config "Sign in with GitHub": when no
# OAuth App client ID is configured, aimee-server runs GitHub's device flow
# through `gh auth login` (gh's own public app identity), so sign-in works out
# of the box with no app registration (git_oauth_gh.c).
ARG GH_CLI_VERSION=2.96.0
ARG GH_CLI_SHA256_amd64=83d5c2ccad5498f58bf6368acb1ab32588cf43ab3a4b1c301bf36328b1c8bd60
RUN set -eux; \
gharch="${TARGETARCH:-amd64}"; \
case "$gharch" in amd64) ;; *) echo "unsupported TARGETARCH=${gharch}" >&2; exit 1 ;; esac; \
eval "want=\${GH_CLI_SHA256_${gharch}}"; \
curl -fsSL --retry 5 --retry-delay 3 --retry-all-errors --retry-max-time 180 --connect-timeout 30 "https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_linux_${gharch}.tar.gz" -o /tmp/gh.tar.gz; \
echo "${want} /tmp/gh.tar.gz" | sha256sum -c -; \
tar -xzf /tmp/gh.tar.gz -C /tmp "gh_${GH_CLI_VERSION}_linux_${gharch}/bin/gh"; \
install -m0755 "/tmp/gh_${GH_CLI_VERSION}_linux_${gharch}/bin/gh" /usr/local/bin/gh; \
rm -rf "/tmp/gh_${GH_CLI_VERSION}_linux_${gharch}"; \
gh --version
# ast-grep — the binary behind the ast_grep_search MCP tool.
#
# NOTHING installed it before, in this image or any deploy script, so the tool
# has never worked in a container. Worse than absent: `sg` is ALSO util-linux's
# set-group-ID command and is present on every Debian base, so the resolver used
# to find /usr/bin/sg, exec it with --json, capture its usage error as output,
# parse that as NDJSON, and answer "No matches found." An agent asking whether a
# pattern repeats was told no, authoritatively, on a machine where the search
# never ran.
#
# Installed ONLY as `ast-grep`, deliberately. The zip also contains an `sg`, but
# putting that in /usr/local/bin would shadow util-linux's sg for everything in
# the image, and aimee's resolver prefers the unambiguous name anyway -- so
# shadowing a system command would buy nothing and could break unrelated
# callers. The release ships a zip, so unzip is a build-time-only dependency.
# Release downloads go through GitHub/CDN edges that return 5xx in bursts: the
# first run of this step took six 503s inside twenty seconds while the same URL
# served 200 from elsewhere. The retry budget has to outlast a CDN wobble rather
# than a dropped packet, hence 8 attempts across 10 minutes with a 15s gap.
# --retry-all-errors is required because -f turns a 503 into exit 22, which plain
# --retry does NOT retry.
ARG AST_GREP_VERSION=0.45.1
ARG AST_GREP_SHA256_amd64=76fb6555be6734fb5057dba8d2fb756430f374bb9e1af694cf1ce00e13238d63
RUN set -eux; \
agarch="${TARGETARCH:-amd64}"; \
case "$agarch" in \
amd64) agtriple="x86_64-unknown-linux-gnu" ;; \
*) echo "unsupported TARGETARCH=${agarch}" >&2; exit 1 ;; \
esac; \
eval "want=\${AST_GREP_SHA256_${agarch}}"; \
apt-get update; \
apt-get install -y --no-install-recommends unzip; \
curl -fsSL --retry 8 --retry-delay 15 --retry-all-errors --retry-max-time 600 \
--connect-timeout 30 \
"https://github.com/ast-grep/ast-grep/releases/download/${AST_GREP_VERSION}/app-${agtriple}.zip" \
-o /tmp/ast-grep.zip; \
echo "${want} /tmp/ast-grep.zip" | sha256sum -c -; \
unzip -o /tmp/ast-grep.zip -d /tmp/ast-grep; \
install -m0755 /tmp/ast-grep/ast-grep /usr/local/bin/ast-grep; \
rm -rf /tmp/ast-grep /tmp/ast-grep.zip; \
apt-get purge -y unzip; \
apt-get autoremove -y; \
rm -rf /var/lib/apt/lists/*; \
# Prove it is really ast-grep and not the util-linux sg we just shadowed --
# the whole point of shipping it is that the resolver's --version check passes.
ast-grep --version | grep -q '^ast-grep '
# The managed compose the server launches for the orchestrated deploy (default
# AIMEE_DEPLOY_COMPOSE_FILE). Inert until AIMEE_DEPLOY_ENABLED=1 + a mounted socket.
COPY deploy/container/aimee-managed.compose.yaml /opt/aimee/deploy/aimee-managed.compose.yaml
# The embedder registry backs GET /v1/embedders — the setup wizard's page-2 picker.
# The wizard runs BEFORE anything is deployed, so the list cannot come from a running
# gateway; the server reads the same file the gateway and supervisor read.
COPY scripts/embedders.json /opt/aimee/embedders.json
ENV AIMEE_HOME=/var/lib/aimee
# On-demand-installed OAuth CLI agents (claude-code / codex) global-install here,
# on the persistent home volume, so the non-secret CLI binaries survive container
# recreate. OAuth credentials live only in Vault; per-session compatibility files
# are materialized beneath /run and removed with the session.
ENV NPM_CONFIG_PREFIX=/var/lib/aimee/.npm-global
ENV PATH=/var/lib/aimee/.npm-global/bin:/usr/local/go/bin:$PATH
# A host can verify several workflow branches simultaneously. Bound each
# verifier's native build and test fan-out so five workflows do not multiply the
# visible CPU count into hundreds of competing compiler/test processes.
ENV AIMEE_VERIFY_MAKE_JOBS=2
ENV AIMEE_VERIFY_TEST_JOBS=2
# claude-code self-updates on launch by default. In this npm-global-prefix layout
# its updater reinstalls the package WITHOUT re-running the install.cjs postinstall
# that fetches the platform-native binary, leaving an empty package dir and a
# dangling bin/claude symlink -> the launcher becomes "claude: not found" and every
# tmux-cli seat that runs it dies with "failed to send prompt to tmux session".
# aimee owns the pinned install + postinstall (server_cli_oauth.c); disable the
# vendor auto-updater so it cannot brick that install. aimee-server (the tmux
# server) exports this to every pane it spawns. Bind-mounted $AIMEE_HOME means the
# broken state would otherwise persist across container recreate.
ENV DISABLE_AUTOUPDATER=1
# Serve the /v1 HTTP API on 0.0.0.0 (the binary defaults to loopback) so the
# published container port reaches it. The bearer token in the baked aimee.yaml
# is still required on every request.
ENV AIMEE_SERVER_HTTP_BIND=1
# Keep the retired process-global authorizer pinned off. Remote write and control
# capabilities come from the caller's explicit identity grant; for the first
# wizard user that grant is bound to the enrolled mTLS certificate. The legacy
# setting remains parseable only so existing configurations still load.
ENV AIMEE_API_REMOTE_WRITES=off
# Request enrolled client certificates from the first connection even when a
# persisted config predates this setting. Bootstrap remains reachable while the
# listener is optional, then the durable roster promotes it to required mTLS.
ENV AIMEE_API_MTLS=optional
# Standalone by default: no kb configured. Point AIMEE_KB_API_URL at a running
# aimee-kb (e.g. http://aimee-kb:8741) to enable the shared/vector features.
# Mirror tier (workspace-resource-plane §3): the per-workspace bare mirrors +
# reconstructed worktrees live here instead of under AIMEE_HOME, so they sit on a
# dedicated durable volume (declared below) and survive container recreation —
# a detached server keeps its checkouts across restarts. These trees can be large
# and have a different backup lifecycle than DB1, hence a separate mount.
ENV AIMEE_WORKSPACES_DIR=/var/lib/aimee-workspaces
# aimee runs as uid 1000 so it can own its data on storage backends that present
# a uniform owner (e.g. SmoothNAS smoothfs tiers force uid 1000). The entrypoint
# stays root for legacy credential erasure, supervision, and the webchat's
# kernel-attested UDS identity; the server runs as this unprivileged user.
RUN useradd --uid 1000 --user-group --home-dir /var/lib/aimee --create-home --shell /usr/sbin/nologin aimee \
&& mkdir -p /var/lib/aimee-workspaces /mnt/media/cores \
&& chmod 1777 /mnt/media/cores \
&& chown aimee:aimee /var/lib/aimee-workspaces
# Durable mirror-tier state (AIMEE_WORKSPACES_DIR). Declaring it a VOLUME means an
# anonymous volume persists the checkouts across `docker run` recreations even
# when no named volume is mounted; operators can bind/name it for backups.
VOLUME /var/lib/aimee-workspaces /mnt/media/cores
COPY --from=build /src/aimee-server /usr/local/bin/aimee-server
COPY --from=build /src/aimee-kb /usr/local/bin/aimee-kb
COPY --from=build /src/aimee-kb-resolver /usr/local/bin/aimee-kb-resolver
# Memory executables, provisioning scripts and the two public catalog files the
# provisioning step reads; empty on a platform without a memory bundle.
COPY --from=build /memory-image/ /opt/aimee/memory/
COPY --chmod=0755 deploy/container/memory-provision.py /usr/local/bin/aimee-memory-provision
COPY --chmod=0755 deploy/container/memory-account-activate.py /usr/local/bin/aimee-memory-activate-account
COPY --chmod=0755 deploy/container/application-health.sh /usr/local/bin/aimee-application-health
COPY --from=build /src/aimee-kb-worm /usr/local/bin/aimee-kb-worm
COPY --from=build /module-runtime/bin/ /usr/local/libexec/aimee-modules/
COPY --from=build /module-runtime/grants/ /opt/aimee/module-grants/
COPY --from=build /module-runtime/server.modules /module-runtime/kb.modules /opt/aimee/module-grants/
COPY --from=wfe-build /out/aimee-wfe /usr/local/bin/aimee-wfe
COPY --from=wfe-build /out/aimee-delegate-egress /usr/local/bin/aimee-delegate-egress
# Static TCP<->UDS bridge; aimee-server docker-cp's it into a proxy-mode delegate sandbox.
COPY --from=build /src/aimee-forwarder /usr/local/bin/aimee-forwarder
# See the build stage: delegates reach aimee THROUGH this binary (`aimee mcp serve`
# as their MCP server, `aimee hooks pre` as their PreToolUse guard).
COPY --from=build /src/aimee /usr/local/bin/aimee
COPY --from=build /thinclient-build/libaimee-client.so /usr/local/lib/libaimee-client.so
# Co-located webchat browser UI: the Go service, the single-file React SPA, and
# Vault-only bootstrap/launch helpers. webchat shares
# AIMEE_HOME so its Unix-socket transports line up with the server.
# Optional webchat: /runtime-web is empty unless built with WITH_RUNTIME_WEB=1. Install
# the binary + SPA when present; the entrypoint skips the browser UI when absent.
COPY --from=runtime-web-stage /runtime-web/ /tmp/runtime-web-stage/
RUN if [ -f /tmp/runtime-web-stage/aimee-runtime-web ]; then \
install -m 0755 /tmp/runtime-web-stage/aimee-runtime-web /usr/local/bin/aimee-runtime-web; \
mkdir -p /usr/local/share/aimee-runtime-web; \
cp /tmp/runtime-web-stage/index.html /usr/local/share/aimee-runtime-web/index.html; \
echo "aimee: webchat bundled in image"; \
else echo "aimee: webchat not bundled (built with WITH_RUNTIME_WEB=0)"; fi; \
rm -rf /tmp/runtime-web-stage
# Optional code-server: /opt/codeserver/usr is empty unless WITH_VSCODE=1, so
# this COPY is a no-op in the default build. When present it lands code-server at
# /usr/bin/code-server; the webchat supervisor launches a per-user instance.
COPY --from=code-server-stage /opt/codeserver/usr/ /usr/
RUN if command -v code-server >/dev/null 2>&1; then echo "aimee: code-server bundled ($(code-server --version 2>/dev/null | head -1))"; else echo "aimee: code-server not bundled (built with WITH_VSCODE=0)"; fi
# PAM service for dashboard logins. runtime-web authenticates through
# smoothgui/auth against /etc/pam.d/<service>; with no file every login fails as
# "authentication unavailable".
COPY deploy/container/pam.d-aimee /etc/pam.d/aimee
COPY deploy/container/runtime-web-lib.sh /usr/local/bin/runtime-web-lib.sh
COPY deploy/container/optional-modules-lib.sh /usr/local/bin/optional-modules-lib.sh
COPY deploy/container/startup-failure-lib.sh /usr/local/bin/startup-failure-lib.sh
COPY deploy/container/plane-supervisor.sh /usr/local/bin/plane-supervisor.sh
COPY deploy/container/module-supervisor.sh /usr/local/bin/module-supervisor.sh
COPY deploy/container/core-storage.sh /usr/local/bin/core-storage.sh
COPY deploy/container/server-entrypoint.sh /usr/local/bin/aimee-server-entrypoint
COPY --chmod=0755 deploy/container/kb-role-runtime.sh /usr/local/bin/aimee-kb-role-runtime
RUN chmod +x /usr/local/bin/aimee-server-entrypoint \
/usr/local/bin/core-storage.sh /usr/local/bin/plane-supervisor.sh \
/usr/local/bin/module-supervisor.sh \
&& ldconfig
# Baked default config (enables the inbound /v1 HTTP listener: port + bearer).
# Kept OUTSIDE $AIMEE_HOME so a bind-mounted (empty) volume can't shadow it; the
# entrypoint seeds it into $AIMEE_HOME/aimee.yaml on first start.
COPY deploy/container/aimee-server.yaml /opt/aimee/defaults/aimee.yaml
# Default dev-lifecycle workflow(s) for autonomous development (default-on). The
# entrypoint seeds them into $AIMEE_HOME/workflows on first start.
COPY config/workflows/ /opt/aimee/defaults/workflows/
# Roundtable presets those workflows name. A roundtable review resolves only a
# saved roundtable, so a workflow gate cannot run until its preset exists. The
# entrypoint seeds them into $AIMEE_HOME/roundtables on first start.
COPY config/roundtables/ /opt/aimee/defaults/roundtables/
# Runs as root for legacy erasure, supervision, and webchat's kernel-attested UDS
# identity; aimee-server itself is dropped to the "aimee" user.
WORKDIR /var/lib/aimee
# 8740 = server /v1 (plaintext, loopback-only); 8743 = server /v1 over native TLS
# (the remote thin-client port); 8443 = aimee-runtime-web browser UI (HTTPS).
EXPOSE 8740 8743 8443
# NOTE: the server's worker threads need a 64 MB stack (the 8 MB container
# default overflows during startup and the process segfaults). The entrypoint
# raises the soft stack rlimit to 64 MB before launching the server, so no
# runtime --ulimit is required on hosts whose hard limit allows it (the usual
# case; hard stack defaults to unlimited). A runtime ulimit still works:
# docker run --ulimit stack=67108864 ... (mirrors systemd LimitSTACK)
# Readiness includes the browser's TLS listener when the dashboard is enabled.
HEALTHCHECK --interval=30s --timeout=7s --start-period=120s --retries=3 \
CMD /usr/local/bin/aimee-application-health
# The entrypoint must consume and unset first-boot credentials before tini
# becomes the long-lived PID-1 subreaper; it execs tini itself after that scrub.
ENTRYPOINT ["aimee-server-entrypoint"]