Skip to content

Commit 8f765d7

Browse files
Copilotj143
andauthored
Fix credentialed localhost registry resolution to use HTTP
Agent-Logs-Url: https://github.com/j143/basic-docker-engine/sessions/9b259d2d-2dd2-4094-849b-5fb1f50355c2 Co-authored-by: j143 <53068787+j143@users.noreply.github.com>
1 parent ffd1c98 commit 8f765d7

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ func resolveRegistry(imageName string) (string, string) {
617617
parts := strings.SplitN(imageName, "/", 2)
618618
if len(parts) == 2 {
619619
host := parts[0]
620+
if at := strings.LastIndex(host, "@"); at >= 0 && at < len(host)-1 {
621+
host = host[at+1:]
622+
}
620623
if strings.Contains(host, ".") || strings.Contains(host, ":") || host == "localhost" {
621624
registryURL = registryURLForHost(host)
622625
repo = parts[1]

main_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ func TestResolveRegistry(t *testing.T) {
158158
wantRegistry: "http://[::1]:5000/v2/",
159159
wantRepository: "alpine:latest",
160160
},
161+
{
162+
name: "credentialed local registry over http",
163+
imageName: "user:password@localhost:5000/alpine",
164+
wantRegistry: "http://localhost:5000/v2/",
165+
wantRepository: "alpine",
166+
},
161167
}
162168

163169
for _, tt := range tests {

0 commit comments

Comments
 (0)