Skip to content

Commit d391076

Browse files
containers: add option to allow all tiers (#10258)
* containers: add option to not set a constraint on tier * changeset * Update packages/containers-shared/src/types.ts Co-authored-by: emily-shen <[email protected]> * fix diff * update comment --------- Co-authored-by: emily-shen <[email protected]>
1 parent c58a05c commit d391076

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

.changeset/famous-coats-chew.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/containers-shared": patch
3+
"wrangler": patch
4+
---
5+
6+
Add the option to allow all tiers when creating a container

packages/containers-shared/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type SharedContainerConfig = {
6868
constraints: {
6969
regions?: string[];
7070
cities?: string[];
71-
tier: number;
71+
tier: number | undefined;
7272
};
7373
observability: { logs_enabled: boolean };
7474
} & InstanceTypeOrLimits;

packages/wrangler/src/__tests__/containers/config.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,33 @@ describe("getNormalizedContainerOptions", () => {
542542
expect(result[0]).toHaveProperty("image_build_context");
543543
expect(result[0]).not.toHaveProperty("image_uri");
544544
});
545+
546+
it("should be able to specify all tiers", async () => {
547+
writeFileSync("Dockerfile", "FROM scratch");
548+
const config: Config = {
549+
name: "test-worker",
550+
containers: [
551+
{
552+
class_name: "TestContainer",
553+
image: `${getCloudflareContainerRegistry()}/test:latest`,
554+
name: "test-container",
555+
constraints: {
556+
tier: -1,
557+
},
558+
},
559+
],
560+
durable_objects: {
561+
bindings: [
562+
{
563+
name: "TEST_DO",
564+
class_name: "TestContainer",
565+
},
566+
],
567+
},
568+
} as Partial<Config> as Config;
569+
570+
const result = await getNormalizedContainerOptions(config);
571+
expect(result).toHaveLength(1);
572+
expect(result[0].constraints.tier).toBeUndefined();
573+
});
545574
});

packages/wrangler/src/containers/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ export const getNormalizedContainerOptions = async (
5858
scheduling_policy: (container.scheduling_policy ??
5959
SchedulingPolicy.DEFAULT) as SchedulingPolicy,
6060
constraints: {
61-
tier: container.constraints?.tier ?? 1,
61+
// if the tier is -1, then we allow all tiers
62+
// Wrangler will default an input value to 1. The API, however, will
63+
// treat an undefined value to mean no constraints on tier (i.e. "all tiers")
64+
tier:
65+
container.constraints?.tier === -1
66+
? undefined
67+
: container.constraints?.tier ?? 1,
6268
regions: container.constraints?.regions?.map((region) =>
6369
region.toUpperCase()
6470
),

0 commit comments

Comments
 (0)