Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extra tags to be provided for tagging the manifest list #32

Merged
merged 1 commit into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions docker/createml.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,55 @@ func PutManifestList(a *types.AuthInfo, yamlInput types.YAMLInput, ignoreMissing
}
defer resp.Body.Close()

var finalDigest string
if statusSuccess(resp.StatusCode) {
dgstHeader := resp.Header.Get("Docker-Content-Digest")
dgst, err := digest.Parse(dgstHeader)
if err != nil {
return "", err
}
return string(dgst), nil
finalDigest = string(dgst)
} else {
return "", fmt.Errorf("Registry push unsuccessful: response %d: %s", resp.StatusCode, resp.Status)
}
// if the YAML includes additional tags, push the added tag references. No other work
// should be required as we have already made sure all target blobs are cross-repo
// mounted and all referenced manifests are already pushed.
for _, tag := range yamlInput.Tags {
newRef, err := reference.WithTag(targetRef, tag)
if err != nil {
return "", fmt.Errorf("Error creating tagged reference for added tag %q: %v", tag, err)
}
pushURL, err := createManifestURLFromRef(newRef, urlBuilder)
if err != nil {
return "", fmt.Errorf("Error setting up repository endpoint and references for %q: %v", newRef, err)
}
logrus.Debugf("[extra tag %q] push url: %s", tag, pushURL)
putRequest, err := http.NewRequest("PUT", pushURL, bytes.NewReader(p))
if err != nil {
return "", fmt.Errorf("[extra tag %q] HTTP PUT request creation failed: %v", tag, err)
}
putRequest.Header.Set("Content-Type", mediaType)
resp, err := httpClient.Do(putRequest)
if err != nil {
return "", fmt.Errorf("[extra tag %q] V2 registry PUT of manifest list failed: %v", tag, err)
}
defer resp.Body.Close()

if statusSuccess(resp.StatusCode) {
dgstHeader := resp.Header.Get("Docker-Content-Digest")
dgst, err := digest.Parse(dgstHeader)
if err != nil {
return "", err
}
if string(dgst) != finalDigest {
logrus.Warnf("Extra tag %q push resulted in non-matching digest %s (should be %s", tag, string(dgst), finalDigest)
}
} else {
return "", fmt.Errorf("[extra tag %q] Registry push unsuccessful: response %d: %s", tag, resp.StatusCode, resp.Status)
}
}
return "", fmt.Errorf("Registry push unsuccessful: response %d: %s", resp.StatusCode, resp.Status)
return finalDigest, nil
}

func getHTTPClient(a *types.AuthInfo, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint, repoName string) (*http.Client, error) {
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ImageInspect struct {
// command.
type YAMLInput struct {
Image string
Tags []string
Manifests []ManifestEntry
}

Expand Down