-
Notifications
You must be signed in to change notification settings - Fork 409
Expand file tree
/
Copy pathcompose.yaml
More file actions
761 lines (717 loc) · 28.6 KB
/
Copy pathcompose.yaml
File metadata and controls
761 lines (717 loc) · 28.6 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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# The install is this file plus .env, side by side, and nothing else.
#
# Everything .env pins is interpolated as ${VAR:?...}, so a missing or partial
# .env fails `docker compose config` and `up` at parse time, naming the
# variable. Without it Compose renders a blank image name or a blank kernel
# version and only warns, and the operator meets either a confusing "neither
# an image nor a build context" error or a fetch-artifacts failure after the
# host has already been mutated. The six knobs that are genuinely optional
# and are absent from .env (TEAM_API_KEY only as a commented line) keep the
# ${VAR:-...} form: HUGEPAGES, PF_MIN_FREE_GIB and FORCE_REBUILD carry a
# working default, while TEAM_API_KEY, ADMIN_TOKEN and
# SANDBOX_ACCESS_TOKEN_HASH_SEED carry none — the stack generates all three
# per install (seed for the key, api-secrets for the api's two), and a value
# set in .env or the shell overrides the generated one.
name: e2b
x-tools: &tools
image: ${E2B_TOOLS_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
x-node-e2b: &node-e2b
image: ${E2B_NODE_E2B_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
services:
postgres:
image: postgres:18.6-alpine
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
PGDATA: /var/lib/postgresql/18/docker
ports:
- "127.0.0.1:5432:5432"
volumes:
- postgres:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"]
interval: 5s
timeout: 3s
retries: 20
redis:
image: redis:7.4.6
restart: unless-stopped
ports:
- "127.0.0.1:6379:6379"
volumes:
- redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
clickhouse:
image: clickhouse/clickhouse-server:25.8.30.16
restart: unless-stopped
environment:
CLICKHOUSE_DB: default
CLICKHOUSE_USER: clickhouse
CLICKHOUSE_PASSWORD: clickhouse
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1"
# sha256 of config/clickhouse/config.xml, same purpose as
# VECTOR_CONFIG_SHA256 on the vector service.
CLICKHOUSE_CONFIG_SHA256: 48f50a1778bd986fdfb74c3f1e796816dbaa78d56c26443b604cbba205504f83
ports:
- "127.0.0.1:9000:9000"
- "127.0.0.1:8123:8123"
volumes:
- clickhouse:/var/lib/clickhouse
configs:
- source: clickhouse-config
target: /etc/clickhouse-server/config.d/config.xml
healthcheck:
test: ["CMD-SHELL", "clickhouse-client --user clickhouse --password clickhouse --query 'SELECT 1'"]
interval: 5s
timeout: 3s
retries: 30
vector:
image: timberio/vector:0.51.1-alpine
restart: unless-stopped
depends_on:
clickhouse:
condition: service_healthy
environment:
VECTOR_CONFIG: /etc/vector/vector.toml
VECTOR_LOG: warn
# sha256 of config/vector/vector.toml. Inert for Vector; it makes the
# service hash change with the inline config so `up` recreates the
# container (compose does not hash `configs:` content). Kept in step by
# tests/config-hashes.bats.
VECTOR_CONFIG_SHA256: a4ca48367c4ae06f81fa08d9f8cbcace70f25a631f00496a44d96282e469b7a3
ports:
- "127.0.0.1:30006:30006"
configs:
- source: vector-config
target: /etc/vector/vector.toml
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:44313/health >/dev/null"]
interval: 10s
timeout: 2s
retries: 12
db-migrator:
image: ${E2B_DB_MIGRATOR_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
restart: "no"
depends_on:
postgres:
condition: service_healthy
environment:
POSTGRES_CONNECTION_STRING: postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
clickhouse-migrator:
image: ${E2B_CLICKHOUSE_MIGRATOR_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
restart: "no"
depends_on:
clickhouse:
condition: service_healthy
environment:
GOOSE_DBSTRING: clickhouse://clickhouse:clickhouse@clickhouse:9000/default
seed:
image: ${E2B_SEED_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
restart: "no"
depends_on:
db-migrator:
condition: service_completed_successfully
environment:
POSTGRES_CONNECTION_STRING: postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
OIDC_ISSUER: http://localhost:4444/
OIDC_SUBJECT: local-dev-user
# The team API key is per install. The seed generates one on the first
# run and keeps it in the seed-state volume, where a re-run finds it again
# and base-template, smoke and ready read it. TEAM_API_KEY in .env or the
# shell (e2b_ plus at least 32 hex characters) pins it instead, and
# changing it later rotates: the next up inserts the new key and revokes
# the seed's earlier one (the api's team-auth cache keeps the old key
# working for up to five minutes). Removing the key file, or `down -v`,
# which drops the volume with the databases, makes the next up generate
# a fresh key the same way.
SEED_TEAM_API_KEY: ${TEAM_API_KEY:-random}
SEED_TEAM_API_KEY_FILE: /run/e2b/team-api-key
volumes:
- seed-state:/run/e2b
preflight:
<<: *tools
restart: "no"
network_mode: host
pid: host
privileged: true
environment:
PF_MIN_FREE_GIB: ${PF_MIN_FREE_GIB:-20}
command: ["/bin/sh", "-c", "exec nsenter -t 1 -m -u -i -n -p -- /bin/bash -s < /opt/e2b/scripts/preflight.sh"]
host-setup:
<<: *tools
restart: "no"
network_mode: host
pid: host
privileged: true
depends_on:
preflight:
condition: service_completed_successfully
environment:
HUGEPAGES: ${HUGEPAGES:-2048}
command: ["/bin/sh", "-c", "exec nsenter -t 1 -m -u -i -n -p -- /bin/bash -s < /opt/e2b/scripts/host-setup.sh"]
fetch-artifacts:
<<: *tools
restart: "no"
network_mode: host
depends_on:
host-setup:
condition: service_completed_successfully
environment:
HOST_ROOT: /host
E2B_ORCHESTRATOR_VERSION: ${E2B_ORCHESTRATOR_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
E2B_ENVD_VERSION: ${E2B_ENVD_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
E2B_KERNEL_VERSION: ${E2B_KERNEL_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
E2B_FIRECRACKER_VERSION: ${E2B_FIRECRACKER_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
E2B_BUSYBOX_VERSION: ${E2B_BUSYBOX_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
volumes:
- /:/host
command: ["/bin/bash", "/opt/e2b/scripts/fetch-artifacts.sh"]
# The api's two secrets are per install, the way the team API key is. This
# generates both on the first start and keeps them in the seed-state volume,
# where a re-run finds them again and the api's entrypoint reads them.
# ADMIN_TOKEN or SANDBOX_ACCESS_TOKEN_HASH_SEED in .env or the shell
# overrides one of them without touching the other. Removing the file, or
# `down -v`, which drops the volume with the databases, makes the next up
# generate a fresh pair: a new hash seed invalidates the tokens of running
# `secure` sandboxes and a new admin token invalidates admin clients.
# preflight is the only gate — nothing here touches the host, so the pair is
# written long before the api needs it — and the values are never printed.
api-secrets:
<<: *tools
restart: "no"
depends_on:
preflight:
condition: service_completed_successfully
volumes:
- seed-state:/run/e2b
command:
- /bin/sh
- -c
- |
set -eu
if [ -s /run/e2b/api.env ]; then
echo "api-secrets: reusing /run/e2b/api.env"
exit 0
fi
umask 077
hex() { head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n'; }
tmp=/run/e2b/api.env.tmp
printf 'GEN_ADMIN_TOKEN=%s\nGEN_SANDBOX_ACCESS_TOKEN_HASH_SEED=%s\n' \
"$$(hex)" "$$(hex)" > "$$tmp"
chmod 600 "$$tmp"
mv "$$tmp" /run/e2b/api.env
echo "api-secrets: generated /run/e2b/api.env"
orchestrator:
<<: *tools
restart: unless-stopped
network_mode: host
pid: host
cgroup: host
privileged: true
environment:
ORCHESTRATOR_SERVICES: orchestrator,template-manager
NODE_ID: orchestrator
NODE_IP: 127.0.0.1
ENVIRONMENT: local
GRPC_PORT: "5008"
PROXY_PORT: "5007"
PPROF_PORT: "6061"
REDIS_URL: 127.0.0.1:6379
CLICKHOUSE_CONNECTION_STRING: clickhouse://clickhouse:clickhouse@127.0.0.1:9000/default
LOGS_COLLECTOR_ADDRESS: http://127.0.0.1:30006
TEMPLATE_STORAGE_URL: file:///var/lib/e2b/storage/templates
BUILD_CACHE_STORAGE_URL: file:///var/lib/e2b/storage/build-cache
ARTIFACTS_REGISTRY_PROVIDER: Local
LOCAL_UPLOAD_BASE_URL: http://127.0.0.1:5008
FIRECRACKER_VERSIONS_DIR: /fc-versions
HOST_KERNELS_DIR: /fc-kernels
HOST_BUSYBOX_DIR: /fc-busybox
BUSYBOX_VERSION: ${E2B_BUSYBOX_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
HOST_ENVD_PATH: /fc-envd/envd
ORCHESTRATOR_BASE_PATH: /orchestrator
SANDBOX_DIR: /fc-vm
NBD_POOL_SIZE: "64"
NETWORK_VERSION: "1"
DEFAULT_KERNEL_VERSION: ${E2B_KERNEL_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
DEFAULT_FIRECRACKER_VERSION: ${E2B_FIRECRACKER_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
depends_on:
fetch-artifacts:
condition: service_completed_successfully
clickhouse-migrator:
condition: service_completed_successfully
redis:
condition: service_healthy
vector:
condition: service_healthy
# orchestrator-launch.sh is PID 1: it sweeps sandbox cgroups on SIGTERM,
# because Compose pre_stop hooks do not fire and the orchestrator itself
# only drains. It sweeps again when the binary dies on its own, so the
# restart policy above cannot bring up a fresh orchestrator beside a
# crashed one's Firecrackers. See scripts/orchestrator-launch.sh.
command: ["/bin/bash", "/opt/e2b/scripts/orchestrator-launch.sh"]
stop_grace_period: 60s
healthcheck:
test: ["CMD-SHELL", "curl -sf --max-time 2 http://127.0.0.1:5008/health"]
interval: 10s
timeout: 3s
retries: 60
start_period: 30s
api:
image: ${E2B_API_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
restart: unless-stopped
network_mode: host
environment:
# Empty means the operator set neither: api-secrets generated a value
# per install for each and the entrypoint below fills it in. A value in
# .env or the shell arrives here and wins, one variable at a time. The
# team API key is per install the same way (seed service above).
ADMIN_TOKEN: ${ADMIN_TOKEN:-}
SANDBOX_ACCESS_TOKEN_HASH_SEED: ${SANDBOX_ACCESS_TOKEN_HASH_SEED:-}
NODE_ID: api
ENVIRONMENT: local
SERVICE_DISCOVERY_PROVIDER: local
LOCAL_ORCHESTRATOR_ADDRESS: 127.0.0.1:5008
POSTGRES_CONNECTION_STRING: postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable
REDIS_URL: 127.0.0.1:6379
CLICKHOUSE_CONNECTION_STRING: clickhouse://clickhouse:clickhouse@127.0.0.1:9000/default
# Sandbox and build logs are read from ClickHouse.
# LOGS_READ_CONFIG fixes the api's logs-read-config flag, which has no
# LaunchDarkly to come from here, and the api runs without LOKI_URL.
# Both arrived with api v0.11.0; v0.8.0 exits on the missing
# LOKI_URL, and tests/pins.bats refuses that pin.
LOGS_READ_CONFIG: "true"
LOGS_COLLECTOR_ADDRESS: http://127.0.0.1:30006
API_INTERNAL_GRPC_PORT: "5009"
API_EDGE_GRPC_PORT: "5109"
PPROF_PORT: "6060"
VOLUME_TOKEN_ENABLED: "false"
AUTH_PROVIDER_CONFIG: '{"jwt":[]}'
DEFAULT_KERNEL_VERSION: ${E2B_KERNEL_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
DEFAULT_FIRECRACKER_VERSION: ${E2B_FIRECRACKER_VERSION:?fetch the .env that ships beside compose.yaml (README, Install)}
env_file:
# optional additional api variables (git-ignored); keys already set above
# cannot be overridden here — change them in compose.yaml, or for
# ADMIN_TOKEN / SANDBOX_ACCESS_TOKEN_HASH_SEED in .env or the shell
# (both are generated per install when unset).
#
# Do not simplify this to the short `- env/api.local.env` form. The long
# `path:`/`required:` syntax is the file's own enforcement of the Compose
# 2.24 floor: 2.23 and older reject `required:` at
# parse time, before anything starts, which turns the documented floor
# into an error message instead of a silent misbehaviour in `--wait`.
# The short form would also make the file mandatory, so a two-file
# install with no env/ directory would fail on every `up`.
- path: env/api.local.env
required: false
volumes:
- seed-state:/run/e2b:ro
# The image's entrypoint is ./api; this wrapper runs it with whichever of
# the two secrets the operator left unset filled in from the file
# api-secrets wrote, which Compose cannot read into a variable itself.
# `sh -c` takes the word after the script as $0, hence the "api"
# placeholder at the end: without it the first word of `command:` below
# would become $0 and never reach the binary. `exec` keeps the api as
# PID 1, so signals and its exit code pass through. Debugging with a
# shell now needs the entrypoint named explicitly, as in
# `docker compose run --rm --entrypoint sh api`.
entrypoint:
- sh
- -c
- |
test -s /run/e2b/api.env || {
echo "api: api-secrets left no /run/e2b/api.env" >&2
echo "FIX: run docker compose up api-secrets and read its output" >&2
exit 1
}
. /run/e2b/api.env
[ -n "$${GEN_ADMIN_TOKEN:-}" ] && [ -n "$${GEN_SANDBOX_ACCESS_TOKEN_HASH_SEED:-}" ] || {
echo "api: /run/e2b/api.env is incomplete" >&2
echo "FIX: docker compose run --rm --no-deps --entrypoint rm api-secrets /run/e2b/api.env, then docker compose up -d" >&2
exit 1
}
export ADMIN_TOKEN="$${ADMIN_TOKEN:-$$GEN_ADMIN_TOKEN}"
export SANDBOX_ACCESS_TOKEN_HASH_SEED="$${SANDBOX_ACCESS_TOKEN_HASH_SEED:-$$GEN_SANDBOX_ACCESS_TOKEN_HASH_SEED}"
exec ./api "$$@"
- api
command: ["--port", "3000"]
depends_on:
api-secrets:
condition: service_completed_successfully
seed:
condition: service_completed_successfully
orchestrator:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/health >/dev/null"]
interval: 10s
timeout: 3s
retries: 30
start_period: 20s
client-proxy:
image: ${E2B_CLIENT_PROXY_IMAGE:?fetch the .env that ships beside compose.yaml (README, Install)}
restart: unless-stopped
network_mode: host
environment:
NODE_ID: client-proxy
ENVIRONMENT: local
REDIS_URL: 127.0.0.1:6379
API_INTERNAL_GRPC_ADDRESS: 127.0.0.1:5009
PROXY_PORT: "3002"
HEALTH_PORT: "3003"
depends_on:
api:
condition: service_healthy
stop_grace_period: 90s
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3003/ >/dev/null"]
interval: 10s
timeout: 3s
retries: 12
start_period: 5s
# Starts once the base template exists and client-proxy is healthy, prints the
# SDK variables and idles. It is the always-on dependent that makes
# `docker compose up -d --wait` wait for the template build (Compose waits
# for a one-shot as "completed" only when an active service depends on it),
# and the one service whose presence means "the stack is usable".
ready:
<<: *tools
restart: unless-stopped
network_mode: host
depends_on:
base-template:
condition: service_completed_successfully
client-proxy:
condition: service_healthy
volumes:
- seed-state:/run/e2b
# /run/e2b/sdk.env holds the three exports for this install, so a shell
# can take them with: eval "$(docker compose exec ready cat /run/e2b/sdk.env)"
# It is re-rendered whenever the seed rotates the key (TEAM_API_KEY changed
# or the key file removed, then `up`): `up` re-runs the seed but does not
# recreate this service, so a one-shot render would go stale.
command:
- /bin/sh
- -c
- |
E2B_HOST=localhost
LOG_HINT='docker compose logs seed'
EPILOGUE='Same, in one line: eval "$$(docker compose exec ready cat /run/e2b/sdk.env)"
Smoke test: docker compose --profile test run --rm smoke
Tear down, in this order:
1. docker compose down (keeps data and /var/lib/e2b)
2. docker compose down -v (also drops the databases)
3. then and only then, to undo the host changes:
docker compose --profile purge run --rm host-teardown
(refuses to run while the orchestrator is up, so it needs step 2 first)'
test -s /run/e2b/team-api-key || {
echo "ready: the seed left no /run/e2b/team-api-key" >&2
echo "FIX: E2B_SEED_IMAGE must be a release whose seed knows SEED_TEAM_API_KEY_FILE (the published seed images do); run $$LOG_HINT" >&2
exit 1
}
last=""
while :; do
key="$$(cat /run/e2b/team-api-key 2>/dev/null)"
if [ -n "$$key" ] && [ "$$key" != "$$last" ]; then
printf 'export E2B_API_KEY=%s\nexport E2B_API_URL=http://%s:3000\nexport E2B_SANDBOX_URL=http://%s:3002\n' "$$key" "$$E2B_HOST" "$$E2B_HOST" > /run/e2b/sdk.env
if [ -z "$$last" ]; then
echo "E2B stack is up. Point the SDK at it (this install's own key):"
else
echo "Team API key rotated; the earlier key stops working within five minutes. The SDK variables are now:"
fi
sed 's/^/ /' /run/e2b/sdk.env
if [ -z "$$last" ]; then
printf '%s\n' "$$EPILOGUE"
fi
last="$$key"
fi
sleep 5
done
base-template:
<<: *node-e2b
restart: "no"
network_mode: host
environment:
E2B_API_URL: http://127.0.0.1:3000
FORCE_REBUILD: ${FORCE_REBUILD:-0}
volumes:
- seed-state:/run/e2b
depends_on:
api:
condition: service_healthy
# Direct, not only through api: on a rotation `up` api is already healthy,
# and without this edge base-template would race the re-run seed for the
# key file and fail with the message meant for an old seed image.
seed:
condition: service_completed_successfully
command:
- /bin/sh
- -c
- |
test -s /run/e2b/team-api-key || {
echo "build-base-template: the seed left no /run/e2b/team-api-key" >&2
echo "FIX: E2B_SEED_IMAGE must be a release whose seed knows SEED_TEAM_API_KEY_FILE (the published seed images do); run docker compose logs seed" >&2
exit 2
}
E2B_API_KEY="$$(cat /run/e2b/team-api-key)" exec node /app/build-base-template.mjs
smoke:
<<: *node-e2b
profiles: [test]
restart: "no"
network_mode: host
environment:
E2B_API_URL: http://127.0.0.1:3000
E2B_SANDBOX_URL: http://127.0.0.1:3002
volumes:
- seed-state:/run/e2b
depends_on:
base-template:
condition: service_completed_successfully
client-proxy:
condition: service_healthy
command:
- /bin/sh
- -c
- |
test -s /run/e2b/team-api-key || {
echo "smoke: the seed left no /run/e2b/team-api-key" >&2
echo "FIX: E2B_SEED_IMAGE must be a release whose seed knows SEED_TEAM_API_KEY_FILE (the published seed images do); run docker compose logs seed" >&2
exit 2
}
E2B_API_KEY="$$(cat /run/e2b/team-api-key)" exec node /app/smoke.mjs
host-teardown:
<<: *tools
profiles: [purge]
restart: "no"
network_mode: host
pid: host
cgroup: host
privileged: true
command: ["/bin/sh", "-c", "exec nsenter -t 1 -m -u -i -n -p -C -- /bin/bash -s < /opt/e2b/scripts/host-teardown.sh"]
volumes:
postgres:
# Only the five-minute team cache lives here, so nothing is lost either way.
# The name is what makes `down -v` collect it: the image declares
# VOLUME /data, so without one every container takes an anonymous volume,
# and `down` before `down -v` strands one of those per install-remove cycle.
redis:
clickhouse:
# The seed's team API key, the api secrets api-secrets writes beside it and
# ready's sdk.env derived from the key. `down -v` drops it together with the
# databases, so the secrets and the database stay in step.
seed-state:
configs:
clickhouse-config:
content: |-
<?xml version="1.0"?>
<clickhouse>
<!-- this is undocumented but needed to enable waiting for for shutdown for a custom amount of time -->
<!-- see https://github.com/ClickHouse/ClickHouse/pull/77515 for more details -->
<shutdown_wait_unfinished>60</shutdown_wait_unfinished>
<shutdown_wait_unfinished_queries>1</shutdown_wait_unfinished_queries>
<!-- Use up 80% of available RAM to be on the safer side, default is 90% -->
<max_server_memory_usage_to_ram_ratio>0.8</max_server_memory_usage_to_ram_ratio>
<default_replica_path>/var/lib/clickhouse/tables/{shard}/{database}/{table}</default_replica_path>
<remote_servers replace="true">
<cluster>
<shard>
<replica>
<host>localhost</host>
<port>9000</port>
<user>clickhouse</user>
<password>clickhouse</password>
</replica>
</shard>
</cluster>
</remote_servers>
<listen_host>0.0.0.0</listen_host>
<tcp_port>9000</tcp_port>
</clickhouse>
vector-config:
content: |
data_dir = "alloc/data/vector/"
[api]
enabled = true
address = "0.0.0.0:44313"
[sources.http_server]
type = "http_server"
address = "0.0.0.0:30006"
encoding = "ndjson"
path_key = "_path"
[transforms.add_source_http_server]
type = "remap"
inputs = ["http_server"]
source = """
del(."_path")
if (!exists(.sandboxID) || .sandboxID == null) && exists(.instanceID) && .instanceID != null {
.sandboxID = .instanceID
}
.timestamp = parse_timestamp(.timestamp, format: "%+") ?? now()
# Normalize keys
if exists(.sandbox_id) {
.sandboxID = .sandbox_id
}
if exists(.build_id) {
.buildID = .build_id
}
if exists(.env_id) {
.envID = .env_id
}
if exists(.team_id) {
.teamID = .team_id
}
if exists(."template.id") {
.templateID = ."template.id"
del(."template.id")
}
if exists(."sandbox.id") {
.sandboxID = ."sandbox.id"
del(."sandbox.id")
}
if exists(."build.id") {
.buildID = ."build.id"
del(."build.id")
}
if exists(."env.id") {
.envID = ."env.id"
del(."env.id")
}
if exists(."team.id") {
.teamID = ."team.id"
del(."team.id")
}
# Apply defaults if not already set
if !exists(.envID) {
.envID = "unknown"
}
if !exists(.category) {
.category = "default"
}
if !exists(.teamID) {
.teamID = "unknown"
}
if !exists(.sandboxID) {
.sandboxID = "unknown"
}
if !exists(.buildID) {
.buildID = "unknown"
}
if !exists(.service) {
if exists(.service_name) && .service_name != null {
.service = .service_name
} else {
.service = "envd"
}
}
"""
[transforms.internal_routing]
type = "route"
inputs = [ "add_source_http_server" ]
[transforms.internal_routing.route]
internal = '.internal == true'
[transforms.remove_internal]
type = "remap"
inputs = [ "internal_routing._unmatched" ]
source = '''
del(.internal)
'''
# Enable debugging of logs to the console
# [sinks.console_logs]
# type = "console"
# inputs = ["remove_internal"]
# encoding.codec = "json"
# One row of the ClickHouse `sandbox_logs` table per line, the same eleven
# columns and the same rules as the collector that writes it in E2B's own
# deployments. The api reads this table for sandbox and template-build logs
# (LOGS_READ_CONFIG=true); there is no Loki in this stack.
# Rows are dropped when the team id is not a UUID, or when a line has no
# sandbox id unless it is a template-manager build line, which the api looks
# up by template and build id and stores under the "unknown" sandbox.
[transforms.sandbox_logs_rows]
type = "remap"
inputs = [ "remove_internal" ]
drop_on_error = true
drop_on_abort = true
source = '''
raw = encode_json(.)
# A UUID, or the row is dropped. The regex has no end anchor on purpose: compose
# interpolation would need that character doubled in the inline copy of this
# file, so the length check closes the match instead.
team_id = string(.teamID) ?? ""
if length(team_id) != 36 || !match(team_id, r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}') {
abort
}
service = string(.service) ?? ""
if service == "" { service = string(.service_name) ?? "" }
if service == "" { service = "envd" }
category = string(.category) ?? ""
if category == "" { category = "default" }
template_id = string(.template_id) ?? ""
if template_id == "" { template_id = string(.templateID) ?? "" }
if template_id == "" { template_id = string(.envID) ?? "" }
if template_id == "unknown" { template_id = "" }
build_id = string(.buildID) ?? ""
if build_id == "unknown" { build_id = "" }
sandbox_id = string(.sandbox_id) ?? ""
if sandbox_id == "" { sandbox_id = string(.sandboxID) ?? "" }
if sandbox_id == "" { sandbox_id = string(.instanceID) ?? "" }
if sandbox_id == "" || sandbox_id == "unknown" {
if service != "template-manager" || build_id == "" { abort }
sandbox_id = "unknown"
}
message = string(.message) ?? ""
if message == "" { message = raw }
level = downcase(string(.level) ?? "")
# sandbox_logs.timestamp is DateTime64(9), 1900-01-01 to 2262-04-11. A producer
# clock outside that range would make ClickHouse reject the whole batch, which
# the sink retries forever and every later line waits behind; such a line keeps
# its content and takes the collector's time.
ts = timestamp(.timestamp) ?? now()
secs = to_unix_timestamp(ts)
if secs > 9223372036 || secs < -2208988800 {
ts = now()
}
promoted = ["timestamp", "message", "level", "team_id", "teamID", "sandbox_id", "sandboxID", "instanceID",
"template_id", "templateID", "envID", "env_id", "build_id", "buildID", "service", "service_name", "category"]
fields = {}
for_each(object(.)) -> |key, value| {
if !includes(promoted, key) {
fields = set!(fields, [key], to_string(value) ?? encode_json(value))
}
}
. = {
"timestamp": ts,
"team_id": team_id,
"sandbox_id": sandbox_id,
"template_id": template_id,
"build_id": build_id,
"service": service,
"category": category,
"level": level,
"message": message,
"raw": raw,
"fields": encode_json(fields),
}
'''
[sinks.clickhouse_sandbox_logs]
type = "clickhouse"
inputs = [ "sandbox_logs_rows" ]
endpoint = "http://clickhouse:8123"
database = "default"
table = "sandbox_logs"
auth.strategy = "basic"
auth.user = "clickhouse"
auth.password = "clickhouse"
# The row carries an RFC 3339 timestamp; ClickHouse parses it into
# DateTime64(9) with best-effort date/time input. Unknown keys are refused by
# design (the remap emits exactly the table's columns), so skipping them would
# only hide a bug.
date_time_best_effort = true
skip_unknown_fields = false
compression = "gzip"
batch.timeout_secs = 1