Skip to content
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

Allow config files to be mounted #1387

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/v1/partial/compressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func TestRemote(t *testing.T) {
if got, want := ok, true; got != want {
t.Errorf("Exists() = %t != %t", got, want)
}

cl, err := partial.ConfigLayer(img)
if err != nil {
t.Fatal(err)
}
if _, ok := cl.(*remote.MountableLayer); !ok {
t.Errorf("ConfigLayer() expected to be MountableLayer, got %T", cl)
}
}

type noDiffID struct {
Expand Down
13 changes: 13 additions & 0 deletions pkg/v1/partial/with.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,22 @@ func (cl *configLayer) MediaType() (types.MediaType, error) {

var _ v1.Layer = (*configLayer)(nil)

// withConfigLayer allows partial image implementations to provide a layer
// for their config file.
type withConfigLayer interface {
ConfigLayer() (v1.Layer, error)
}

// ConfigLayer implements v1.Layer from the raw config bytes.
// This is so that clients (e.g. remote) can access the config as a blob.
//
// Images that want to return a specific layer implementation can implement
// withConfigLayer.
func ConfigLayer(i WithRawConfigFile) (v1.Layer, error) {
if wcl, ok := unwrap(i).(withConfigLayer); ok {
return wcl.ConfigLayer()
}

h, err := ConfigName(i)
if err != nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions pkg/v1/remote/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ func (mi *mountableImage) LayerByDiffID(d v1.Hash) (v1.Layer, error) {
func (mi *mountableImage) Descriptor() (*v1.Descriptor, error) {
return partial.Descriptor(mi.Image)
}

// ConfigLayer retains the original reference so that it can be mounted.
// See partial.ConfigLayer.
func (mi *mountableImage) ConfigLayer() (v1.Layer, error) {
l, err := partial.ConfigLayer(mi.Image)
if err != nil {
return nil, err
}
return &MountableLayer{
Layer: l,
Reference: mi.Reference,
}, nil
}