Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/spicy-buttons-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

Handle registry ports when matching container image digests

Wrangler now strips tags without breaking registry ports when comparing local
images to remote digests. This prevents unnecessary pushes for tags like
`localhost:5000/app:tag`.
36 changes: 36 additions & 0 deletions packages/wrangler/src/__tests__/cloudchamber/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,42 @@ describe("buildAndMaybePush", () => {
expect(dockerLoginImageRegistry).toHaveBeenCalledOnce();
});

it("should match digests for images with registry ports", async () => {
vi.mocked(runDockerCmd).mockResolvedValueOnce({
abort: () => {},
ready: Promise.resolve({ aborted: false }),
});
vi.mocked(dockerImageInspect).mockReset();
vi.mocked(dockerImageInspect)
.mockResolvedValueOnce(
'["localhost:5000/test-app@sha256:three"]'
)
.mockResolvedValueOnce("53387881 2");
vi.mocked(runDockerCmdWithOutput).mockReset();
vi.mocked(runDockerCmdWithOutput).mockImplementationOnce(() => {
return '{"Descriptor":{"digest":"sha256:three"}}';
});

await runWrangler(
"containers build ./container-context -t localhost:5000/test-app:tag -p"
);

expect(runDockerCmdWithOutput).toHaveBeenCalledOnce();
expect(runDockerCmdWithOutput).toHaveBeenCalledWith("docker", [
"manifest",
"inspect",
"-v",
"localhost:5000/test-app@sha256:three",
]);
expect(runDockerCmd).toHaveBeenCalledTimes(1);
expect(runDockerCmd).toHaveBeenCalledWith("docker", [
"image",
"rm",
"localhost:5000/test-app:tag",
]);
expect(dockerLoginImageRegistry).toHaveBeenCalledOnce();
});

it("should be able to build image and not push", async () => {
await runWrangler("containers build ./container-context -t test-app");
expect(dockerBuild).toHaveBeenCalledTimes(1);
Expand Down
15 changes: 11 additions & 4 deletions packages/wrangler/src/cloudchamber/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import type {
} from "@cloudflare/containers-shared";
import type { Config } from "@cloudflare/workers-utils";

function stripImageTag(image: string): string {
const [name] = image.split("@");
const lastColon = name.lastIndexOf(":");
const lastSlash = name.lastIndexOf("/");

return lastColon > lastSlash ? name.slice(0, lastColon) : name;
}

export function buildYargs(yargs: CommonYargsArgv) {
return yargs
.positional("PATH", {
Expand Down Expand Up @@ -162,10 +170,9 @@ export async function buildAndMaybePush(
);
}

const repositoryOnly = resolveImageName(
account.external_account_id,
imageTag
).split(":")[0];
const repositoryOnly = stripImageTag(
resolveImageName(account.external_account_id, imageTag)
);

logger.debug("respositoryOnly:", repositoryOnly);

Expand Down