Skip to content

Commit d69e125

Browse files
Merge pull request #53 from drone-plugins/CI-15702
fix: [CI-15702]: Override dockerhub v2 url to v1
2 parents 78d2e90 + 3e5570e commit d69e125

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docker.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ type (
139139
}
140140
)
141141

142+
const (
143+
v2HubRegistryURL string = "https://registry.hub.docker.com/v2/"
144+
v1RegistryURL string = "https://index.docker.io/v1/" // Default registry
145+
v2RegistryURL string = "https://index.docker.io/v2/" // v2 registry is not supported
146+
)
147+
142148
// Exec executes the plugin step
143149
func (p Plugin) Exec() error {
144150

@@ -453,14 +459,20 @@ func getDigest(metadataFile string) (string, error) {
453459

454460
// helper function to create the docker login command.
455461
func commandLogin(login Login) *exec.Cmd {
456-
if login.Email != "" {
457-
return commandLoginEmail(login)
462+
loginCopy := login
463+
// update v2 docker registry to v1
464+
if loginCopy.Registry == v2RegistryURL || loginCopy.Registry == v2HubRegistryURL {
465+
fmt.Fprintf(os.Stdout, "Found dockerhub v2 registry, overriding with v1 registry instead: %s\n", v1RegistryURL)
466+
loginCopy.Registry = v1RegistryURL
467+
}
468+
if loginCopy.Email != "" {
469+
return commandLoginEmail(loginCopy)
458470
}
459471
return exec.Command(
460472
dockerExe, "login",
461-
"-u", login.Username,
462-
"-p", login.Password,
463-
login.Registry,
473+
"-u", loginCopy.Username,
474+
"-p", loginCopy.Password,
475+
loginCopy.Registry,
464476
)
465477
}
466478

0 commit comments

Comments
 (0)