forked from google/go-containerregistry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to filter layers from tarball
Continuation of this PR: google#209 This should be considered a relatively advanced option, but for folks that know what they are doing you can reduce the amount of data that you need to encode in the tarball for the daemon to load it. The ultimate use case of this option will be from daemon.Write, which currently uses the docker load interface to pull image into the daemon, however, this currently reuploads (and redownloads) the base image on each write in context like ko. If we can determine the set of layers that already exist in the daemon we can elide these from the tarball to dramatically improve performance. Related: google#205
- Loading branch information
1 parent
ff1ac7f
commit 2dce6f7
Showing
5 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
// Copyright 2019 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tarball | ||
|
||
import ( | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
) | ||
|
||
// Option is a functional option for tarball operations. | ||
type Option func(*options) error | ||
|
||
// LayerFilter defines a function for filtering layers. | ||
// True - indicates the layer should be kept, | ||
// False - indicates the layer should be excluded. | ||
type LayerFilter func(v1.Layer) (bool, error) | ||
|
||
type options struct { | ||
filter LayerFilter | ||
} | ||
|
||
func makeOptions(opts ...Option) (*options, error) { | ||
o := &options{ | ||
filter: func(v1.Layer) (bool, error) { | ||
return true, nil | ||
}, | ||
} | ||
|
||
for _, option := range opts { | ||
if err := option(o); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return o, nil | ||
} | ||
|
||
// WithLayerFilter allows omitting layers when writing a tarball. | ||
func WithLayerFilter(lf LayerFilter) Option { | ||
return func(o *options) error { | ||
o.filter = lf | ||
return nil | ||
} | ||
} |
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