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

containerd-native converter #224

Merged
merged 1 commit into from
Dec 24, 2020
Merged

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Dec 22, 2020

The nativeconverter package provides containerd-native converter that does not depend on GGCR.

Usage: ctr images convert --oci --estargz SRC DST

Specifying --oci is highly recommended, otherwise "containerd.io/snapshot/stargz/toc.digest" will be lost, unless the original image has already OCI mediatype.

Close #223

@AkihiroSuda AkihiroSuda force-pushed the native-converter branch 8 times, most recently from 7df7cdc to 2eaefb5 Compare December 23, 2020 11:57
@AkihiroSuda AkihiroSuda changed the title [WIP] containerd-native converter containerd-native converter Dec 23, 2020
@AkihiroSuda AkihiroSuda marked this pull request as ready for review December 23, 2020 11:57
@AkihiroSuda
Copy link
Member Author

cc @dmcgowan @fuweid

I'm planning to move nativeconverter pkg (excluding nativeconverter/estargz pkg) in this PR to the main repo.
Aside from eStargz conversion, the package can be used for converting Docker media types to OCI and potentially vice versa: ctr images convert --oci SRC DST

Comment on lines +173 to +193
func readPathsFromRecordFile(filename string) ([]string, error) {
r, err := os.Open(filename)
if err != nil {
return nil, err
}
defer r.Close()
dec := json.NewDecoder(r)
var paths []string
added := make(map[string]struct{})
for dec.More() {
var e recorder.Entry
if err := dec.Decode(&e); err != nil {
return nil, err
}
if _, ok := added[e.Path]; !ok {
paths = append(paths, e.Path)
added[e.Path] = struct{}{}
}
}
return paths, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it per layer in the future.

nativeconverter/nativeconverter.go Show resolved Hide resolved
nativeconverter/nativeconverter.go Outdated Show resolved Hide resolved
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +380 to +381
cfg DualConfig
cfgAsOCI ocispec.Image // read only, used for parsing cfg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

The `nativeconverter` package provides containerd-native converter that does not depend on GGCR.

Usage: `ctr images convert --oci --estargz SRC DST`

Specifying `--oci` is highly recommended, otherwise "containerd.io/snapshot/stargz/toc.digest" will be lost,
unless the original image has already OCI mediatype.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

ready to merge?

@ktock
Copy link
Member

ktock commented Dec 24, 2020

Yes!

@ktock ktock merged commit c0cd3fb into containerd:master Dec 24, 2020
AkihiroSuda added a commit to AkihiroSuda/containerd that referenced this pull request Jan 22, 2021
Go example:
```go
opts := []converter.Opt{
  // convert Docker media types to OCI ones
  converter.WithDocker2OCI(true),
  // convert tar.gz layers to uncompressed tar layers
  converter.WithLayerConvertFunc(uncompress.LayerConvertFunc),
}
srcRef := "example.com/foo:orig"
dstRef := "example.com/foo:converted"
dstImg, err = converter.Convert(ctx, client, dstRef, srcRef, opts...)
fmt.Println(dstImg.Target)
```

ctr example: `ctr images convert --oci --uncompress example.com/foo:orig example.com/foo:converted`

Go test: `go test -exec sudo -test.root -test.run TestConvert`

The implementation is from containerd/stargz-snapshotter#224,
but eStargz-specific functions are not included in this PR.

eStargz converter can be specified by importing `estargz` package and using `WithLayerConvertFunc(estargz.LayerConvertFunc)` option.

This converter interface will be potentially useful for converting zstd and ocicrypt layers as well.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimizer: imageio should use containerd native API
2 participants