Repository navigation
Keep hosted app artifacts in a configured R2 location - #374
Conversation
The hosted installation profile now requires `storageLocation`, an R2 location hint. Provisioning creates the artifacts bucket with it, and the bucket is named `<name>-artifacts-<location>`. Without a hint, Cloudflare places a new bucket near whoever creates it, which for a CI deployment can be another continent from the runtime. The runtime reads this bucket on every app request. Cloudflare honors a hint only the first time a bucket name is created, so the location is part of the name: a new location gets a new bucket.
| artifacts: `${installation.name}-artifacts`, | ||
| // Cloudflare honors a location hint only when a bucket name is first created, so the | ||
| // location is part of the name and a new location gets a new bucket. | ||
| artifacts: `${installation.name}-artifacts-${installation.storageLocation}`, |
There was a problem hiding this comment.
If someone redeploys or removes an app after the first copy, the old control plane can overwrite hosts/<hostname>.json before it switches buckets. The final copy skips that key because it already exists in the new bucket. Visitors can keep seeing the old version or an app that was removed. Pause writes and let in-flight writes finish, then sync additions, updates, and deletions while preserving metadata. Resume writes only after both Workers use the new bucket.
There was a problem hiding this comment.
The upgrade steps in the description now pause app deployments, removals and settings changes before the copy, so routing records and organization settings cannot change between the copy and the switch. Both Workers then switch in one deployment. The last step copies only objects the runtime creates on first use, such as app keys, which are never overwritten once written.
There was a problem hiding this comment.
Step 5 now copies every object that changed in the old bucket after the copy, not only missing ones: app keys, service indexes and the workload key ring that the runtime writes until the deployment completes. It overwrites an object in the new bucket only if that object has not changed there since the copy, and it reports objects that changed in both buckets.
| artifacts: `${installation.name}-artifacts`, | ||
| // Cloudflare honors a location hint only when a bucket name is first created, so the | ||
| // location is part of the name and a new location gets a new bucket. | ||
| artifacts: `${installation.name}-artifacts-${installation.storageLocation}`, |
There was a problem hiding this comment.
If a saved --control-config file lists the old ARTIFACTS bucket alongside an extra binding, it replaces the whole r2_buckets list. The control plane keeps publishing updates to the old bucket while the runtime reads the new one. Merge extra bindings by name and reject overrides that move ARTIFACTS or WIDEFLEET_PACKAGES away from the configured bucket.
There was a problem hiding this comment.
Overrides replace top-level keys such as r2_buckets, services and kv_namespaces as a whole, and this PR does not change that. A control override that lists r2_buckets already replaces the ARTIFACTS binding today, whatever the bucket name. The location only changes the generated name. Override merging would need its own change.
There was a problem hiding this comment.
You're right — the override replacement behavior is pre-existing, and this PR only changes the generated bucket name. The risk I flagged isn't specific to this change. Thank you for clarifying.
The hosted installation profile now requires
storageLocation, an R2 location hint (wnam,enam,weur,eeur,apacoroc). Provisioning creates the artifacts bucket with--location, and the bucket is named<name>-artifacts-<location>.Without a hint, Cloudflare places a new bucket near whoever creates it. For a deployment that runs in CI, that can be another continent from where the runtime serves apps, and the runtime reads this bucket on every app request: routing records, app code and app secrets. Cloudflare honors a location hint only the first time a bucket name is created, so the location is part of the name and a new location always gets a new bucket.
Upgrading an existing installation
The profile no longer parses without
storageLocation, so a deployment never switches to a new, empty bucket by accident. To move an existing installation:<name>-artifacts-<location>with the chosen location hint.<name>-artifactsbucket, including HTTP and custom metadata.Testing
pnpm checktests/cloudflare/hosted-installation.test.ts: both Workers bind the location-named bucket, Wrangler sends the location hint when it creates the bucket against a local API server, and a profile without a validstorageLocationis rejected.Hold the merge until the upgrade prevents the old and new buckets from creating conflicting app keys.
Findings
Summary
Hosted profiles now require an R2 location hint. The deploy script uses it to name and create the artifact bucket, and both generated Worker configs point to that bucket.
Reviews (4) · Last reviewed commit: "Create the hosted artifacts bucket throu..." · Reviewed by Greptile