mirror of https://github.com/docker/docs.git
Improve the error management with the registry communication
This commit is contained in:
parent
fc0eac37e4
commit
77549ad4f6
35
registry.go
35
registry.go
|
|
@ -58,7 +58,10 @@ func (graph *Graph) getRemoteHistory(imgId string, authConfig *auth.AuthConfig)
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil || res.StatusCode != 200 {
|
||||||
|
if res != nil {
|
||||||
|
return nil, fmt.Errorf("Internal server error: %d trying to fetch remote history for %s", res.StatusCode, imgId)
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
@ -85,7 +88,7 @@ func (graph *Graph) LookupRemoteImage(imgId string, authConfig *auth.AuthConfig)
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil || res.StatusCode != 307 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return res.StatusCode == 307
|
return res.StatusCode == 307
|
||||||
|
|
@ -103,7 +106,10 @@ func (graph *Graph) getRemoteImage(imgId string, authConfig *auth.AuthConfig) (*
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil || res.StatusCode != 307 {
|
||||||
|
if res != nil {
|
||||||
|
return nil, nil, fmt.Errorf("Internal server error: %d trying to get image %s", res.StatusCode, imgId)
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
@ -159,7 +165,10 @@ func (graph *Graph) PullRepository(user, repoName, askedTag string, repositories
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil || res.StatusCode != 200 {
|
||||||
|
if res != nil {
|
||||||
|
return fmt.Errorf("Internal server error: %d trying to pull %s", res.StatusCode, repoName)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
@ -221,8 +230,8 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
|
||||||
return fmt.Errorf("Error: Invalid Json")
|
return fmt.Errorf("Error: Invalid Json")
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Error: Internal server error trying to push image {%s} (json): %s (%d)\n",
|
"Error: Internal server error: %d trying to push image {%s} (json): %s\n",
|
||||||
img.Id, err, res.StatusCode)
|
res.StatusCode, img.Id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,7 +240,7 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
|
||||||
res2, err := client.Do(req2)
|
res2, err := client.Do(req2)
|
||||||
if err != nil || res2.StatusCode != 307 {
|
if err != nil || res2.StatusCode != 307 {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Error trying to push image {%s} (layer 1): %s\n",
|
"Internal server error trying to push image {%s} (layer 1): %s\n",
|
||||||
img.Id, err)
|
img.Id, err)
|
||||||
}
|
}
|
||||||
url, err := res2.Location()
|
url, err := res2.Location()
|
||||||
|
|
@ -266,11 +275,10 @@ func (graph *Graph) PushImage(imgOrig *Image, authConfig *auth.AuthConfig) error
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Error trying to push image {%s} (layer 2): %s\n",
|
"Error trying to push image {%s} (layer 2): %s\n",
|
||||||
img.Id, err)
|
img.Id, err)
|
||||||
} else {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"Error trying to push image {%s} (layer 2): %s (%d)\n",
|
|
||||||
img.Id, err, res3.StatusCode)
|
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf(
|
||||||
|
"Error trying to push image {%s} (layer 2): %s (%d)\n",
|
||||||
|
img.Id, err, res3.StatusCode)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
@ -292,7 +300,10 @@ func (graph *Graph) pushTag(user, repo, revision, tag string, authConfig *auth.A
|
||||||
req.Header.Add("Content-type", "application/json")
|
req.Header.Add("Content-type", "application/json")
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil || (res.StatusCode != 200 && res.StatusCode != 201) {
|
||||||
|
if res != nil {
|
||||||
|
return fmt.Errorf("Internal server error: %d trying to push tag %s on %s/%s", res.StatusCode, tag, user, repo)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("Result of push tag: %d\n", res.StatusCode)
|
fmt.Printf("Result of push tag: %d\n", res.StatusCode)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue