Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / infra / agents / compose.yml

compose.yml211 lines · 7.4 KiBRaw
1# Compose project `agents`: on-server coding-agent sandbox + orchestrator.
2#
3# Coexists with the prod `location-share` project (server, caddy, watcher):
4# nothing here touches that project, its containers, or its volumes. The only
5# shared state is read-only: the `location-share_srv-data` volume (release
6# lock file) and the external `location-share_default` network (agentd gets
7# the `agents-ui` alias on it so Caddy can route agents.maproj.org).
8#
9# Disk bounding: the toolchain/cache/slot volumes live inside
10# /root/agent-world/builds (a size-bounded loop-mounted ext4 image created by
11# host-setup.sh). Named volumes with local-driver bind options are used
12# instead of plain bind mounts so that on first use Docker seeds /cargo-home
13# and /opt/android-sdk from the builder image (plain binds would hide the
14# image content behind empty host dirs).
15#
16# Run from the deploy checkout (/root/agent-world/Modern-Apps):
17# docker compose -p agents -f infra/agents/compose.yml up -d --build
18
19name: agents
20
21services:
22 # One-shot (runs once per `up`, as root): verifies the image-seeded
23 # toolchain volumes arrived, installs gradle.properties, fixes ownership.
24 builder-init:
25 build:
26 context: .
27 dockerfile: Dockerfile.builder
28 image: agents-builder:local
29 pull_policy: build
30 user: root
31 # The image ENTRYPOINT runs the runner; override it: init runs a shell
32 # script instead (compose `command` alone would only replace CMD args).
33 entrypoint: ["/bin/bash"]
34 volumes:
35 - gradle-cache:/gradle-cache
36 - cargo-home:/cargo-home
37 - android-sdk:/opt/android-sdk
38 - slots:/builds/slots
39 command:
40 - -c
41 - |
42 set -euo pipefail
43 for d in /gradle-cache /builds/slots; do
44 test -e "$$d/.on-loop-fs" || { echo "builder-init: FATAL: $$d is not on the bounded loop fs (run host-setup.sh / mount /root/agent-world/builds)" >&2; exit 1; }
45 done
46 DEV=$$(stat -c %d /gradle-cache)
47 for d in /cargo-home /opt/android-sdk /builds/slots; do
48 [ "$$(stat -c %d "$$d")" = "$$DEV" ] || { echo "builder-init: FATAL: $$d is not on the same bounded fs as /gradle-cache" >&2; exit 1; }
49 done
50 MARKER=/gradle-cache/.agents-init-done
51 if [ -e "$$MARKER" ]; then echo "builder-init: already done, skipping"; exit 0; fi
52 test -x /cargo-home/bin/cargo || { echo "builder-init: FATAL: /cargo-home/bin/cargo missing (image seeding of the cargo-home volume did not happen)" >&2; exit 1; }
53 test -d /opt/android-sdk/ndk/29.0.14206865 || { echo "builder-init: FATAL: /opt/android-sdk/ndk/29.0.14206865 missing (image seeding of the android-sdk volume did not happen)" >&2; exit 1; }
54 cp /opt/agent/gradle.properties /gradle-cache/gradle.properties
55 chown -R 10001:10001 /gradle-cache /cargo-home /opt/android-sdk /builds/slots
56 touch "$$MARKER"
57 echo "builder-init: done"
58 networks:
59 - agents-internal
60 restart: "no"
61
62 # The sandbox: agent-runner as uid/gid 10001, capped well below the box so
63 # the live server keeps headroom (box: 8 vCPU / 31 GiB; releases cap at
64 # 5 CPU / 20 GB — never run an agent build during a release build).
65 builder:
66 build:
67 context: .
68 dockerfile: Dockerfile.builder
69 image: agents-builder:local
70 pull_policy: build
71 user: "10001:10001"
72 depends_on:
73 builder-init:
74 condition: service_completed_successfully
75 cpus: 6
76 mem_limit: 14g
77 memswap_limit: 16g
78 pids_limit: 4096
79 cpu_shares: 256
80 # No `no-new-privileges`: under snap Docker's AppArmor confinement it makes
81 # every exec fail with EPERM. Equivalent protection comes from cap_drop ALL
82 # + non-root uid + an image with all setuid/setgid bits stripped.
83 cap_drop:
84 - ALL
85 restart: unless-stopped
86 environment:
87 RUNNER_LISTEN: "0.0.0.0:7070"
88 RUNNER_SLOTS: "4"
89 RUNNER_SLOTS_DIR: /builds/slots
90 RUNNER_MIRROR: /mirror/Modern-Apps.git
91 volumes:
92 - gradle-cache:/gradle-cache
93 - cargo-home:/cargo-home
94 - android-sdk:/opt/android-sdk
95 - slots:/builds/slots
96 - agents-mirror:/mirror:ro
97 networks:
98 - agents-internal
99 - agents-egress
100
101 # The trusted orchestrator (another agent owns Dockerfile.agentd): talks to
102 # the sandbox over agents-internal, serves the UI on location-share_default
103 # as `agents-ui`, pushes via the mirror volume.
104 agentd:
105 build:
106 context: .
107 dockerfile: Dockerfile.agentd
108 image: agents-agentd:local
109 pull_policy: build
110 env_file:
111 - /root/agent-world/.env
112 environment:
113 AGENTD_RUNNER_URL: http://builder:7070
114 AGENTD_STATE_DIR: /state
115 AGENTD_MIRROR_DIR: /mirror/Modern-Apps.git
116 AGENTD_RELEASE_SIGNAL: /signal/release
117 AGENTD_LISTEN: "0.0.0.0:8080"
118 AGENTD_SLOTS: "4"
119 volumes:
120 - agents-state:/state
121 - agents-mirror:/mirror
122 - agents-signal:/signal:ro
123 mem_limit: 1g
124 # See builder: no-new-privileges breaks exec under snap Docker.
125 cap_drop:
126 - ALL
127 restart: unless-stopped
128 networks:
129 agents-internal:
130 location-share_default:
131 aliases:
132 - agents-ui
133
134 # Mirrors the prod release lock into the agents world every 5s so agentd
135 # can defer builds while a release runs. Watched path overridable for
136 # testing via RELEASE_LOCK_FILE.
137 release-signal:
138 image: alpine:3.21
139 environment:
140 RELEASE_LOCK_FILE: /srv/release_in_progress
141 volumes:
142 - location-share_srv-data:/srv:ro
143 - agents-signal:/signal
144 command:
145 - /bin/sh
146 - -c
147 - |
148 LOCK="$${RELEASE_LOCK_FILE:-/srv/release_in_progress}";
149 while true; do
150 if [ -e "$$LOCK" ]; then touch /signal/release; else rm -f /signal/release; fi;
151 sleep 5;
152 done
153 network_mode: none
154 mem_limit: 32m
155 cap_drop:
156 - ALL
157 restart: unless-stopped
158
159volumes:
160 # Toolchain/cache/slot data, bounded by the /root/agent-world/builds ext4
161 # image. Bind-backed named volumes: Docker seeds image content
162 # (/cargo-home toolchain, /opt/android-sdk) into them on first use.
163 gradle-cache:
164 driver: local
165 driver_opts:
166 type: none
167 o: bind
168 device: /root/agent-world/builds/gradle-cache
169 cargo-home:
170 driver: local
171 driver_opts:
172 type: none
173 o: bind
174 device: /root/agent-world/builds/cargo-home
175 android-sdk:
176 driver: local
177 driver_opts:
178 type: none
179 o: bind
180 device: /root/agent-world/builds/android-sdk
181 slots:
182 driver: local
183 driver_opts:
184 type: none
185 o: bind
186 device: /root/agent-world/builds/slots
187 # agentd-owned: mirror checkout, persistent state, release signal flag.
188 agents-mirror:
189 agents-state:
190 agents-signal:
191 # Prod server state (external): release-signal reads only the
192 # release_in_progress lock file from it. Must be declared external —
193 # otherwise compose would create an empty project-scoped volume of the
194 # same name instead of attaching the prod one.
195 location-share_srv-data:
196 external: true
197
198networks:
199 # Sandbox <-> agentd only. No route out (egress goes via agents-egress,
200 # which the host firewall constrains).
201 agents-internal:
202 internal: true
203 # Sandbox egress with a pinned subnet the host firewall rules reference.
204 agents-egress:
205 driver: bridge
206 ipam:
207 config:
208 - subnet: 172.31.250.0/24
209 # Prod stack network (external): agentd serves the UI here as `agents-ui`.
210 location-share_default:
211 external: true