Skip to content

Commit 36cbccb

Browse files
committed
PR feedback
1 parent 189e5f8 commit 36cbccb

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

packages/containers-shared/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export type SharedContainerConfig = {
6969
cities?: string[];
7070
tier: number;
7171
};
72-
observability: { logsEnabled: boolean };
72+
observability: { logs_enabled: boolean };
7373
} & InstanceTypeOrLimits;
7474

7575
/** build/pull agnostic container options */

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { mkdirSync, writeFileSync } from "fs";
2-
import path from "path";
1+
import { mkdirSync, writeFileSync } from "node:fs";
2+
import path from "node:path";
33
import { getCloudflareContainerRegistry } from "@cloudflare/containers-shared";
44
import { vi } from "vitest";
55
import { getNormalizedContainerOptions } from "../../containers/config";
@@ -149,7 +149,7 @@ describe("getNormalizedContainerOptions", () => {
149149
image_vars: undefined,
150150
constraints: { tier: 1 },
151151
observability: {
152-
logsEnabled: false,
152+
logs_enabled: false,
153153
},
154154
});
155155
});
@@ -190,7 +190,7 @@ describe("getNormalizedContainerOptions", () => {
190190
image_uri: "registry.cloudflare.com/some-account-id/test:latest",
191191
constraints: { tier: 1 },
192192
observability: {
193-
logsEnabled: false,
193+
logs_enabled: false,
194194
},
195195
});
196196
});
@@ -224,7 +224,7 @@ describe("getNormalizedContainerOptions", () => {
224224
} as Partial<Config> as Config;
225225

226226
const result = await getNormalizedContainerOptions(config);
227-
227+
expect(result).toHaveLength(1);
228228
expect(result[0]).toMatchObject({
229229
name: "test-container",
230230
class_name: "TestContainer",
@@ -265,7 +265,7 @@ describe("getNormalizedContainerOptions", () => {
265265
} as Partial<Config> as Config;
266266

267267
const result = await getNormalizedContainerOptions(config);
268-
268+
expect(result).toHaveLength(1);
269269
expect(result[0]).toMatchObject({
270270
name: "test-container",
271271
class_name: "TestContainer",
@@ -316,7 +316,7 @@ describe("getNormalizedContainerOptions", () => {
316316
} as Partial<Config> as Config;
317317

318318
const result = await getNormalizedContainerOptions(config);
319-
319+
expect(result).toHaveLength(1);
320320
expect(result[0]).toEqual({
321321
name: "custom-name",
322322
class_name: "TestContainer",
@@ -332,7 +332,7 @@ describe("getNormalizedContainerOptions", () => {
332332
cities: ["nyc", "sf"],
333333
},
334334
observability: {
335-
logsEnabled: true,
335+
logs_enabled: true,
336336
},
337337
});
338338
});
@@ -363,7 +363,7 @@ describe("getNormalizedContainerOptions", () => {
363363
} as Partial<Config> as Config;
364364

365365
const result = await getNormalizedContainerOptions(config);
366-
366+
expect(result).toHaveLength(1);
367367
expect(result[0]).toMatchObject({
368368
name: "test-container",
369369
class_name: "TestContainer",
@@ -377,7 +377,7 @@ describe("getNormalizedContainerOptions", () => {
377377
image_vars: undefined,
378378
constraints: { tier: 1 },
379379
observability: {
380-
logsEnabled: false,
380+
logs_enabled: false,
381381
},
382382
});
383383
});
@@ -446,7 +446,7 @@ describe("getNormalizedContainerOptions", () => {
446446
} as Partial<Config> as Config;
447447

448448
const result = await getNormalizedContainerOptions(config);
449-
449+
expect(result).toHaveLength(1);
450450
// Check that it has dockerfile properties (not image_uri)
451451
expect(result[0]).toHaveProperty("dockerfile");
452452
expect(result[0]).toHaveProperty("image_build_context");

packages/wrangler/src/cloudchamber/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export async function buildCommand(
244244
},
245245
getDockerPath() ?? args.pathToDocker,
246246
args.push,
247-
// this means we wont be able to read the disk size from the config, but that option is deprecated anyway at least for containers.
247+
// this means we won't be able to read the disk size from the config, but that option is deprecated anyway at least for containers.
248248
// and this never actually worked for cloudchamber as this command was previously reading it from config.containers not config.cloudchamber
249249
undefined
250250
);

packages/wrangler/src/containers/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
SharedContainerConfig,
1616
} from "@cloudflare/containers-shared";
1717

18-
// TODO: allow merging in args from commands with config. e.g. for `wrangler containers build`
1918
/**
2019
* This normalises config into an intermediate shape for building or pulling.
2120
* We set defaults here too, because we can assume that if the value is undefined,
@@ -70,7 +69,7 @@ export const getNormalizedContainerOptions = async (
7069
rollout_step_percentage: container.rollout_step_percentage ?? 25,
7170
rollout_kind: container.rollout_kind ?? "full_auto",
7271
observability: {
73-
logsEnabled:
72+
logs_enabled:
7473
config.observability?.logs?.enabled ??
7574
config.observability?.enabled === true,
7675
},

packages/wrangler/src/containers/deploy.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ function cleanupObservability(
9797
}
9898
}
9999

100+
/**
101+
* Resolves current configuration based on previous deployment.
102+
*/
100103
function observabilityToConfiguration(
104+
/** Taken from current wrangler config */
101105
observabilityFromConfig: boolean,
106+
/** From previous deployment */
102107
existingObservabilityConfig: ObservabilityConfiguration | undefined
103108
): ObservabilityConfiguration | undefined {
104109
// Let's use logs for the sake of simplicity of explanation.
@@ -134,12 +139,10 @@ function observabilityToConfiguration(
134139

135140
if (observabilityFromConfig) {
136141
return { logs: { enabled: true } };
142+
} else if (logsAlreadyEnabled === undefined) {
143+
return undefined;
137144
} else {
138-
if (logsAlreadyEnabled === undefined) {
139-
return undefined;
140-
} else {
141-
return { logs: { enabled: false } };
142-
}
145+
return { logs: { enabled: false } };
143146
}
144147
}
145148

@@ -172,7 +175,7 @@ function containerConfigToCreateRequest(
172175
vcpu: containerApp.vcpu,
173176
}),
174177
observability: observabilityToConfiguration(
175-
containerApp.observability.logsEnabled,
178+
containerApp.observability.logs_enabled,
176179
prevApp?.configuration.observability
177180
),
178181
},
@@ -191,7 +194,7 @@ export async function apply(
191194
imageUpdateRequired?: boolean;
192195
/**
193196
* If the image was built and pushed, or is a registry link, we have to update the image ref and this will be defined
194-
* If it is undefined, the image has not change, and we do not need to update the image ref
197+
* If it is undefined, the image has not changed, and we do not need to update the image ref
195198
*/
196199
newImageLink: string | undefined;
197200
durable_object_namespace_id: string;
@@ -261,7 +264,9 @@ export async function apply(
261264

262265
// we need to sort the objects (by key) because the diff algorithm works with lines
263266
const normalisedPrevApp = sortObjectRecursive<ModifyApplicationRequestBody>(
264-
stripUndefined(cleanPrevious(prevApp, containerConfig, accountId))
267+
stripUndefined(
268+
cleanApplicationFromAPI(prevApp, containerConfig, accountId)
269+
)
265270
);
266271

267272
const modifyReq = createApplicationToModifyApplication(appConfig);
@@ -487,7 +492,7 @@ const doAction = async (
487492
/**
488493
* clean up application object received from API so that we get a nicer diff when comparing it to the current config.
489494
*/
490-
export function cleanPrevious(
495+
export function cleanApplicationFromAPI(
491496
prev: Application,
492497
currentConfig: ContainerNormalizedConfig,
493498
accountId: string

0 commit comments

Comments
 (0)