Skip to content

feat(cloudflare): run DO-attached containers in alchemy dev#584

Draft
Butch78 wants to merge 2 commits into
alchemy-run:mainfrom
Butch78:feat/dev-local-containers
Draft

feat(cloudflare): run DO-attached containers in alchemy dev#584
Butch78 wants to merge 2 commits into
alchemy-run:mainfrom
Butch78:feat/dev-local-containers

Conversation

@Butch78

@Butch78 Butch78 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Run Durable-Object-attached containers under alchemy dev, using workerd's native container support against the local Docker daemon (what wrangler dev / miniflare do).

A worker binds a container class to a DO namespace with an image name; locally that image is started per DO instance and exposed as ctx.container:

yield* worker.bind`my-container`({
  containers: [{ className: "MyDo", imageName: "my-image:dev" }],
});
  • containers binding data gains an optional imageName; entries without one are remote-only attachments and are ignored locally (ctx.container stays absent)
  • LocalWorkerProvider maps className -> imageName from binding data, attaches container: { imageName } to the matching workerd DO namespace, and configures a localDocker container engine (socket unix:///var/run/docker.sock)
  • The egress-interceptor sidecar image defaults to the same pinned cloudflare/proxy-everything miniflare uses; ALCHEMY_CONTAINER_EGRESS_IMAGE overrides it (e.g. to work around Containers local dev sidecar can intercept Docker bridge traffic and break readiness cloudflare/workerd#6792 on hosts where TPROXY intercepts bridge-local traffic and hangs the sidecar readiness probe)

Draft because it activates only once @distilled.cloud/cloudflare-runtime threads the container config through to workerd: alchemy-run/cloudflare-tools#46, then a catalog bump here. The new fields typecheck against 0.10.12 and are dropped by its config assembly, so behavior is unchanged until that lands.

Validated end-to-end on the cloudflare-tools#46 runtime: a Rust DataFusion container attached to a DO class under alchemy dev cold-starts on first request, serves proxied traffic, and is destroyed by the DO's idle alarm.

Butch78 and others added 2 commits June 11, 2026 08:07
Thread a per-class container image from binding data
(containers: [{ className, imageName }]) through LocalWorkerProvider
into workerd's native container support: each DO namespace with an
attached image gets container: { imageName }, and the worker gets a
localDocker containerEngine pointing at the host's docker socket
(egress sidecar image overridable via ALCHEMY_CONTAINER_EGRESS_IMAGE).

Inert until @distilled.cloud/cloudflare-runtime threads the container
config through to workerd (alchemy-run/cloudflare-tools#46): the
fields typecheck today via spreads and are dropped by the 0.10.12
config assembly, so behavior is unchanged until the catalog bump.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Extract the inline className->imageName loop into an exported, documented
`collectContainerImages` helper and export `toRuntimeDurableObjectNamespaces`,
then cover both with unit tests (remote-only attachments skipped, className
collision, container attached only to mapped namespaces).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Butch78

Butch78 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Added unit tests in 472532b (test/Cloudflare/Workers/LocalWorkerProvider.test.ts). Pulled the inline className -> imageName loop out into an exported, documented collectContainerImages helper and exported toRuntimeDurableObjectNamespaces, so both are covered directly: remote-only attachments (no imageName) are skipped, className collisions take the last write, and the container field is attached only to namespaces that have a mapped image. Still draft pending cloudflare-tools#46 + the catalog bump.

@john-royal john-royal self-assigned this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants