Skip to content

Commit e5dfe0b

Browse files
authored
Revert "Build containers without account ID (#9765)"
This reverts commit 05adc61.
1 parent 3743896 commit e5dfe0b

File tree

9 files changed

+103
-259
lines changed

9 files changed

+103
-259
lines changed

packages/containers-shared/src/images.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { buildImage } from "./build";
2-
import {
3-
getCloudflareContainerRegistry,
4-
isCloudflareRegistryLink,
5-
} from "./knobs";
2+
import { isCloudflareRegistryLink } from "./knobs";
63
import { dockerLoginManagedRegistry } from "./login";
74
import { ContainerDevOptions } from "./types";
85
import {
@@ -107,31 +104,3 @@ export async function prepareContainerImagesForDev(
107104
}
108105
}
109106
}
110-
111-
/**
112-
* Resolve an image name to the full unambiguous name.
113-
*
114-
* For now, this only converts images stored in the managed registry to contain
115-
* the user's account ID in the path.
116-
*/
117-
export async function resolveImageName(
118-
accountId: string,
119-
image: string
120-
): Promise<string> {
121-
let url: URL;
122-
try {
123-
url = new URL(`http://${image}`);
124-
} catch (_) {
125-
return image;
126-
}
127-
128-
if (url.hostname !== getCloudflareContainerRegistry()) {
129-
return image;
130-
}
131-
132-
if (url.pathname.startsWith(`/${accountId}`)) {
133-
return image;
134-
}
135-
136-
return `${url.hostname}/${accountId}${url.pathname}`;
137-
}

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("buildAndMaybePush", () => {
6262
buildCmd: [
6363
"build",
6464
"-t",
65-
`${getCloudflareContainerRegistry()}/test-app:tag`,
65+
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
6666
"--platform",
6767
"linux/amd64",
6868
"--provenance=false",
@@ -73,7 +73,7 @@ describe("buildAndMaybePush", () => {
7373
dockerfile,
7474
});
7575
expect(dockerImageInspect).toHaveBeenCalledWith("/custom/docker/path", {
76-
imageTag: `${getCloudflareContainerRegistry()}/test-app:tag`,
76+
imageTag: `${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
7777
formatString:
7878
"{{ .Size }} {{ len .RootFS.Layers }} {{json .RepoDigests}}",
7979
});
@@ -94,7 +94,7 @@ describe("buildAndMaybePush", () => {
9494
buildCmd: [
9595
"build",
9696
"-t",
97-
`${getCloudflareContainerRegistry()}/test-app:tag`,
97+
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
9898
"--platform",
9999
"linux/amd64",
100100
"--provenance=false",
@@ -104,26 +104,14 @@ describe("buildAndMaybePush", () => {
104104
],
105105
dockerfile,
106106
});
107-
108-
// 3 calls: docker tag + docker push + docker rm
109-
expect(runDockerCmd).toHaveBeenCalledTimes(3);
110-
expect(runDockerCmd).toHaveBeenNthCalledWith(1, "docker", [
111-
"tag",
112-
`${getCloudflareContainerRegistry()}/test-app:tag`,
113-
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
114-
]);
115-
expect(runDockerCmd).toHaveBeenNthCalledWith(2, "docker", [
107+
expect(runDockerCmd).toHaveBeenCalledTimes(1);
108+
expect(runDockerCmd).toHaveBeenCalledWith("docker", [
116109
"push",
117110
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
118111
]);
119-
expect(runDockerCmd).toHaveBeenNthCalledWith(3, "docker", [
120-
"image",
121-
"rm",
122-
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
123-
]);
124112
expect(dockerImageInspect).toHaveBeenCalledOnce();
125113
expect(dockerImageInspect).toHaveBeenCalledWith("docker", {
126-
imageTag: `${getCloudflareContainerRegistry()}/test-app:tag`,
114+
imageTag: `${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
127115
formatString:
128116
"{{ .Size }} {{ len .RootFS.Layers }} {{json .RepoDigests}}",
129117
});
@@ -136,7 +124,7 @@ describe("buildAndMaybePush", () => {
136124
ready: Promise.resolve({ aborted: false }),
137125
});
138126
vi.mocked(dockerImageInspect).mockResolvedValue(
139-
'53387881 2 ["registry.cloudflare.com/test-app@sha256:three"]'
127+
'53387881 2 ["registry.cloudflare.com/some-account-id/test-app@sha256:three"]'
140128
);
141129
await runWrangler(
142130
"containers build ./container-context -t test-app:tag -p"
@@ -145,7 +133,7 @@ describe("buildAndMaybePush", () => {
145133
buildCmd: [
146134
"build",
147135
"-t",
148-
`${getCloudflareContainerRegistry()}/test-app:tag`,
136+
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
149137
"--platform",
150138
"linux/amd64",
151139
"--provenance=false",
@@ -169,11 +157,11 @@ describe("buildAndMaybePush", () => {
169157
expect(runDockerCmd).toHaveBeenNthCalledWith(2, "docker", [
170158
"image",
171159
"rm",
172-
`${getCloudflareContainerRegistry()}/test-app:tag`,
160+
`${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
173161
]);
174162
expect(dockerImageInspect).toHaveBeenCalledOnce();
175163
expect(dockerImageInspect).toHaveBeenCalledWith("docker", {
176-
imageTag: `${getCloudflareContainerRegistry()}/test-app:tag`,
164+
imageTag: `${getCloudflareContainerRegistry()}/some-account-id/test-app:tag`,
177165
formatString:
178166
"{{ .Size }} {{ len .RootFS.Layers }} {{json .RepoDigests}}",
179167
});
@@ -187,7 +175,7 @@ describe("buildAndMaybePush", () => {
187175
buildCmd: [
188176
"build",
189177
"-t",
190-
`${getCloudflareContainerRegistry()}/test-app`,
178+
`${getCloudflareContainerRegistry()}/some-account-id/test-app`,
191179
"--platform",
192180
"linux/amd64",
193181
"--provenance=false",
@@ -209,7 +197,7 @@ describe("buildAndMaybePush", () => {
209197
buildCmd: [
210198
"build",
211199
"-t",
212-
`${getCloudflareContainerRegistry()}/test-app`,
200+
`${getCloudflareContainerRegistry()}/some-account-id/test-app`,
213201
"--platform",
214202
"linux/amd64",
215203
"--provenance=false",
@@ -288,24 +276,27 @@ describe("buildAndMaybePush", () => {
288276
});
289277

290278
describe("resolveAppDiskSize", () => {
279+
const accountBase = {
280+
limits: { disk_mb_per_deployment: 2000 },
281+
} as CompleteAccountCustomer;
291282
it("should return parsed app disk size", () => {
292-
const result = resolveAppDiskSize({
283+
const result = resolveAppDiskSize(accountBase, {
293284
...defaultConfiguration,
294285
configuration: { image: "", disk: { size: "500MB" } },
295286
});
296287
expect(result).toBeCloseTo(500 * 1000 * 1000, -5);
297288
});
298289

299290
it("should return default size when disk size not set", () => {
300-
const result = resolveAppDiskSize({
291+
const result = resolveAppDiskSize(accountBase, {
301292
...defaultConfiguration,
302293
configuration: { image: "" },
303294
});
304295
expect(result).toBeCloseTo(2 * 1000 * 1000 * 1000, -5);
305296
});
306297

307298
it("should return undefined if app is not passed", () => {
308-
expect(resolveAppDiskSize(undefined)).toBeUndefined();
299+
expect(resolveAppDiskSize(accountBase, undefined)).toBeUndefined();
309300
});
310301
});
311302
});

0 commit comments

Comments
 (0)