Skip to content

Commit

Permalink
Calculate digest if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Nov 5, 2022
1 parent efad427 commit ce4cf85
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion registry/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package registry

import (
"context"
_ "crypto/sha256"
"fmt"
"net/http"

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

return digest.Parse(resp.Header.Get("Docker-Content-Digest"))
d := resp.Header.Get("Docker-Content-Digest")
if d == "" {
// Get the v2 manifest.
m, err := r.Manifest(ctx, image.Path, image.Reference())
if err != nil {
return "", err
}
_, p, _ := m.Payload()
return digest.FromBytes(p), nil
}

return digest.Parse(d)
}

0 comments on commit ce4cf85

Please sign in to comment.