Skip to content

Commit 9222070

Browse files
vicbkaziu687
andauthored
fix r2 bulk put to respect bucket jurisdiction (#1064)
Co-authored-by: kaziu687 <[email protected]>
1 parent e4e6191 commit 9222070

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

.changeset/five-eyes-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix r2 bulk put to respect bucket jurisdiction

packages/cloudflare/src/cli/commands/populate-cache.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@ describe("populateCache", () => {
137137
expect.objectContaining({ target })
138138
);
139139
});
140+
141+
test(`${target} using jurisdiction`, async () => {
142+
const { runWrangler } = await import("../utils/run-wrangler.js");
143+
144+
setupMockFileSystem();
145+
vi.mocked(runWrangler).mockClear();
146+
147+
await populateCache(
148+
{
149+
outputDir: "/test/output",
150+
} as BuildOptions,
151+
{
152+
default: {
153+
override: {
154+
incrementalCache: "cf-r2-incremental-cache",
155+
},
156+
},
157+
} as any, // eslint-disable-line @typescript-eslint/no-explicit-any
158+
{
159+
r2_buckets: [
160+
{
161+
binding: "NEXT_INC_CACHE_R2_BUCKET",
162+
bucket_name: "test-bucket",
163+
jurisdiction: "eu",
164+
},
165+
],
166+
} as any, // eslint-disable-line @typescript-eslint/no-explicit-any
167+
{ target, shouldUsePreviewId: false },
168+
{} as any // eslint-disable-line @typescript-eslint/no-explicit-any
169+
);
170+
171+
expect(runWrangler).toHaveBeenCalledWith(
172+
expect.anything(),
173+
expect.arrayContaining(["r2 bulk put", "test-bucket", "--jurisdiction eu"]),
174+
expect.objectContaining({ target })
175+
);
176+
});
140177
}
141178
);
142179
});

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,17 @@ async function populateR2IncrementalCache(
245245
fs.writeFileSync(listFile, JSON.stringify(objectList));
246246

247247
const concurrency = Math.max(1, populateCacheOptions.cacheChunkSize ?? 50);
248+
const jurisdiction = binding.jurisdiction ? `--jurisdiction ${binding.jurisdiction}` : "";
248249

249250
runWrangler(
250251
buildOpts,
251-
["r2 bulk put", bucket, `--filename ${quoteShellMeta(listFile)}`, `--concurrency ${concurrency}`],
252+
[
253+
"r2 bulk put",
254+
bucket,
255+
`--filename ${quoteShellMeta(listFile)}`,
256+
`--concurrency ${concurrency}`,
257+
jurisdiction,
258+
],
252259
{
253260
target: populateCacheOptions.target,
254261
configPath: populateCacheOptions.wranglerConfigPath,

0 commit comments

Comments
 (0)