mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
Merge pull request #4160 from Dokploy/fix/extract-image-tag-port
fix: extractImageTag misidentifies registry port as tag
This commit is contained in:
@@ -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",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user