add label flags to ctr import, add integration tests
Signed-off-by: roman-kiselenko <roman.kiselenko.dev@gmail.com>
This commit is contained in:
committed by
roman-kiselenko
parent
0bb7fd36ce
commit
a3c62e698d
@@ -38,6 +38,7 @@ type importOpts struct {
|
||||
compress bool
|
||||
discardLayers bool
|
||||
skipMissing bool
|
||||
imageLabels map[string]string
|
||||
}
|
||||
|
||||
// ImportOpt allows the caller to specify import specific options
|
||||
@@ -52,6 +53,14 @@ func WithImageRefTranslator(f func(string) string) ImportOpt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithImageLabels are the image labels to apply to a new image
|
||||
func WithImageLabels(labels map[string]string) ImportOpt {
|
||||
return func(c *importOpts) error {
|
||||
c.imageLabels = labels
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithDigestRef is used to create digest images for each
|
||||
// manifest in the index.
|
||||
func WithDigestRef(f func(digest.Digest) string) ImportOpt {
|
||||
@@ -223,7 +232,12 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
|
||||
}
|
||||
|
||||
for i := range imgs {
|
||||
img, err := is.Update(ctx, imgs[i], "target")
|
||||
fieldsPath := []string{"target"}
|
||||
if iopts.imageLabels != nil {
|
||||
fieldsPath = append(fieldsPath, "labels")
|
||||
imgs[i].Labels = iopts.imageLabels
|
||||
}
|
||||
img, err := is.Update(ctx, imgs[i], fieldsPath...)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user