Skip to content

Commit 24e4c95

Browse files
committed
add deprecation warnings
1 parent 8195d2d commit 24e4c95

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
@@ -2459,6 +2459,36 @@ describe("normalizeAndValidateConfig()", () => {
24592459
- Expected \\"containers.scheduling_policy\\" field to be one of [\\"regional\\",\\"moon\\",\\"default\\"] but got \\"invalid\\"."
24602460
`);
24612461
});
2462+
2463+
it("should warn for deprecated container fields", () => {
2464+
const { diagnostics } = normalizeAndValidateConfig(
2465+
{
2466+
name: "test-worker",
2467+
containers: [
2468+
{
2469+
class_name: "test-class",
2470+
instances: 10,
2471+
configuration: {
2472+
image: "config-image"
2473+
},
2474+
durable_objects: {
2475+
namespace_id: "test-namespace"
2476+
}
2477+
},
2478+
],
2479+
} as unknown as RawConfig,
2480+
undefined,
2481+
undefined,
2482+
{ env: undefined }
2483+
);
2484+
2485+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2486+
"Processing wrangler configuration:
2487+
- \\"containers.configuration\\" is deprecated. Use top level \\"containers\\" fields instead. \\"configuration.image\\" should be \\"image\\", \\"configuration.disk\\" should be set via \\"instance_type\\".
2488+
- \\"containers.instances\\" is deprecated. Use \\"containers.max_instances\\" instead.
2489+
- \\"containers.durable_objects\\" is deprecated. Use the \\"class_name\\" field instead."
2490+
`);
2491+
});
24622492
});
24632493

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

packages/wrangler/src/config/validation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,6 @@ function validateContainerApp(
24212421
name += config === undefined ? "" : `-${envName}`;
24222422
containerAppOptional.name = name.toLowerCase().replace(/ /g, "-");
24232423
}
2424-
24252424
if (
24262425
!containerAppOptional.configuration?.image &&
24272426
!containerAppOptional.image
@@ -2430,6 +2429,11 @@ function validateContainerApp(
24302429
`"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.`
24312430
);
24322431
}
2432+
if ("configuration" in containerAppOptional) {
2433+
diagnostics.warnings.push(
2434+
`"containers.configuration" is deprecated. Use top level "containers" fields instead. "configuration.image" should be "image", "configuration.disk" should be set via "instance_type".`
2435+
);
2436+
}
24332437

24342438
// Validate that we have an image configuration for this container app.
24352439
// For legacy reasons we have to check both at containerAppOptional.image and
@@ -2522,6 +2526,19 @@ function validateContainerApp(
25222526
"string",
25232527
["regional", "moon", "default"]
25242528
);
2529+
2530+
// Add deprecation warnings for legacy fields
2531+
if ("instances" in containerAppOptional) {
2532+
diagnostics.warnings.push(
2533+
`"containers.instances" is deprecated. Use "containers.max_instances" instead.`
2534+
);
2535+
}
2536+
if ("durable_objects" in containerAppOptional) {
2537+
diagnostics.warnings.push(
2538+
`"containers.durable_objects" is deprecated. Use the "class_name" field instead.`
2539+
);
2540+
}
2541+
25252542
validateAdditionalProperties(
25262543
diagnostics,
25272544
field,
@@ -2540,6 +2557,7 @@ function validateContainerApp(
25402557
"constraints",
25412558
"rollout_step_percentage",
25422559
"rollout_kind",
2560+
"durable_objects",
25432561
]
25442562
);
25452563
}

0 commit comments

Comments
 (0)