Skip to content

Commit 7b19198

Browse files
committed
add deprecation warnings
1 parent 34e0a3b commit 7b19198

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

packages/wrangler/src/__tests__/cloudchamber/deploy.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("wrangler deploy with containers", () => {
9696
containers: [
9797
{
9898
name: "my-container",
99-
instances: 10,
99+
max_instances: 10,
100100
class_name: "ExampleDurableObject",
101101
image: "./Dockerfile",
102102
},
@@ -147,7 +147,7 @@ describe("wrangler deploy with containers", () => {
147147
containers: [
148148
{
149149
name: "my-container",
150-
instances: 10,
150+
max_instances: 10,
151151
class_name: "ExampleDurableObject",
152152
image: "./Dockerfile",
153153
},
@@ -161,7 +161,7 @@ describe("wrangler deploy with containers", () => {
161161

162162
mockCreateApplication({
163163
name: "my-container",
164-
instances: 10,
164+
max_instances: 10,
165165
durable_objects: { namespace_id: "1" },
166166
configuration: {
167167
image:
@@ -206,7 +206,7 @@ describe("wrangler deploy with containers", () => {
206206
{
207207
image: "docker.io/hello:world",
208208
name: "my-container",
209-
instances: 10,
209+
max_instances: 10,
210210
class_name: "ExampleDurableObject",
211211
},
212212
],
@@ -217,7 +217,7 @@ describe("wrangler deploy with containers", () => {
217217

218218
mockCreateApplication({
219219
name: "my-container",
220-
instances: 10,
220+
max_instances: 10,
221221
durable_objects: { namespace_id: "1" },
222222
scheduling_policy: SchedulingPolicy.DEFAULT,
223223
});
@@ -287,7 +287,7 @@ describe("wrangler deploy with containers", () => {
287287
containers: [
288288
{
289289
name: "my-container",
290-
instances: 10,
290+
max_instances: 10,
291291
class_name: "ExampleDurableObject",
292292
image: "../Dockerfile",
293293
},
@@ -311,7 +311,7 @@ describe("wrangler deploy with containers", () => {
311311

312312
mockCreateApplication({
313313
name: "my-container",
314-
instances: 10,
314+
max_instances: 10,
315315
durable_objects: { namespace_id: "1" },
316316
configuration: {
317317
image:
@@ -391,7 +391,7 @@ describe("wrangler deploy with containers", () => {
391391
containers: [
392392
{
393393
name: "my-container",
394-
instances: 10,
394+
max_instances: 10,
395395
class_name: "ExampleDurableObject",
396396
image: "../Dockerfile",
397397
},
@@ -408,7 +408,7 @@ describe("wrangler deploy with containers", () => {
408408

409409
mockCreateApplication({
410410
name: "my-container",
411-
instances: 10,
411+
max_instances: 10,
412412
durable_objects: { namespace_id: "1" },
413413
configuration: {
414414
image:
@@ -453,7 +453,7 @@ describe("wrangler deploy with containers", () => {
453453
{
454454
image: "docker.io/hello:world",
455455
name: "my-container",
456-
instances: 10,
456+
max_instances: 10,
457457
class_name: "ExampleDurableObject",
458458
},
459459
],
@@ -515,7 +515,7 @@ describe("wrangler deploy with containers dry run", () => {
515515
{
516516
image: "./Dockerfile",
517517
name: "my-container",
518-
instances: 10,
518+
max_instances: 10,
519519
class_name: "ExampleDurableObject",
520520
},
521521
],

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,36 @@ describe("normalizeAndValidateConfig()", () => {
24642464
- Expected \\"containers.scheduling_policy\\" field to be one of [\\"regional\\",\\"moon\\",\\"default\\"] but got \\"invalid\\"."
24652465
`);
24662466
});
2467+
2468+
it("should warn for deprecated container fields", () => {
2469+
const { diagnostics } = normalizeAndValidateConfig(
2470+
{
2471+
name: "test-worker",
2472+
containers: [
2473+
{
2474+
class_name: "test-class",
2475+
instances: 10,
2476+
configuration: {
2477+
image: "config-image"
2478+
},
2479+
durable_objects: {
2480+
namespace_id: "test-namespace"
2481+
}
2482+
},
2483+
],
2484+
} as unknown as RawConfig,
2485+
undefined,
2486+
undefined,
2487+
{ env: undefined }
2488+
);
2489+
2490+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2491+
"Processing wrangler configuration:
2492+
- \\"containers.configuration\\" is deprecated. Use top level \\"containers\\" fields instead. \\"configuration.image\\" should be \\"image\\", \\"configuration.disk\\" should be set via \\"instance_type\\".
2493+
- \\"containers.instances\\" is deprecated. Use \\"containers.max_instances\\" instead.
2494+
- \\"containers.durable_objects\\" is deprecated. Use the \\"class_name\\" field instead."
2495+
`);
2496+
});
24672497
});
24682498

24692499
describe("[kv_namespaces]", () => {

packages/wrangler/src/config/validation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,6 @@ function validateContainerApp(
24312431
name += config === undefined ? "" : `-${envName}`;
24322432
containerAppOptional.name = name.toLowerCase().replace(/ /g, "-");
24332433
}
2434-
24352434
if (
24362435
!containerAppOptional.configuration?.image &&
24372436
!containerAppOptional.image
@@ -2440,6 +2439,11 @@ function validateContainerApp(
24402439
`"containers.image" field must be defined for each container app. This should be the path to your Dockerfile or a image URI pointing to the Cloudflare registry.`
24412440
);
24422441
}
2442+
if ("configuration" in containerAppOptional) {
2443+
diagnostics.warnings.push(
2444+
`"containers.configuration" is deprecated. Use top level "containers" fields instead. "configuration.image" should be "image", "configuration.disk" should be set via "instance_type".`
2445+
);
2446+
}
24432447

24442448
// Validate that we have an image configuration for this container app.
24452449
// For legacy reasons we have to check both at containerAppOptional.image and
@@ -2532,6 +2536,19 @@ function validateContainerApp(
25322536
"string",
25332537
["regional", "moon", "default"]
25342538
);
2539+
2540+
// Add deprecation warnings for legacy fields
2541+
if ("instances" in containerAppOptional) {
2542+
diagnostics.warnings.push(
2543+
`"containers.instances" is deprecated. Use "containers.max_instances" instead.`
2544+
);
2545+
}
2546+
if ("durable_objects" in containerAppOptional) {
2547+
diagnostics.warnings.push(
2548+
`"containers.durable_objects" is deprecated. Use the "class_name" field instead.`
2549+
);
2550+
}
2551+
25352552
validateAdditionalProperties(
25362553
diagnostics,
25372554
field,
@@ -2550,6 +2567,7 @@ function validateContainerApp(
25502567
"constraints",
25512568
"rollout_step_percentage",
25522569
"rollout_kind",
2570+
"durable_objects",
25532571
]
25542572
);
25552573
}

0 commit comments

Comments
 (0)