Fix: extractImageTag misidentifies registry port as image tag#4110
Open
mahdirajaee wants to merge 64 commits intoDokploy:canaryfrom
Open
Fix: extractImageTag misidentifies registry port as image tag#4110mahdirajaee wants to merge 64 commits intoDokploy:canaryfrom
mahdirajaee wants to merge 64 commits intoDokploy:canaryfrom
Conversation
🚀 Release v0.21.8
🚀 Release v0.22.0
🚀 Release v0.22.1
🚀 Release v0.22.2
🚀 Release v0.22.3
🚀 Release v0.22.4
🚀 Release v0.22.5
🚀 Release v0.22.6
🚀 Release v0.22.7
🚀 Release v0.23.0
🚀 Release v0.23.1
🚀 Release v0.23.2
🚀 Release v0.23.3
🚀 Release v0.23.4
🚀 Release v0.23.5
🚀 Release v0.23.6
🚀 Release v0.23.7
🚀 Release v0.24.0
🚀 Release v0.24.1
🚀 Release v0.24.2
🚀 Release v0.24.3
🚀 Release v0.24.4
🚀 Release v0.24.5
🚀 Release v0.24.6
🚀 Release v0.24.7
🚀 Release v0.24.8
🚀 Release v0.24.9
🚀 Release v0.24.10
🚀 Release v0.24.11
🚀 Release v0.24.12
🚀 Release v0.25.8
🚀 Release v0.25.9
🚀 Release v0.25.10
🚀 Release v0.25.11
🚀 Release v0.26.0
🚀 Release v0.26.1
🚀 Release v0.26.2
🚀 Release v0.26.3
🚀 Release v0.26.4
🚀 Release v0.26.5
🚀 Release v0.26.6
🚀 Release v0.26.7
🚀 Release v0.27.0
refactor(deployments): enhance deployment worker and queue handling f…
🚀 Release v0.27.1
🚀 Release v0.28.0
🚀 Release v0.28.1
🚀 Release v0.28.2
🚀 Release v0.28.3
🚀 Release v0.28.4
🚀 Release v0.28.5
🚀 Release v0.28.6
🚀 Release v0.28.7
🚀 Release v0.28.8
Comment on lines
+327
to
+332
| const afterColon = dockerImage.substring(lastColonIndex + 1); | ||
| if (/^\d{1,5}$/.test(afterColon)) { | ||
| return "latest"; | ||
| } | ||
|
|
||
| return afterColon; |
Contributor
There was a problem hiding this comment.
Port-with-path regex doesn't match the primary fix case
The PR's headline fix case — myregistry:5000/myapp — is not actually fixed by this code.
For "myregistry:5000/myapp":
lastIndexOf(":")→ index 10 (the only colon, aftermyregistry)afterColon→"5000/myapp"/^\d{1,5}$/.test("5000/myapp")→false(the$anchor requires the entire substring to be digits; the/myappsuffix breaks the match)- The function falls through and returns
"5000/myapp"— identical to the old behaviour
The regex correctly handles myregistry:5000 (bare registry with port, no image path) but misses the registry:port/imagepath pattern, which is the dominant real-world form.
A minimal fix is to also accept a digit sequence followed by a /:
Suggested change
| const afterColon = dockerImage.substring(lastColonIndex + 1); | |
| if (/^\d{1,5}$/.test(afterColon)) { | |
| return "latest"; | |
| } | |
| return afterColon; | |
| const afterColon = dockerImage.substring(lastColonIndex + 1); | |
| // Matches a port number either alone (registry:5000) or followed by a path | |
| // (registry:5000/image). Pure-digit tags without a slash are ambiguous but | |
| // consistent with the behaviour of extractImageName. | |
| if (/^\d{1,5}(\/|$)/.test(afterColon)) { | |
| return "latest"; | |
| } | |
| return afterColon; |
With this regex "5000/myapp" matches ^\d{1,5}\/ and returns "latest" as expected, while "v2", "latest", and "1.0.0" are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4082
extractImageTaguses a naivesplit(":")approach that misidentifies the registry port as a tag for private registry images without explicit tags (e.g.,myregistry:5000/myappreturns"5000/myapp"instead of"latest").Changes
Replaced the
split(":").pop()logic withlastIndexOf+ port-number detection, matching the pattern already used inextractImageName.Test Cases
myregistry:5000/myapp"5000/myapp""latest"myregistry:5000/myapp:v2"v2""v2"nginx:latest"latest""latest"nginx"latest""latest"Greptile Summary
This PR attempts to fix
extractImageTagmisidentifying the registry port as a tag for images likemyregistry:5000/myapp, mirroring thelastIndexOf+ port-detection pattern already used inextractImageName.However, the fix is incomplete: the regex
/^\d{1,5}$/only matches a bare port number with nothing following it. For"myregistry:5000/myapp"— the PR's own headline example —afterColonevaluates to"5000/myapp", which fails the digit-only test because of the/myappsuffix. The function therefore falls through and returns"5000/myapp", identical to the broken behaviour before the change.registry:port(no image path),image:tag,image(no colon), andregistry:port/image:tag.registry:port/image(port followed by a path component with no explicit tag), which is the primary scenario reported in issue extractImageTag misidentifies registry port as tag for private registry images without explicit tags #4082.extractImageNamefunction has the same gap (it would return"myregistry"for the same input instead of the full image name), suggesting this is a systemic issue in the port-detection logic shared across the file./^\d{1,5}(\/|$)/to also match a port followed by a path separator.Confidence Score: 4/5
Safe to merge once the regex is widened to cover registry:port/image — a one-character change fixes the incomplete match.
There is one P1 defect: the port-detection regex /^\d{1,5}$/ does not match the primary use-case (registry:port/image) because the afterColon substring includes the path component. The PR's own test table claims 'latest' for this input but the code still returns '5000/myapp'. The fix is structurally correct and almost complete; it just needs the regex extended to /^\d{1,5}(/|$)/. All other test cases (explicit tag, no tag, bare port) behave correctly.
apps/dokploy/pages/api/deploy/[refreshToken].ts — specifically the regex on line 328
Important Files Changed
Reviews (1): Last reviewed commit: "Fix extractImageTag parsing registry por..." | Re-trigger Greptile
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!