Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

i remove image, use hub.ManifestDigest("nginx", "1.14.1"),but in the manifest.go ManifestDigest() resp == nil #65

Open
ap6108 opened this issue Nov 27, 2018 · 3 comments

Comments

@ap6108
Copy link

ap6108 commented Nov 27, 2018

i remove image, use hub.ManifestDigest("nginx", "1.14.1"),
but in the manifest.go ManifestDigest() resp == nil.
sameple is :
digest, err2 := hub.ManifestDigest(requestObject.Name, requestObject.Version)
in the menifest.go 👍
resp, err := registry.Client.Head(url)
fmt.Printf("resp %+v\n", resp)

the resp is nil
how to do it?
thanks!

@kispaljr
Copy link

kispaljr commented Nov 27, 2018

Hi!

Well, the name of the nginx repository should be library/nginx.
Otherwise this works for me:

package main

import (
	"fmt"

	"github.com/heroku/docker-registry-client/registry"
)

func main() {
	url := "https://registry-1.docker.io/"
	username := "" // anonymous
	password := "" // anonymous
	hub, err := registry.New(url, username, password)

	digest, err := hub.ManifestDigest("library/nginx", "1.14.1")
	fmt.Print(digest, err)
}

Please note however that the return value will be the hash of the schema1 manifest. For the schema2 manifest you should use something like the method added in @peragwin's PR: #51

@ap6108
Copy link
Author

ap6108 commented Nov 28, 2018

in v2,docker 17.03, it is also get nil resp. the error is:
ManifestDigest: Head http://192.168.2.39:8082/v2/httpd/manifests/2.4.37: http: non-successful response (status=404 body="")

func (registry *Registry) ManifestV2Digest(repository, reference string) (digest.Digest, error) {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.head url=%s repository=%s reference=%s", url, repository, reference)
req, err := http.NewRequest("HEAD", url, nil)
if err != nil {
return "", err
}
req.Header.Set("Accept", schema2.MediaTypeManifest)
resp, err := registry.Client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return "", err
}
return digest.Parse(resp.Header.Get("Docker-Content-Digest"))
}
but it fail.

if i do this:
curl -u admin:admin123 --head -XGET -H "Accept: application/vnd.docker.distribution.manifest.v2+json" http://192.168.2.39:8082/v2/httpd/manifests/2.4.37
it is ok.

and how do solved it?

@ap6108
Copy link
Author

ap6108 commented Nov 28, 2018

i solved it. the fuc ManifestV2Digest() modify "HEAD" to "GET"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants