Skip to content

Commit 65ce653

Browse files
Calculate digest if missing
1 parent efad427 commit 65ce653

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

registry/digest.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package registry
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"fmt"
67
"net/http"
78

@@ -36,5 +37,16 @@ func (r *Registry) Digest(ctx context.Context, image Image) (digest.Digest, erro
3637
return "", fmt.Errorf("got status code: %d", resp.StatusCode)
3738
}
3839

39-
return digest.Parse(resp.Header.Get("Docker-Content-Digest"))
40+
d := resp.Header.Get("Docker-Content-Digest")
41+
if d == "" {
42+
// Get the v2 manifest.
43+
m, err := r.Manifest(ctx, image.Path, image.Reference())
44+
if err != nil {
45+
return "", err
46+
}
47+
_, p, _ := m.Payload()
48+
d = fmt.Sprintf("sha256:%x", sha256.Sum256(p))
49+
}
50+
51+
return digest.Parse(d)
4052
}

0 commit comments

Comments
 (0)