New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import/export support for OCI compatible image manifest version of cache manifest (opt-in on export, inferred on import) #3724
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package remotecache | |
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"sync" | ||
"time" | ||
|
@@ -14,6 +15,7 @@ import ( | |
"github.com/moby/buildkit/solver" | ||
"github.com/moby/buildkit/util/bklog" | ||
"github.com/moby/buildkit/util/imageutil" | ||
"github.com/moby/buildkit/util/progress" | ||
"github.com/moby/buildkit/worker" | ||
digest "github.com/opencontainers/go-digest" | ||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
|
@@ -47,24 +49,52 @@ func (ci *contentCacheImporter) Resolve(ctx context.Context, desc ocispecs.Descr | |
return nil, err | ||
} | ||
|
||
var mfst ocispecs.Index | ||
if err := json.Unmarshal(dt, &mfst); err != nil { | ||
manifestType, err := imageutil.DetectManifestBlobMediaType(dt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
allLayers := v1.DescriptorProvider{} | ||
layerDone := progress.OneOff(ctx, fmt.Sprintf("inferred cache manifest type: %s", manifestType)) | ||
layerDone(nil) | ||
|
||
allLayers := v1.DescriptorProvider{} | ||
var configDesc ocispecs.Descriptor | ||
|
||
for _, m := range mfst.Manifests { | ||
if m.MediaType == v1.CacheConfigMediaTypeV0 { | ||
configDesc = m | ||
continue | ||
switch manifestType { | ||
case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex: | ||
var mfst ocispecs.Index | ||
if err := json.Unmarshal(dt, &mfst); err != nil { | ||
return nil, err | ||
} | ||
allLayers[m.Digest] = v1.DescriptorProviderPair{ | ||
Descriptor: m, | ||
Provider: ci.provider, | ||
|
||
for _, m := range mfst.Manifests { | ||
if m.MediaType == v1.CacheConfigMediaTypeV0 { | ||
configDesc = m | ||
continue | ||
} | ||
allLayers[m.Digest] = v1.DescriptorProviderPair{ | ||
Descriptor: m, | ||
Provider: ci.provider, | ||
} | ||
} | ||
case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest: | ||
var mfst ocispecs.Manifest | ||
if err := json.Unmarshal(dt, &mfst); err != nil { | ||
return nil, err | ||
} | ||
|
||
if mfst.Config.MediaType == v1.CacheConfigMediaTypeV0 { | ||
configDesc = mfst.Config | ||
} | ||
for _, m := range mfst.Layers { | ||
allLayers[m.Digest] = v1.DescriptorProviderPair{ | ||
Descriptor: m, | ||
Provider: ci.provider, | ||
} | ||
} | ||
default: | ||
err = errors.Wrapf(err, "unsupported or uninferrable manifest type") | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would work fine if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, my apologies for not seeing the integ test failure indicating this issue: I did see some integ tests fail without any changes from my part so I thought that was attributable to other changes in master. Very good catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tested in my local, ripping out 88-91 does indeed fix the integ tests failing below. |
||
} | ||
|
||
if dsls, ok := ci.provider.(DistributionSourceLabelSetter); ok { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be follow-up, but I guess manifest list of "cache image manifests" should also be a valid configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure I should tackle this because I don't know how such a cache would/could be exported.