From 8dbb6c58b9f243a740644339e4637f294590c6b1 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 26 Aug 2020 15:58:12 +0200 Subject: [PATCH] Print ACR login debug info Signed-off-by: Guillaume Tardif --- aci/convert/registry_credentials.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/aci/convert/registry_credentials.go b/aci/convert/registry_credentials.go index 77220815d..be94ea5ea 100644 --- a/aci/convert/registry_credentials.go +++ b/aci/convert/registry_credentials.go @@ -70,6 +70,7 @@ func getRegistryCredentials(project compose.Project, helper registryHelper) ([]c for _, registry := range acrRegistries { err := helper.autoLoginAcr(registry) if err != nil { + fmt.Printf("WARNING : %v\n", err) fmt.Printf("Could not automatically login to %s from your Azure login. Assuming you already logged in to the ACR registry\n", registry) } } @@ -158,20 +159,24 @@ func (c cliRegistryHelper) autoLoginAcr(registry string) error { repoAuthURL := fmt.Sprintf("https://%s/oauth2/exchange", registry) res, err := http.Post(repoAuthURL, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) if err != nil { - return err - } - if res.StatusCode != 200 { - return errors.Errorf("error while accessing ACR token from Azure login, status : %s", res.Status) + return errors.Wrap(err, "could not query ACR token") } bits, err := ioutil.ReadAll(res.Body) if err != nil { - return err + return errors.Wrap(err, "could not read response body") + } + if res.StatusCode != 200 { + return errors.Errorf("could not obtain ACR token from Azure login, status : %s, response: %s", res.Status, string(bits)) } newToken := oauth2.Token{} if err := json.Unmarshal(bits, &newToken); err != nil { - return err + return errors.Wrap(err, "could not read ACR token") } - cmd := exec.Command("docker", "login", "-p", newToken.RefreshToken, "-u", tokenUsername, registry) - return cmd.Run() + cmd := exec.Command("docker", "login", "-u", tokenUsername, "-p", newToken.RefreshToken, registry) + bytes, err := cmd.CombinedOutput() + if err != nil { + return errors.Wrap(err, fmt.Sprintf("could not 'docker login' to %s :\n%s\n", registry, string(bytes))) + } + return nil }