server: skip blob verification for already verified blobs
This commit is contained in:
parent
98e65929dc
commit
de5beb06b3
2 changed files with 18 additions and 14 deletions
|
@ -340,17 +340,17 @@ type downloadOpts struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloadBlob downloads a blob from the registry and stores it in the blobs directory
|
// downloadBlob downloads a blob from the registry and stores it in the blobs directory
|
||||||
func downloadBlob(ctx context.Context, opts downloadOpts) error {
|
func downloadBlob(ctx context.Context, opts downloadOpts) (cacheHit bool, _ error) {
|
||||||
fp, err := GetBlobsPath(opts.digest)
|
fp, err := GetBlobsPath(opts.digest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := os.Stat(fp)
|
fi, err := os.Stat(fp)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, os.ErrNotExist):
|
case errors.Is(err, os.ErrNotExist):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return err
|
return false, err
|
||||||
default:
|
default:
|
||||||
opts.fn(api.ProgressResponse{
|
opts.fn(api.ProgressResponse{
|
||||||
Status: fmt.Sprintf("pulling %s", opts.digest[7:19]),
|
Status: fmt.Sprintf("pulling %s", opts.digest[7:19]),
|
||||||
|
@ -359,7 +359,7 @@ func downloadBlob(ctx context.Context, opts downloadOpts) error {
|
||||||
Completed: fi.Size(),
|
Completed: fi.Size(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
data, ok := blobDownloadManager.LoadOrStore(opts.digest, &blobDownload{Name: fp, Digest: opts.digest})
|
data, ok := blobDownloadManager.LoadOrStore(opts.digest, &blobDownload{Name: fp, Digest: opts.digest})
|
||||||
|
@ -369,12 +369,12 @@ func downloadBlob(ctx context.Context, opts downloadOpts) error {
|
||||||
requestURL = requestURL.JoinPath("v2", opts.mp.GetNamespaceRepository(), "blobs", opts.digest)
|
requestURL = requestURL.JoinPath("v2", opts.mp.GetNamespaceRepository(), "blobs", opts.digest)
|
||||||
if err := download.Prepare(ctx, requestURL, opts.regOpts); err != nil {
|
if err := download.Prepare(ctx, requestURL, opts.regOpts); err != nil {
|
||||||
blobDownloadManager.Delete(opts.digest)
|
blobDownloadManager.Delete(opts.digest)
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:contextcheck
|
//nolint:contextcheck
|
||||||
go download.Run(context.Background(), requestURL, opts.regOpts)
|
go download.Run(context.Background(), requestURL, opts.regOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
return download.Wait(ctx, opts.fn)
|
return false, download.Wait(ctx, opts.fn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,23 +853,27 @@ func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn fu
|
||||||
layers = append(layers, manifest.Layers...)
|
layers = append(layers, manifest.Layers...)
|
||||||
layers = append(layers, manifest.Config)
|
layers = append(layers, manifest.Config)
|
||||||
|
|
||||||
|
skipVerify := make(map[string]bool)
|
||||||
for _, layer := range layers {
|
for _, layer := range layers {
|
||||||
if err := downloadBlob(
|
cacheHit, err := downloadBlob(ctx, downloadOpts{
|
||||||
ctx,
|
mp: mp,
|
||||||
downloadOpts{
|
digest: layer.Digest,
|
||||||
mp: mp,
|
regOpts: regOpts,
|
||||||
digest: layer.Digest,
|
fn: fn,
|
||||||
regOpts: regOpts,
|
})
|
||||||
fn: fn,
|
if err != nil {
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
skipVerify[layer.Digest] = cacheHit
|
||||||
delete(deleteMap, layer.Digest)
|
delete(deleteMap, layer.Digest)
|
||||||
}
|
}
|
||||||
delete(deleteMap, manifest.Config.Digest)
|
delete(deleteMap, manifest.Config.Digest)
|
||||||
|
|
||||||
fn(api.ProgressResponse{Status: "verifying sha256 digest"})
|
fn(api.ProgressResponse{Status: "verifying sha256 digest"})
|
||||||
for _, layer := range layers {
|
for _, layer := range layers {
|
||||||
|
if skipVerify[layer.Digest] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := verifyBlob(layer.Digest); err != nil {
|
if err := verifyBlob(layer.Digest); err != nil {
|
||||||
if errors.Is(err, errDigestMismatch) {
|
if errors.Is(err, errDigestMismatch) {
|
||||||
// something went wrong, delete the blob
|
// something went wrong, delete the blob
|
||||||
|
|
Loading…
Reference in a new issue