Use `image.Store` and `content.Store` stored in the ImageService struct
instead of fetching it every time from containerd client.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
| ... | ... |
@@ -178,7 +178,7 @@ func (i *ImageService) GetImageManifest(ctx context.Context, refOrID string, opt |
| 178 | 178 |
platform = platforms.Only(*options.Platform) |
| 179 | 179 |
} |
| 180 | 180 |
|
| 181 |
- cs := i.client.ContentStore() |
|
| 181 |
+ cs := i.content |
|
| 182 | 182 |
|
| 183 | 183 |
img, err := i.resolveImage(ctx, refOrID) |
| 184 | 184 |
if err != nil {
|
| ... | ... |
@@ -237,7 +237,7 @@ func (i *ImageService) GetImageManifest(ctx context.Context, refOrID string, opt |
| 237 | 237 |
func (i *ImageService) size(ctx context.Context, desc ocispec.Descriptor, platform platforms.MatchComparer) (int64, error) {
|
| 238 | 238 |
var size int64 |
| 239 | 239 |
|
| 240 |
- cs := i.client.ContentStore() |
|
| 240 |
+ cs := i.content |
|
| 241 | 241 |
handler := containerdimages.LimitManifests(containerdimages.ChildrenHandler(cs), platform, 1) |
| 242 | 242 |
|
| 243 | 243 |
var wh containerdimages.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
| ... | ... |
@@ -360,7 +360,7 @@ func (i *ImageService) resolveImage(ctx context.Context, refOrID string) (contai |
| 360 | 360 |
// pointing to the same repository as the given reference. |
| 361 | 361 |
func (i *ImageService) getAllImagesWithRepository(ctx context.Context, ref reference.Named) ([]containerdimages.Image, error) {
|
| 362 | 362 |
nameFilter := "^" + regexp.QuoteMeta(ref.Name()) + ":" + reference.TagRegexp.String() + "$" |
| 363 |
- return i.client.ImageService().List(ctx, "name~="+strconv.Quote(nameFilter)) |
|
| 363 |
+ return i.images.List(ctx, "name~="+strconv.Quote(nameFilter)) |
|
| 364 | 364 |
} |
| 365 | 365 |
|
| 366 | 366 |
func imageFamiliarName(img containerdimages.Image) string {
|
| ... | ... |
@@ -378,7 +378,7 @@ func imageFamiliarName(img containerdimages.Image) string {
|
| 378 | 378 |
// targeting the specified digest. |
| 379 | 379 |
// If images have different values, an errdefs.Conflict error will be returned. |
| 380 | 380 |
func (i *ImageService) getImageLabelByDigest(ctx context.Context, target digest.Digest, labelKey string) (string, error) {
|
| 381 |
- imgs, err := i.client.ImageService().List(ctx, "target.digest=="+target.String()+",labels."+labelKey) |
|
| 381 |
+ imgs, err := i.images.List(ctx, "target.digest=="+target.String()+",labels."+labelKey) |
|
| 382 | 382 |
if err != nil {
|
| 383 | 383 |
return "", errdefs.System(err) |
| 384 | 384 |
} |
| ... | ... |
@@ -202,12 +202,12 @@ func newROLayerForImage(ctx context.Context, imgDesc *ocispec.Descriptor, i *Ima |
| 202 | 202 |
platMatcher = platforms.Only(*platform) |
| 203 | 203 |
} |
| 204 | 204 |
|
| 205 |
- confDesc, err := containerdimages.Config(ctx, i.client.ContentStore(), *imgDesc, platMatcher) |
|
| 205 |
+ confDesc, err := containerdimages.Config(ctx, i.content, *imgDesc, platMatcher) |
|
| 206 | 206 |
if err != nil {
|
| 207 | 207 |
return nil, err |
| 208 | 208 |
} |
| 209 | 209 |
|
| 210 |
- diffIDs, err := containerdimages.RootFS(ctx, i.client.ContentStore(), confDesc) |
|
| 210 |
+ diffIDs, err := containerdimages.RootFS(ctx, i.content, confDesc) |
|
| 211 | 211 |
if err != nil {
|
| 212 | 212 |
return nil, err |
| 213 | 213 |
} |
| ... | ... |
@@ -446,7 +446,7 @@ func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent st |
| 446 | 446 |
if err != nil {
|
| 447 | 447 |
return nil, err |
| 448 | 448 |
} |
| 449 |
- parentImageManifest, err := containerdimages.Manifest(ctx, i.client.ContentStore(), parentDesc, platforms.Default()) |
|
| 449 |
+ parentImageManifest, err := containerdimages.Manifest(ctx, i.content, parentDesc, platforms.Default()) |
|
| 450 | 450 |
if err != nil {
|
| 451 | 451 |
return nil, err |
| 452 | 452 |
} |
| ... | ... |
@@ -455,7 +455,7 @@ func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent st |
| 455 | 455 |
parentDigest = parentDesc.Digest |
| 456 | 456 |
} |
| 457 | 457 |
|
| 458 |
- cs := i.client.ContentStore() |
|
| 458 |
+ cs := i.content |
|
| 459 | 459 |
|
| 460 | 460 |
ra, err := cs.ReaderAt(ctx, ocispec.Descriptor{Digest: layerDigest})
|
| 461 | 461 |
if err != nil {
|
| ... | ... |
@@ -504,7 +504,7 @@ func (i *ImageService) createImageOCI(ctx context.Context, imgToCreate imagespec |
| 504 | 504 |
} |
| 505 | 505 |
}() |
| 506 | 506 |
|
| 507 |
- manifestDesc, ccDesc, err := writeContentsForImage(ctx, i.snapshotter, i.client.ContentStore(), imgToCreate, layers, containerConfig) |
|
| 507 |
+ manifestDesc, ccDesc, err := writeContentsForImage(ctx, i.snapshotter, i.content, imgToCreate, layers, containerConfig) |
|
| 508 | 508 |
if err != nil {
|
| 509 | 509 |
return "", err |
| 510 | 510 |
} |
| ... | ... |
@@ -523,13 +523,13 @@ func (i *ImageService) createImageOCI(ctx context.Context, imgToCreate imagespec |
| 523 | 523 |
img.Labels[imageLabelClassicBuilderFromScratch] = "1" |
| 524 | 524 |
} |
| 525 | 525 |
|
| 526 |
- createdImage, err := i.client.ImageService().Update(ctx, img) |
|
| 526 |
+ createdImage, err := i.images.Update(ctx, img) |
|
| 527 | 527 |
if err != nil {
|
| 528 | 528 |
if !cerrdefs.IsNotFound(err) {
|
| 529 | 529 |
return "", err |
| 530 | 530 |
} |
| 531 | 531 |
|
| 532 |
- if createdImage, err = i.client.ImageService().Create(ctx, img); err != nil {
|
|
| 532 |
+ if createdImage, err = i.images.Create(ctx, img); err != nil {
|
|
| 533 | 533 |
return "", fmt.Errorf("failed to create new image: %w", err)
|
| 534 | 534 |
} |
| 535 | 535 |
} |
| ... | ... |
@@ -38,7 +38,7 @@ with adaptations to match the Moby data model and services. |
| 38 | 38 |
// CommitImage creates a new image from a commit config. |
| 39 | 39 |
func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig) (image.ID, error) {
|
| 40 | 40 |
container := i.containers.Get(cc.ContainerID) |
| 41 |
- cs := i.client.ContentStore() |
|
| 41 |
+ cs := i.content |
|
| 42 | 42 |
|
| 43 | 43 |
var parentManifest ocispec.Manifest |
| 44 | 44 |
var parentImage imagespec.DockerOCIImage |
| ... | ... |
@@ -375,7 +375,7 @@ func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image, |
| 375 | 375 |
CreatedAt: time.Now(), |
| 376 | 376 |
Labels: img.Labels, |
| 377 | 377 |
} |
| 378 |
- if _, err = i.client.ImageService().Create(ctx, img); err != nil && !cerrdefs.IsAlreadyExists(err) {
|
|
| 378 |
+ if _, err = i.images.Create(ctx, img); err != nil && !cerrdefs.IsAlreadyExists(err) {
|
|
| 379 | 379 |
return fmt.Errorf("failed to create dangling image: %w", err)
|
| 380 | 380 |
} |
| 381 | 381 |
} |
| ... | ... |
@@ -84,13 +84,12 @@ func (i *ImageService) ImageHistory(ctx context.Context, name string) ([]*imaget |
| 84 | 84 |
return imgs |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
- is := i.client.ImageService() |
|
| 88 | 87 |
currentImg := img |
| 89 | 88 |
for _, h := range history {
|
| 90 | 89 |
dgst := currentImg.Target.Digest.String() |
| 91 | 90 |
h.ID = dgst |
| 92 | 91 |
|
| 93 |
- imgs, err := is.List(ctx, "target.digest=="+dgst) |
|
| 92 |
+ imgs, err := i.images.List(ctx, "target.digest=="+dgst) |
|
| 94 | 93 |
if err != nil {
|
| 95 | 94 |
return nil, err |
| 96 | 95 |
} |
| ... | ... |
@@ -157,5 +156,5 @@ func (i *ImageService) getParentsByBuilderLabel(ctx context.Context, img contain |
| 157 | 157 |
return nil, nil |
| 158 | 158 |
} |
| 159 | 159 |
|
| 160 |
- return i.client.ImageService().List(ctx, "target.digest=="+dgst.String()) |
|
| 160 |
+ return i.images.List(ctx, "target.digest=="+dgst.String()) |
|
| 161 | 161 |
} |
| ... | ... |
@@ -66,7 +66,7 @@ func (i *ImageService) ImportImage(ctx context.Context, ref reference.Named, pla |
| 66 | 66 |
return "", errdefs.InvalidParameter(err) |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 |
- cs := i.client.ContentStore() |
|
| 69 |
+ cs := i.content |
|
| 70 | 70 |
|
| 71 | 71 |
compressedDigest, uncompressedDigest, mt, err := saveArchive(ctx, cs, layerReader) |
| 72 | 72 |
if err != nil {
|
| ... | ... |
@@ -299,11 +299,9 @@ func writeBlobAndReturnDigest(ctx context.Context, cs content.Store, mt string, |
| 299 | 299 |
|
| 300 | 300 |
// saveImage creates an image in the ImageService or updates it if it exists. |
| 301 | 301 |
func (i *ImageService) saveImage(ctx context.Context, img images.Image) error {
|
| 302 |
- is := i.client.ImageService() |
|
| 303 |
- |
|
| 304 |
- if _, err := is.Update(ctx, img); err != nil {
|
|
| 302 |
+ if _, err := i.images.Update(ctx, img); err != nil {
|
|
| 305 | 303 |
if cerrdefs.IsNotFound(err) {
|
| 306 |
- if _, err := is.Create(ctx, img); err != nil {
|
|
| 304 |
+ if _, err := i.images.Create(ctx, img); err != nil {
|
|
| 307 | 305 |
return errdefs.Unknown(err) |
| 308 | 306 |
} |
| 309 | 307 |
} else {
|
| ... | ... |
@@ -72,7 +72,7 @@ func (i *ImageService) Images(ctx context.Context, opts imagetypes.ListOptions) |
| 72 | 72 |
return nil, err |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- imgs, err := i.client.ImageService().List(ctx) |
|
| 75 |
+ imgs, err := i.images.List(ctx) |
|
| 76 | 76 |
if err != nil {
|
| 77 | 77 |
return nil, err |
| 78 | 78 |
} |
| ... | ... |
@@ -103,7 +103,7 @@ func (i *ImageService) Images(ctx context.Context, opts imagetypes.ListOptions) |
| 103 | 103 |
layers = make(map[digest.Digest]int) |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
- contentStore := i.client.ContentStore() |
|
| 106 |
+ contentStore := i.content |
|
| 107 | 107 |
uniqueImages := map[digest.Digest]images.Image{}
|
| 108 | 108 |
tagsByDigest := map[digest.Digest][]string{}
|
| 109 | 109 |
intermediateImages := map[digest.Digest]struct{}{}
|
| ... | ... |
@@ -426,7 +426,7 @@ func (i *ImageService) setupFilters(ctx context.Context, imageFilters filters.Ar |
| 426 | 426 |
return nil, err |
| 427 | 427 |
} |
| 428 | 428 |
|
| 429 |
- labelFn, err := setupLabelFilter(i.client.ContentStore(), imageFilters) |
|
| 429 |
+ labelFn, err := setupLabelFilter(i.content, imageFilters) |
|
| 430 | 430 |
if err != nil {
|
| 431 | 431 |
return nil, err |
| 432 | 432 |
} |
| ... | ... |
@@ -90,7 +90,7 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor |
| 90 | 90 |
}) |
| 91 | 91 |
opts = append(opts, containerd.WithImageHandler(h)) |
| 92 | 92 |
|
| 93 |
- pp := pullProgress{store: i.client.ContentStore(), showExists: true}
|
|
| 93 |
+ pp := pullProgress{store: i.content, showExists: true}
|
|
| 94 | 94 |
finishProgress := jobs.showProgress(ctx, out, pp) |
| 95 | 95 |
|
| 96 | 96 |
var outNewImg *containerd.Image |
| ... | ... |
@@ -140,7 +140,7 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor |
| 140 | 140 |
sentPullingFrom = true |
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 |
- available, _, _, missing, err := images.Check(ctx, i.client.ContentStore(), desc, p) |
|
| 143 |
+ available, _, _, missing, err := images.Check(ctx, i.content, desc, p) |
|
| 144 | 144 |
if err != nil {
|
| 145 | 145 |
return nil, err |
| 146 | 146 |
} |
| ... | ... |
@@ -187,7 +187,7 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor |
| 187 | 187 |
logger.Info("image pulled")
|
| 188 | 188 |
|
| 189 | 189 |
// The pull succeeded, so try to remove any dangling image we have for this target |
| 190 |
- err = i.client.ImageService().Delete(compatcontext.WithoutCancel(ctx), danglingImageName(img.Target().Digest)) |
|
| 190 |
+ err = i.images.Delete(compatcontext.WithoutCancel(ctx), danglingImageName(img.Target().Digest)) |
|
| 191 | 191 |
if err != nil && !cerrdefs.IsNotFound(err) {
|
| 192 | 192 |
// Image pull succeeded, but cleaning up the dangling image failed. Ignore the |
| 193 | 193 |
// error to not mark the pull as failed. |
| ... | ... |
@@ -91,7 +91,7 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, m |
| 91 | 91 |
} |
| 92 | 92 |
}() |
| 93 | 93 |
|
| 94 |
- img, err := i.client.ImageService().Get(ctx, targetRef.String()) |
|
| 94 |
+ img, err := i.images.Get(ctx, targetRef.String()) |
|
| 95 | 95 |
if err != nil {
|
| 96 | 96 |
if cerrdefs.IsNotFound(err) {
|
| 97 | 97 |
return errdefs.NotFound(fmt.Errorf("tag does not exist: %s", reference.FamiliarString(targetRef)))
|
| ... | ... |
@@ -100,7 +100,7 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, m |
| 100 | 100 |
} |
| 101 | 101 |
|
| 102 | 102 |
target := img.Target |
| 103 |
- store := i.client.ContentStore() |
|
| 103 |
+ store := i.content |
|
| 104 | 104 |
|
| 105 | 105 |
resolver, tracker := i.newResolverFromAuthConfig(ctx, authConfig, targetRef) |
| 106 | 106 |
pp := pushProgress{Tracker: tracker}
|
| ... | ... |
@@ -28,8 +28,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re |
| 28 | 28 |
Labels: targetImage.Labels, |
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
- is := i.client.ImageService() |
|
| 32 |
- _, err = is.Create(ctx, newImg) |
|
| 31 |
+ _, err = i.images.Create(ctx, newImg) |
|
| 33 | 32 |
if err != nil {
|
| 34 | 33 |
if !cerrdefs.IsAlreadyExists(err) {
|
| 35 | 34 |
return errdefs.System(errors.Wrapf(err, "failed to create image with name %s and target %s", newImg.Name, newImg.Target.Digest.String())) |
| ... | ... |
@@ -54,7 +53,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re |
| 54 | 54 |
return errors.Wrapf(err, "failed to delete previous image %s", replacedImg.Name) |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
- if _, err = is.Create(compatcontext.WithoutCancel(ctx), newImg); err != nil {
|
|
| 57 |
+ if _, err = i.images.Create(compatcontext.WithoutCancel(ctx), newImg); err != nil {
|
|
| 58 | 58 |
return errdefs.System(errors.Wrapf(err, "failed to create an image %s with target %s after deleting the existing one", |
| 59 | 59 |
newImg.Name, imageID.String())) |
| 60 | 60 |
} |
| ... | ... |
@@ -69,7 +68,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re |
| 69 | 69 |
defer i.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), events.ActionTag) |
| 70 | 70 |
|
| 71 | 71 |
// Delete the source dangling image, as it's no longer dangling. |
| 72 |
- if err := is.Delete(compatcontext.WithoutCancel(ctx), danglingImageName(targetImage.Target.Digest)); err != nil {
|
|
| 72 |
+ if err := i.images.Delete(compatcontext.WithoutCancel(ctx), danglingImageName(targetImage.Target.Digest)); err != nil {
|
|
| 73 | 73 |
logger.WithError(err).Warn("unexpected error when deleting dangling image")
|
| 74 | 74 |
} |
| 75 | 75 |
|