c8d/cache: Use ContainerConfig from content store

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-01-16 13:42:50 +01:00
parent f760cb4f97
commit 8390bc5683
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A
4 changed files with 38 additions and 16 deletions

View file

@ -5,10 +5,14 @@ import (
"reflect"
"strings"
"github.com/containerd/log"
"github.com/docker/docker/api/types/container"
imagetype "github.com/docker/docker/api/types/image"
"github.com/docker/docker/builder"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// MakeImageCache creates a stateful image cache.
@ -71,12 +75,35 @@ func (ic *localCache) GetCache(parentID string, cfg *container.Config) (imageID
var match *image.Image
for _, child := range children {
childImage, err := ic.imageService.GetImage(ctx, child.String(), imagetype.GetImageOpts{})
ccDigestStr, err := ic.imageService.getImageLabelByDigest(ctx, child.Digest(), imageLabelClassicBuilderContainerConfig)
if err != nil {
return "", err
}
if ccDigestStr == "" {
continue
}
dgst, err := digest.Parse(ccDigestStr)
if err != nil {
log.G(ctx).WithError(err).Warnf("invalid container config digest: %q", ccDigestStr)
continue
}
var cc container.Config
if err := readConfig(ctx, ic.imageService.content, ocispec.Descriptor{Digest: dgst}, &cc); err != nil {
if errdefs.IsNotFound(err) {
log.G(ctx).WithError(err).WithField("image", child).Warnf("missing container config: %q", ccDigestStr)
continue
}
return "", err
}
if isMatch(&cc, cfg) {
childImage, err := ic.imageService.GetImage(ctx, child.String(), imagetype.GetImageOpts{})
if err != nil {
return "", err
}
if isMatch(&childImage.ContainerConfig, cfg) {
if childImage.Created != nil && (match == nil || match.Created.Before(*childImage.Created)) {
match = childImage
}

View file

@ -144,8 +144,7 @@ func generateCommitImageConfig(baseConfig imagespec.DockerOCIImage, diffID diges
EmptyLayer: diffID == "",
}),
},
Config: containerConfigToDockerOCIImageConfig(opts.Config),
ContainerConfig: containerConfigToDockerOCIImageConfig(opts.ContainerConfig),
Config: containerConfigToDockerOCIImageConfig(opts.Config),
}
}

View file

@ -18,14 +18,13 @@ import (
// - Details
func dockerOciImageToDockerImagePartial(id image.ID, img imagespec.DockerOCIImage) *image.Image {
v1Image := image.V1Image{
DockerVersion: dockerversion.Version,
Config: dockerOCIImageConfigToContainerConfig(img.Config),
ContainerConfig: *dockerOCIImageConfigToContainerConfig(img.ContainerConfig),
Architecture: img.Platform.Architecture,
Variant: img.Platform.Variant,
OS: img.Platform.OS,
Author: img.Author,
Created: img.Created,
DockerVersion: dockerversion.Version,
Config: dockerOCIImageConfigToContainerConfig(img.Config),
Architecture: img.Platform.Architecture,
Variant: img.Platform.Variant,
OS: img.Platform.OS,
Author: img.Author,
Created: img.Created,
}
rootFS := &image.RootFS{
@ -67,8 +66,7 @@ func dockerImageToDockerOCIImage(img image.Image) imagespec.DockerOCIImage {
RootFS: rootfs,
History: img.History,
},
Config: containerConfigToDockerOCIImageConfig(img.Config),
ContainerConfig: containerConfigToDockerOCIImageConfig(&img.ContainerConfig),
Config: containerConfigToDockerOCIImageConfig(img.Config),
}
}

View file

@ -14,8 +14,6 @@ type DockerOCIImage struct {
// Shadow ocispec.Image.Config
Config DockerOCIImageConfig `json:"config,omitempty"`
ContainerConfig DockerOCIImageConfig `json:"container_config,omitempty"`
}
// DockerOCIImageConfig is a ocispec.ImageConfig extended with Docker specific fields.