diff --git a/apps/dokploy/__test__/deploy/github.test.ts b/apps/dokploy/__test__/deploy/github.test.ts index d2e773dfc..104e108f1 100644 --- a/apps/dokploy/__test__/deploy/github.test.ts +++ b/apps/dokploy/__test__/deploy/github.test.ts @@ -415,5 +415,24 @@ describe("Docker Image Name and Tag Extraction", () => { expect(extractImageTag("my-image:123")).toBe("123"); expect(extractImageTag("my-image:1")).toBe("1"); }); + + it("should return 'latest' for registry with port but no tag", () => { + expect(extractImageTag("registry.example.com:5000/myimage")).toBe( + "latest", + ); + expect(extractImageTag("registry:5000/fedora/httpd")).toBe("latest"); + expect(extractImageTag("localhost:5000/myapp")).toBe("latest"); + expect(extractImageTag("my-registry.io:443/org/app")).toBe("latest"); + }); + + it("should extract tag from registry with port and tag", () => { + expect(extractImageTag("registry:5000/image:tag")).toBe("tag"); + expect(extractImageTag("registry.example.com:5000/myimage:v2.0")).toBe( + "v2.0", + ); + expect(extractImageTag("localhost:5000/app:sha-abc123")).toBe( + "sha-abc123", + ); + }); }); }); diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index 1c57731a7..1a99c3a8e 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -319,8 +319,19 @@ export function extractImageTag(dockerImage: string | null) { return null; } - const tag = dockerImage.split(":").pop(); - return tag === dockerImage ? "latest" : tag; + const lastColonIndex = dockerImage.lastIndexOf(":"); + if (lastColonIndex === -1) { + return "latest"; + } + + const afterColon = dockerImage.substring(lastColonIndex + 1); + const isPortWithPath = /^\d{1,5}\//.test(afterColon); + + if (isPortWithPath) { + return "latest"; + } + + return afterColon; } /**