-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Do not re-tag non-distributable blob descriptors #2561
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78bb713
Do not re-tag non-distributable blob descriptors
cpuguy83 893bfdd
Move non-dist layer conversion to GetRemotes
cpuguy83 3a2a031
Add foreign-layer integration tests
cpuguy83 758410d
Cleanup foreign-layers implementation
cpuguy83 c332148
push: always skip foreign layers
cpuguy83 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package config | ||
|
||
import "github.com/moby/buildkit/util/compression" | ||
|
||
type RefConfig struct { | ||
Compression compression.Config | ||
PreferNonDistributable bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,13 @@ import ( | |
|
||
"github.com/containerd/containerd/content" | ||
"github.com/containerd/containerd/errdefs" | ||
"github.com/containerd/containerd/images" | ||
"github.com/containerd/containerd/leases" | ||
"github.com/containerd/containerd/mount" | ||
"github.com/containerd/containerd/snapshots" | ||
"github.com/docker/docker/pkg/idtools" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/moby/buildkit/cache/config" | ||
"github.com/moby/buildkit/identity" | ||
"github.com/moby/buildkit/session" | ||
"github.com/moby/buildkit/snapshot" | ||
|
@@ -47,7 +49,7 @@ type ImmutableRef interface { | |
Finalize(context.Context) error | ||
|
||
Extract(ctx context.Context, s session.Group) error // +progress | ||
GetRemotes(ctx context.Context, createIfNeeded bool, compressionopt compression.Config, all bool, s session.Group) ([]*solver.Remote, error) | ||
GetRemotes(ctx context.Context, createIfNeeded bool, cfg config.RefConfig, all bool, s session.Group) ([]*solver.Remote, error) | ||
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. 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. Maybe functional options? |
||
LayerChain() RefList | ||
} | ||
|
||
|
@@ -589,7 +591,48 @@ func (sr *immutableRef) Clone() ImmutableRef { | |
return sr.clone() | ||
} | ||
|
||
func (sr *immutableRef) ociDesc(ctx context.Context, dhs DescHandlers) (ocispecs.Descriptor, error) { | ||
// layertoDistributable changes the passed in media type to the "distributable" version of the media type. | ||
func layerToDistributable(mt string) string { | ||
if !images.IsNonDistributable(mt) { | ||
// Layer is already a distributable media type (or this is not even a layer). | ||
// No conversion needed | ||
return mt | ||
} | ||
|
||
switch mt { | ||
case ocispecs.MediaTypeImageLayerNonDistributable: | ||
return ocispecs.MediaTypeImageLayer | ||
case ocispecs.MediaTypeImageLayerNonDistributableGzip: | ||
return ocispecs.MediaTypeImageLayerGzip | ||
case ocispecs.MediaTypeImageLayerNonDistributableZstd: | ||
return ocispecs.MediaTypeImageLayerZstd | ||
case images.MediaTypeDockerSchema2LayerForeign: | ||
return images.MediaTypeDockerSchema2Layer | ||
case images.MediaTypeDockerSchema2LayerForeignGzip: | ||
return images.MediaTypeDockerSchema2LayerGzip | ||
default: | ||
return mt | ||
} | ||
} | ||
|
||
func layerToNonDistributable(mt string) string { | ||
switch mt { | ||
case ocispecs.MediaTypeImageLayer: | ||
return ocispecs.MediaTypeImageLayerNonDistributable | ||
case ocispecs.MediaTypeImageLayerGzip: | ||
return ocispecs.MediaTypeImageLayerNonDistributableGzip | ||
case ocispecs.MediaTypeImageLayerZstd: | ||
return ocispecs.MediaTypeImageLayerNonDistributableZstd | ||
case images.MediaTypeDockerSchema2Layer: | ||
return images.MediaTypeDockerSchema2LayerForeign | ||
case images.MediaTypeDockerSchema2LayerForeignGzip: | ||
return images.MediaTypeDockerSchema2LayerForeignGzip | ||
default: | ||
return mt | ||
} | ||
} | ||
|
||
func (sr *immutableRef) ociDesc(ctx context.Context, dhs DescHandlers, preferNonDist bool) (ocispecs.Descriptor, error) { | ||
dgst := sr.getBlob() | ||
if dgst == "" { | ||
return ocispecs.Descriptor{}, errors.Errorf("no blob set for cache record %s", sr.ID()) | ||
|
@@ -598,8 +641,21 @@ func (sr *immutableRef) ociDesc(ctx context.Context, dhs DescHandlers) (ocispecs | |
desc := ocispecs.Descriptor{ | ||
Digest: sr.getBlob(), | ||
Size: sr.getBlobSize(), | ||
MediaType: sr.getMediaType(), | ||
Annotations: make(map[string]string), | ||
MediaType: sr.getMediaType(), | ||
} | ||
|
||
if preferNonDist { | ||
if urls := sr.getURLs(); len(urls) > 0 { | ||
// Make sure the media type is the non-distributable version | ||
// We don't want to rely on the stored media type here because it could have been stored as distributable originally. | ||
desc.MediaType = layerToNonDistributable(desc.MediaType) | ||
desc.URLs = urls | ||
} | ||
} | ||
if len(desc.URLs) == 0 { | ||
// If there are no URL's, there is no reason to have this be non-dsitributable | ||
desc.MediaType = layerToDistributable(desc.MediaType) | ||
} | ||
|
||
if blobDesc, err := getBlobDesc(ctx, sr.cm.ContentStore, desc.Digest); err == nil { | ||
|
@@ -748,6 +804,7 @@ func getBlobDesc(ctx context.Context, cs content.Store, dgst digest.Digest) (oci | |
if !ok { | ||
return ocispecs.Descriptor{}, fmt.Errorf("no media type is stored for %q", info.Digest) | ||
} | ||
|
||
desc := ocispecs.Descriptor{ | ||
Digest: info.Digest, | ||
Size: info.Size, | ||
|
@@ -1062,7 +1119,7 @@ func (sr *immutableRef) unlazyLayer(ctx context.Context, dhs DescHandlers, pg pr | |
}) | ||
} | ||
|
||
desc, err := sr.ociDesc(ctx, dhs) | ||
desc, err := sr.ociDesc(ctx, dhs, true) | ||
cpuguy83 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a use case that required a separate packages for this definition?
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.
Import cycle from cache->solver->cache
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.
Ok, let's figure this out later. It's more about what the dependency between solver and cache pkg should be.