Skip to content

Keep hosted app artifacts in a configured R2 location - #374

Merged
tnkuehne merged 2 commits into
mainfrom
artifacts-location
Nov 24, 2026
Merged

tnkuehne merged 2 commits into
mainfrom
artifacts-location

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The hosted installation profile now requires storageLocation, an R2 location hint (wnam, enam, weur, eeur, apac or oc). 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:

  1. Create <name>-artifacts-<location> with the chosen location hint.
  2. Pause app deployments, app removals and settings changes, and let running ones finish. Routing records and organization settings change only through these.
  3. Copy every object from the old <name>-artifacts bucket, including HTTP and custom metadata.
  4. Deploy, so both Workers switch to the new bucket in one deployment.
  5. Copy every object that changed in the old bucket after the copy. The runtime still writes there until the deployment completes, for example app keys on first use, service indexes and the workload key ring. Overwrite an object in the new bucket only if it has not changed there since the copy. Report any object that changed in both buckets, then resume.

Testing

  • pnpm check
  • tests/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 valid storageLocation is rejected.

RetriggerView in GreptileConfidence Score: 4/5

Hold the merge until the upgrade prevents the old and new buckets from creating conflicting app keys.

Findings

  1. P1 Bucket move drops updates ▶
  2. P1 Workers use different buckets ▶

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.

  • Hosted apps now use an artifacts bucket with a chosen location.

Reviews (4) · Last reviewed commit: "Create the hosted artifacts bucket throu..." · Reviewed by Greptile

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}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Bucket move drops updates

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Workers use different buckets

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tnkuehne
tnkuehne merged commit 199798f into main Nov 24, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the artifacts-location branch November 24, 2026 17:40
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.

1 participant