Skip to content

Commit 7a2b396

Browse files
committed
naming changes and other minor pr feedback
1 parent c92dd82 commit 7a2b396

File tree

16 files changed

+116
-109
lines changed

16 files changed

+116
-109
lines changed

packages/containers-shared/src/images.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
runDockerCmd,
1111
verifyDockerInstalled,
1212
} from "./utils";
13-
import type { ContainerNormalisedConfig, RegistryLinkConfig } from "./types";
13+
import type { ContainerNormalizedConfig, RegistryLinkConfig } from "./types";
1414

1515
export async function pullImage(
1616
dockerPath: string,
@@ -20,15 +20,15 @@ export async function pullImage(
2020
await dockerLoginManagedRegistry(dockerPath);
2121
const pull = runDockerCmd(dockerPath, [
2222
"pull",
23-
options.registry_link,
23+
options.image_uri,
2424
// All containers running on our platform need to be built for amd64 architecture, but by default docker pull seems to look for an image matching the host system, so we need to specify this here
2525
"--platform",
2626
"linux/amd64",
2727
]);
2828
const ready = pull.ready.then(async ({ aborted }: { aborted: boolean }) => {
2929
if (!aborted) {
3030
// re-tag image with the expected dev-formatted image tag for consistency
31-
await runDockerCmd(dockerPath, ["tag", options.registry_link, tag]);
31+
await runDockerCmd(dockerPath, ["tag", options.image_uri, tag]);
3232
}
3333
});
3434

@@ -52,13 +52,13 @@ export async function pullImage(
5252
*/
5353
export async function prepareContainerImagesForDev(options: {
5454
dockerPath: string;
55-
containerOptions: ContainerNormalisedConfig[];
55+
containerOptions: ContainerNormalizedConfig[];
5656
onContainerImagePreparationStart: (args: {
57-
containerOptions: ContainerNormalisedConfig;
57+
containerOptions: ContainerNormalizedConfig;
5858
abort: () => void;
5959
}) => void;
6060
onContainerImagePreparationEnd: (args: {
61-
containerOptions: ContainerNormalisedConfig[];
61+
containerOptions: ContainerNormalizedConfig[];
6262
}) => void;
6363
}) {
6464
const {
@@ -90,9 +90,9 @@ export async function prepareContainerImagesForDev(options: {
9090
containerOptions: options,
9191
});
9292
} else {
93-
if (!isCloudflareRegistryLink(options.registry_link)) {
93+
if (!isCloudflareRegistryLink(options.image_uri)) {
9494
throw new Error(
95-
`Image "${options.registry_link}" is a registry link but does not point to the Cloudflare container registry.\n` +
95+
`Image "${options.image_uri}" is a registry link but does not point to the Cloudflare container registry.\n` +
9696
`To use an existing image from another repository, see https://developers.cloudflare.com/containers/image-management/#using-existing-images`
9797
);
9898
}

packages/containers-shared/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ export type BuildArgs = {
2222
setNetworkToHost?: boolean;
2323
};
2424

25-
export type ContainerNormalisedConfig = RegistryLinkConfig | DockerfileConfig;
25+
export type ContainerNormalizedConfig = RegistryLinkConfig | DockerfileConfig;
2626
export type DockerfileConfig = SharedContainerConfig & {
27-
/** absolute path, resolved relative to the wrangler config file */
27+
/** absolute path, resolved relative to the wrangler config file */
2828
dockerfile: string;
2929
/** absolute path, resolved relative to the wrangler config file. defaults to the directory of the dockerfile */
3030
image_build_context: string;
3131
image_vars?: Record<string, string>;
3232
};
3333
export type RegistryLinkConfig = SharedContainerConfig & {
34-
registry_link: string;
34+
image_uri: string;
3535
};
3636

3737
export type InstanceTypeOrLimits =

packages/containers-shared/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFile, spawn } from "child_process";
22
import { existsSync, statSync } from "fs";
33
import path from "path";
44
import { dockerImageInspect } from "./inspect";
5-
import type { ContainerNormalisedConfig } from "./types";
5+
import type { ContainerNormalizedConfig } from "./types";
66
import type { StdioOptions } from "child_process";
77

88
/** helper for simple docker command call that don't require any io handling */
@@ -229,7 +229,7 @@ export const getContainerIdsFromImage = async (
229229
*/
230230
export async function checkExposedPorts(
231231
dockerPath: string,
232-
options: ContainerNormalisedConfig,
232+
options: ContainerNormalizedConfig,
233233
imageTag: string
234234
) {
235235
const output = await dockerImageInspect(dockerPath, {

packages/containers-shared/tests/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mkdirSync, writeFileSync } from "fs";
2-
import { ContainerNormalisedConfig } from "../src/types";
32
import { checkExposedPorts, isDockerfile } from "./../src/utils";
43
import { runInTempDir } from "./helpers/run-in-tmp-dir";
4+
import type { ContainerNormalizedConfig } from "../src/types";
55

66
describe("isDockerfile", () => {
77
const dockerfile =
@@ -75,7 +75,7 @@ vi.mock("../src/inspect", async (importOriginal) => {
7575
const containerConfig = {
7676
dockerfile: "",
7777
class_name: "MyContainer",
78-
} as ContainerNormalisedConfig;
78+
} as ContainerNormalizedConfig;
7979
describe("checkExposedPorts", () => {
8080
beforeEach(() => {
8181
docketImageInspectResult = "1";
@@ -90,8 +90,8 @@ describe("checkExposedPorts", () => {
9090

9191
it("should error, with an appropriate message when no ports are exported", async () => {
9292
docketImageInspectResult = "0";
93-
expect(checkExposedPorts("docker", containerConfig, "image:tag")).rejects
94-
.toThrowErrorMatchingInlineSnapshot(`
93+
await expect(checkExposedPorts("docker", containerConfig, "image:tag"))
94+
.rejects.toThrowErrorMatchingInlineSnapshot(`
9595
[Error: The container "MyContainer" does not expose any ports. In your Dockerfile, please expose any ports you intend to connect to.
9696
For additional information please see: https://developers.cloudflare.com/containers/local-dev/#exposing-ports.
9797
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ describe("buildAndMaybePush", () => {
281281
configDiskInBytes: 3000 * MiB, // ie 3GB - this exceeds the account limit of 2GB
282282
})
283283
).rejects.toThrowErrorMatchingInlineSnapshot(
284-
`[Error: Exceeded account limits: Your container is configured to use a disk size of 3146 MB. However, that exceeds the account limit of 2000MB]`
284+
`[Error: Exceeded account limits: Your container is configured to use a disk size of 3146MB. However, that exceeds the account limit of 2000MB]`
285285
);
286286
});
287287

@@ -293,7 +293,7 @@ describe("buildAndMaybePush", () => {
293293
configDiskInBytes: undefined,
294294
})
295295
).rejects.toThrowErrorMatchingInlineSnapshot(
296-
`[Error: Image too large: needs 3146 MB, but your app is limited to images with size 2000 MB. Your account needs more disk size per instance to run this container. The default disk size is 2GB.]`
296+
`[Error: Image too large: needs 3146MB, but your app is limited to images with size 2000MB. Your account needs more disk size per instance to run this container. The default disk size is 2GB.]`
297297
);
298298
});
299299

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

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { isDockerfile } from "@cloudflare/containers-shared";
1+
import { mkdirSync, writeFileSync } from "fs";
2+
import { getCloudflareContainerRegistry } from "@cloudflare/containers-shared";
23
import { vi } from "vitest";
34
import { getNormalizedContainerOptions } from "../../containers/config";
45
import { UserError } from "../../errors";
6+
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
7+
import { runInTempDir } from "../helpers/run-in-tmp";
58
import type { Config } from "../../config";
69

7-
// Mock dependencies using vi.hoisted
8-
vi.mock("@cloudflare/containers-shared");
9-
10-
const mockIsDockerfile = vi.mocked(isDockerfile);
11-
1210
describe("getNormalizedContainerOptions", () => {
11+
runInTempDir();
1312
beforeEach(() => {
1413
vi.clearAllMocks();
1514
});
@@ -99,18 +98,19 @@ describe("getNormalizedContainerOptions", () => {
9998
await expect(getNormalizedContainerOptions(config)).rejects.toThrow(
10099
UserError
101100
);
102-
await expect(getNormalizedContainerOptions(config)).rejects.toThrow(
103-
"The container class_name TestContainer does not match any durable object class_name defined in your Wrangler config file"
101+
await expect(
102+
getNormalizedContainerOptions(config)
103+
).rejects.toThrowErrorMatchingInlineSnapshot(
104+
`[Error: The container test-container is referencing the durable object TestContainer, which appears to be defined on the other-script Worker instead (via the 'script_name' field). You cannot configure a container on a Durable Object that is defined in another Worker.]`
104105
);
105106
});
106107

107108
it("should normalize and set defaults for container with dockerfile", async () => {
108-
mockIsDockerfile.mockReturnValue(true);
109+
writeFileSync("Dockerfile", "FROM scratch");
109110

110111
const config: Config = {
111112
name: "test-worker",
112-
configPath: "/test/wrangler.toml",
113-
userConfigPath: "/test/wrangler.toml",
113+
configPath: "./wrangler.toml",
114114
topLevelName: "test-worker",
115115
containers: [
116116
{
@@ -132,24 +132,22 @@ describe("getNormalizedContainerOptions", () => {
132132
const result = await getNormalizedContainerOptions(config);
133133

134134
expect(result).toHaveLength(1);
135-
expect(result[0]).toEqual({
135+
expect(result[0]).toMatchObject({
136136
name: "test-container",
137137
class_name: "TestContainer",
138138
max_instances: 0,
139139
scheduling_policy: "default",
140140
rollout_step_percentage: 25,
141141
rollout_kind: "full_auto",
142142
instance_type: "dev",
143-
dockerfile: "/test/Dockerfile",
144-
image_build_context: "/test",
143+
dockerfile: expect.stringMatching(/[/\\]Dockerfile$/),
144+
image_build_context: expect.stringMatching(/[/\\][^/\\]*$/),
145145
image_vars: undefined,
146146
constraints: undefined,
147147
});
148148
});
149149

150150
it("should normalize and set defaults for container with registry image", async () => {
151-
mockIsDockerfile.mockReturnValue(false);
152-
153151
const config: Config = {
154152
name: "test-worker",
155153
configPath: "/test/wrangler.toml",
@@ -174,22 +172,20 @@ describe("getNormalizedContainerOptions", () => {
174172
const result = await getNormalizedContainerOptions(config);
175173

176174
expect(result).toHaveLength(1);
177-
expect(result[0]).toEqual({
175+
expect(result[0]).toMatchObject({
178176
name: "test-container",
179177
class_name: "TestContainer",
180178
max_instances: 0,
181179
scheduling_policy: "default",
182180
rollout_step_percentage: 25,
183181
rollout_kind: "full_auto",
184182
instance_type: "dev",
185-
registry_link: "registry.example.com/test:latest",
186183
constraints: undefined,
184+
image_uri: "registry.cloudflare.com/some-account-id/test:latest",
187185
});
188186
});
189187

190188
it("should handle custom limit configuration", async () => {
191-
mockIsDockerfile.mockReturnValue(false);
192-
193189
const config: Config = {
194190
name: "test-worker",
195191
configPath: "/test/wrangler.toml",
@@ -219,7 +215,7 @@ describe("getNormalizedContainerOptions", () => {
219215

220216
const result = await getNormalizedContainerOptions(config);
221217

222-
expect(result[0]).toEqual({
218+
expect(result[0]).toMatchObject({
223219
name: "test-container",
224220
class_name: "TestContainer",
225221
max_instances: 0,
@@ -229,14 +225,12 @@ describe("getNormalizedContainerOptions", () => {
229225
disk_bytes: 5_000_000_000, // 5000 MB in bytes
230226
memory_mib: 1024,
231227
vcpu: 2,
232-
registry_link: "registry.example.com/test:latest",
233228
constraints: undefined,
229+
image_uri: "registry.example.com/test:latest",
234230
});
235231
});
236232

237233
it("should handle instance type configuration", async () => {
238-
mockIsDockerfile.mockReturnValue(false);
239-
240234
const config: Config = {
241235
name: "test-worker",
242236
configPath: "/test/wrangler.toml",
@@ -262,22 +256,20 @@ describe("getNormalizedContainerOptions", () => {
262256

263257
const result = await getNormalizedContainerOptions(config);
264258

265-
expect(result[0]).toEqual({
259+
expect(result[0]).toMatchObject({
266260
name: "test-container",
267261
class_name: "TestContainer",
268262
max_instances: 0,
269263
scheduling_policy: "default",
270264
rollout_step_percentage: 25,
271265
rollout_kind: "full_auto",
272266
instance_type: "standard",
273-
registry_link: "registry.example.com/test:latest",
274267
constraints: undefined,
268+
image_uri: "registry.example.com/test:latest",
275269
});
276270
});
277271

278272
it("should handle all custom configuration options", async () => {
279-
mockIsDockerfile.mockReturnValue(false);
280-
281273
const config: Config = {
282274
name: "test-worker",
283275
configPath: "/test/wrangler.toml",
@@ -320,7 +312,7 @@ describe("getNormalizedContainerOptions", () => {
320312
rollout_step_percentage: 50,
321313
rollout_kind: "full_manual",
322314
instance_type: "basic",
323-
registry_link: "registry.example.com/test:latest",
315+
image_uri: "registry.example.com/test:latest",
324316
constraints: {
325317
regions: ["us-east-1", "us-west-2"],
326318
cities: ["NYC", "SF"],
@@ -330,17 +322,17 @@ describe("getNormalizedContainerOptions", () => {
330322
});
331323

332324
it("should handle dockerfile with default build context", async () => {
333-
mockIsDockerfile.mockReturnValue(true);
325+
mkdirSync("nested", { recursive: true });
326+
writeFileSync("nested/Dockerfile", "FROM scratch");
334327

335328
const config: Config = {
336329
name: "test-worker",
337-
configPath: "/test/wrangler.toml",
338-
userConfigPath: "/test/wrangler.toml",
330+
configPath: "./wrangler.toml",
339331
topLevelName: "test-worker",
340332
containers: [
341333
{
342334
class_name: "TestContainer",
343-
image: "./path/to/Dockerfile",
335+
image: "./nested/Dockerfile",
344336
name: "test-container",
345337
},
346338
],
@@ -356,24 +348,22 @@ describe("getNormalizedContainerOptions", () => {
356348

357349
const result = await getNormalizedContainerOptions(config);
358350

359-
expect(result[0]).toEqual({
351+
expect(result[0]).toMatchObject({
360352
name: "test-container",
361353
class_name: "TestContainer",
362354
max_instances: 0,
363355
scheduling_policy: "default",
364356
rollout_step_percentage: 25,
365357
rollout_kind: "full_auto",
366358
instance_type: "dev",
367-
dockerfile: "/test/path/to/Dockerfile",
368-
image_build_context: "/test/path/to",
359+
dockerfile: expect.stringMatching(/[/\\]nested[/\\]Dockerfile$/),
360+
image_build_context: expect.stringMatching(/[/\\]nested$/),
369361
image_vars: undefined,
370362
constraints: undefined,
371363
});
372364
});
373365

374366
it("should handle multiple containers", async () => {
375-
mockIsDockerfile.mockReturnValue(false);
376-
377367
const config: Config = {
378368
name: "test-worker",
379369
configPath: "/test/wrangler.toml",
@@ -413,8 +403,7 @@ describe("getNormalizedContainerOptions", () => {
413403
});
414404

415405
it("should handle config with no configPath", async () => {
416-
mockIsDockerfile.mockReturnValue(true);
417-
406+
writeFileSync("Dockerfile", "FROM scratch");
418407
const config: Config = {
419408
name: "test-worker",
420409
configPath: undefined,
@@ -439,9 +428,9 @@ describe("getNormalizedContainerOptions", () => {
439428

440429
const result = await getNormalizedContainerOptions(config);
441430

442-
// Check that it has dockerfile properties (not registry_link)
431+
// Check that it has dockerfile properties (not image_uri)
443432
expect(result[0]).toHaveProperty("dockerfile");
444433
expect(result[0]).toHaveProperty("image_build_context");
445-
expect(result[0]).not.toHaveProperty("registry_link");
434+
expect(result[0]).not.toHaveProperty("image_uri");
446435
});
447436
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { writeWranglerConfig } from "../helpers/write-wrangler-config";
2626
import type {
2727
AccountRegistryToken,
2828
Application,
29-
ContainerNormalisedConfig,
29+
ContainerNormalizedConfig,
3030
CreateApplicationRequest,
3131
ImageRegistryCredentialsConfiguration,
3232
InstanceType,
@@ -37,9 +37,9 @@ vi.mock("node:child_process");
3737
describe("maybeBuildContainer", () => {
3838
it("Should return imageUpdate: true if using an image URI", async () => {
3939
const config = {
40-
registry_link: "registry.cloudflare.com/some-image:uri",
40+
image_uri: "registry.cloudflare.com/some-image:uri",
4141
class_name: "Test",
42-
} as ContainerNormalisedConfig;
42+
} as ContainerNormalizedConfig;
4343
const result = await maybeBuildContainer(
4444
config,
4545
"some-tag:thing",

0 commit comments

Comments
 (0)