Skip to content

Commit 4d4646b

Browse files
committed
use userConfigPath instead of redirected one
1 parent c7de92e commit 4d4646b

File tree

7 files changed

+122
-5
lines changed

7 files changed

+122
-5
lines changed

.changeset/breezy-regions-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/containers-shared": patch
3+
"wrangler": patch
4+
---
5+
6+
Resolve container image path based on the user's original config path instead of redirected config

packages/containers-shared/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export function isDir(path: string) {
102102
/** returns true if it is a dockerfile, false if it is a registry link, throws if neither */
103103
export const isDockerfile = (
104104
image: string,
105+
/** The original (non-redirected) user config path */
105106
configPath: string | undefined
106107
): boolean => {
107108
const baseDir = configPath ? path.dirname(configPath) : process.cwd();

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,113 @@ describe("wrangler deploy with containers", () => {
346346
expect(std.warn).toMatchInlineSnapshot(`""`);
347347
});
348348

349+
it("resolve the dockerfile based on the non-redirected userConfigPath rather than the actual config path", async () => {
350+
vi.stubEnv("WRANGLER_DOCKER_BIN", "/usr/bin/docker");
351+
mockGetVersion("Galaxy-Class");
352+
353+
vi.mocked(spawn)
354+
.mockImplementationOnce(mockDockerInfo())
355+
.mockImplementationOnce(
356+
mockDockerBuild(
357+
"my-container",
358+
"Galaxy",
359+
"FROM scratch",
360+
// note that the cwd for the test is not the same as the cwd that the wrangler command is running in
361+
// fortunately we are using an absolute path
362+
process.cwd()
363+
)
364+
)
365+
.mockImplementationOnce(mockDockerImageInspect("my-container", "Galaxy"))
366+
.mockImplementationOnce(mockDockerLogin("mockpassword"))
367+
.mockImplementationOnce(
368+
mockDockerManifestInspect("some-account-id/my-container", true)
369+
)
370+
.mockImplementationOnce(
371+
mockDockerTag("my-container", "some-account-id/my-container", "Galaxy")
372+
)
373+
.mockImplementationOnce(
374+
mockDockerPush("some-account-id/my-container", "Galaxy")
375+
)
376+
.mockImplementationOnce(
377+
mockDockerImageDelete("some-account-id/my-container", "Galaxy")
378+
);
379+
380+
mockContainersAccount();
381+
382+
const wranglerConfig = {
383+
main: "index.js",
384+
durable_objects: {
385+
bindings: [
386+
{
387+
name: "EXAMPLE_DO_BINDING",
388+
class_name: "ExampleDurableObject",
389+
},
390+
],
391+
},
392+
containers: [
393+
{
394+
name: "my-container",
395+
max_instances: 10,
396+
class_name: "ExampleDurableObject",
397+
image: "./Dockerfile",
398+
},
399+
],
400+
migrations: [{ tag: "v1", new_sqlite_classes: ["ExampleDurableObject"] }],
401+
};
402+
// user wrangler config
403+
writeWranglerConfig(wranglerConfig, "./wrangler.json");
404+
// set up redirected config
405+
fs.mkdirSync(".wrangler/deploy", { recursive: true });
406+
fs.writeFileSync(
407+
".wrangler/deploy/config.json",
408+
JSON.stringify({ configPath: "./wrangler.json" })
409+
);
410+
writeWranglerConfig(
411+
{ ...wranglerConfig, main: "../../index.js" },
412+
".wrangler/deploy/wrangler.json"
413+
);
414+
// dockerfile is in the root of the project
415+
fs.writeFileSync("Dockerfile", "FROM scratch");
416+
mockGetApplications([]);
417+
418+
mockGenerateImageRegistryCredentials();
419+
420+
mockCreateApplication({
421+
name: "my-container",
422+
max_instances: 10,
423+
durable_objects: { namespace_id: "1" },
424+
configuration: {
425+
image:
426+
getCloudflareContainerRegistry() +
427+
"/some-account-id/my-container:Galaxy",
428+
},
429+
});
430+
431+
await runWrangler("deploy");
432+
expect(std.info).toMatchInlineSnapshot(`
433+
"Using redirected Wrangler configuration.
434+
- Configuration being used: \\".wrangler/deploy/wrangler.json\\"
435+
- Original user's configuration: \\"wrangler.json\\"
436+
- Deploy configuration file: \\".wrangler/deploy/config.json\\""
437+
`);
438+
expect(std.out).toMatchInlineSnapshot(`
439+
"Total Upload: xx KiB / gzip: xx KiB
440+
Worker Startup Time: 100 ms
441+
Your Worker has access to the following bindings:
442+
Binding Resource
443+
env.EXAMPLE_DO_BINDING (ExampleDurableObject) Durable Object
444+
445+
Uploaded test-name (TIMINGS)
446+
Building image my-container:Galaxy
447+
Image does not exist remotely, pushing: registry.cloudflare.com/some-account-id/my-container:Galaxy
448+
Deployed test-name triggers (TIMINGS)
449+
https://test-name.test-sub-domain.workers.dev
450+
Current Version ID: Galaxy-Class"
451+
`);
452+
453+
expect(std.err).toMatchInlineSnapshot(`""`);
454+
expect(std.warn).toMatchInlineSnapshot(`""`);
455+
});
349456
it("should support deploying a worker with multiple containers", async () => {
350457
mockGetVersion(
351458
"Galaxy-Class",

packages/wrangler/src/api/startDevWorker/ConfigController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ async function resolveConfig(
400400
// container API client is properly set so that we can get the correct permissions
401401
// from the cloudchamber API to pull from the repository.
402402
const needsPulling = resolved.containers?.some(
403-
(c) => !isDockerfile(c.image ?? c.configuration?.image, config.configPath)
403+
(c) =>
404+
!isDockerfile(c.image ?? c.configuration?.image, config.userConfigPath)
404405
);
405406
if (needsPulling && !resolved.dev.remote) {
406407
await fillOpenAPIConfiguration(config, containersScope);

packages/wrangler/src/cloudchamber/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export async function buildCommand(
239239
},
240240
getDockerPath() ?? args.pathToDocker,
241241
args.push,
242-
config.configPath,
242+
config.userConfigPath,
243243
container
244244
);
245245
}

packages/wrangler/src/cloudchamber/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function maybeBuildContainer(
1717
imageTag: string,
1818
dryRun: boolean,
1919
pathToDocker: string,
20+
/** The original (non-redirected) user config path */
2021
configPath?: string
2122
): Promise<{ image: string; imageUpdated: boolean }> {
2223
try {
@@ -120,7 +121,7 @@ export async function deployContainers(
120121
versionId,
121122
dryRun,
122123
pathToDocker,
123-
config.configPath
124+
config.userConfigPath
124125
);
125126
container.configuration ??= {};
126127
container.configuration.image = buildResult.image;

packages/wrangler/src/deploy/deploy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
786786
const hasDockerfiles = config.containers.some((container) =>
787787
isDockerfile(
788788
container.image ?? container.configuration?.image,
789-
config.configPath
789+
// this is the original (non-redirected) config path
790+
config.userConfigPath
790791
)
791792
);
792793
if (hasDockerfiles) {
@@ -802,7 +803,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
802803
workerTag ?? "worker-tag",
803804
props.dryRun,
804805
dockerPath,
805-
config.configPath
806+
config.userConfigPath
806807
);
807808
}
808809
}

0 commit comments

Comments
 (0)