-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[wrangler] Allow containers to be attached to Durable Objects via exports
#15026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
petebacondarwin
wants to merge
9
commits into
main
Choose a base branch
from
devx-2628-containers-via-exports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16b09c7
[wrangler] Allow containers to be attached to Durable Objects via `ex…
petebacondarwin a5e2090
[wrangler] Add live deploy e2e coverage for containers attached via `…
petebacondarwin 9ba3e01
[wrangler] Update versions upload container metadata assertion
petebacondarwin a66d14a
[wrangler] Catch the reverse container/Durable Object link mismatch
petebacondarwin 3048816
[wrangler] Reject two containers attached to the same Durable Object
petebacondarwin 85e8461
[wrangler] Fix container link validation across environment levels
petebacondarwin b9f8c47
[vite-plugin] Clarify the empty result of getContainerOptions
petebacondarwin f619f62
remove pre-emptive mention of free-standing container configs
petebacondarwin f4b1cbc
[config] Require `storage: "sqlite"` for a Durable Object `container`
petebacondarwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| "@cloudflare/config": minor | ||
| --- | ||
|
|
||
| Add a `container` option to `exports.durableObject()` | ||
|
|
||
| Live Durable Object exports can now attach a container by name, matching the new `container` field in the Wrangler configuration format: | ||
|
|
||
| ```typescript | ||
| import { defineWorker, exports } from "@cloudflare/config"; | ||
|
|
||
| export default defineWorker({ | ||
| name: "my-worker", | ||
| compatibilityDate: "2026-07-01", | ||
| exports: { | ||
| MyContainerDO: exports.durableObject({ | ||
| storage: "sqlite", | ||
| container: "my-container", | ||
| }), | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Containers are only supported on the SQLite storage engine, so `container` is only offered alongside `storage: "sqlite"`. Passing it with `storage: "legacy-kv"` is a type error rather than something only caught on deploy: | ||
|
|
||
| ```typescript | ||
| exports.durableObject({ | ||
| storage: "legacy-kv", | ||
| // Object literal may only specify known properties, | ||
| // and 'container' does not exist in type '{ storage: "legacy-kv" }' | ||
| container: "my-container", | ||
| }); | ||
| ``` | ||
|
|
||
| This is an experimental feature: containers themselves are not yet configurable from `cloudflare.config.ts`, so the field is only useful once they are. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| "wrangler": minor | ||
| "@cloudflare/vite-plugin": minor | ||
| --- | ||
|
|
||
| Allow containers to be attached to a Durable Object from its `exports` entry | ||
|
|
||
| A container can now be linked to its Durable Object from the export side, using a new `container` field that names an entry in the `containers` array. As a result `containers[].class_name` is now optional — a container that is referenced this way only needs a `name`: | ||
|
|
||
| ```jsonc | ||
| { | ||
| "name": "my-worker", | ||
| "main": "worker.js", | ||
| "compatibility_date": "2026-07-01", | ||
| "containers": [ | ||
| { "name": "my-container", "image": "./Dockerfile", "max_instances": 1 }, | ||
| ], | ||
| "exports": { | ||
| "MyContainerDO": { | ||
| "type": "durable-object", | ||
| "storage": "sqlite", | ||
| "container": "my-container", | ||
| }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| The existing `containers[].class_name` direction keeps working and either direction may be used, but the two must agree: a container that names its Durable Object cannot also be claimed by a different one. | ||
|
|
||
| `container` is only valid on live `durable-object` exports (`created` and `expecting-transfer`) and requires `storage: "sqlite"`. Wrangler now also reports an error when: | ||
|
|
||
| - a `container` reference names a container that does not exist | ||
| - two Durable Object exports claim the same container | ||
| - a container and a Durable Object export disagree about which one they are linked to | ||
| - a container ends up linked to no Durable Object at all | ||
| - two containers share a `name` | ||
| - two containers are attached to the same Durable Object | ||
|
|
||
| That last case was previously accepted but could never work: workerd attaches a single container per Durable Object namespace, and in local development every container for a class builds into the same image tag, so one silently overwrote the other. If you have two containers on one `class_name`, give each its own Durable Object class. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.