Skip to content

Commit 4077af1

Browse files
authored
Merge pull request #4160 from Dokploy/fix/extract-image-tag-port
fix: extractImageTag misidentifies registry port as tag
2 parents c854d4e + 8a043dc commit 4077af1

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

apps/dokploy/__test__/deploy/github.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,5 +415,24 @@ describe("Docker Image Name and Tag Extraction", () => {
415415
expect(extractImageTag("my-image:123")).toBe("123");
416416
expect(extractImageTag("my-image:1")).toBe("1");
417417
});
418+
419+
it("should return 'latest' for registry with port but no tag", () => {
420+
expect(extractImageTag("registry.example.com:5000/myimage")).toBe(
421+
"latest",
422+
);
423+
expect(extractImageTag("registry:5000/fedora/httpd")).toBe("latest");
424+
expect(extractImageTag("localhost:5000/myapp")).toBe("latest");
425+
expect(extractImageTag("my-registry.io:443/org/app")).toBe("latest");
426+
});
427+
428+
it("should extract tag from registry with port and tag", () => {
429+
expect(extractImageTag("registry:5000/image:tag")).toBe("tag");
430+
expect(extractImageTag("registry.example.com:5000/myimage:v2.0")).toBe(
431+
"v2.0",
432+
);
433+
expect(extractImageTag("localhost:5000/app:sha-abc123")).toBe(
434+
"sha-abc123",
435+
);
436+
});
418437
});
419438
});

apps/dokploy/pages/api/deploy/[refreshToken].ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,19 @@ export function extractImageTag(dockerImage: string | null) {
319319
return null;
320320
}
321321

322-
const tag = dockerImage.split(":").pop();
323-
return tag === dockerImage ? "latest" : tag;
322+
const lastColonIndex = dockerImage.lastIndexOf(":");
323+
if (lastColonIndex === -1) {
324+
return "latest";
325+
}
326+
327+
const afterColon = dockerImage.substring(lastColonIndex + 1);
328+
const isPortWithPath = /^\d{1,5}\//.test(afterColon);
329+
330+
if (isPortWithPath) {
331+
return "latest";
332+
}
333+
334+
return afterColon;
324335
}
325336

326337
/**

0 commit comments

Comments
 (0)