Skip to content

Commit 6982cda

Browse files
author
clarehkli
committed
add support for the new --estargz-gzip-helper option in stargz-snapshotter
add support for the newly added image conversion --estargz-gzip-helper option in stargz-snapshotter Signed-off-by: clarehkli <clarehkli@tencent.com>
1 parent 356c99a commit 6982cda

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

cmd/nerdctl/image/image_convert.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func convertCommand() *cobra.Command {
6161
cmd.Flags().Int("estargz-min-chunk-size", 0, "The minimal number of bytes of data must be written in one gzip stream. (requires stargz-snapshotter >= v0.13.0)")
6262
cmd.Flags().Bool("estargz-external-toc", false, "Separate TOC JSON into another image (called \"TOC image\"). The name of TOC image is the original + \"-esgztoc\" suffix. Both eStargz and the TOC image should be pushed to the same registry. (requires stargz-snapshotter >= v0.13.0) (EXPERIMENTAL)")
6363
cmd.Flags().Bool("estargz-keep-diff-id", false, "Convert to esgz without changing diffID (cannot be used in conjunction with '--estargz-record-in'. must be specified with '--estargz-external-toc')")
64+
cmd.Flags().String("estargz-gzip-helper", "", "Helper command for decompressing layers compressed with gzip. Options: pigz, igzip, or gzip.")
6465
// #endregion
6566

6667
// #region zstd flags
@@ -149,6 +150,10 @@ func convertOptions(cmd *cobra.Command) (types.ImageConvertOptions, error) {
149150
if err != nil {
150151
return types.ImageConvertOptions{}, err
151152
}
153+
estargzGzipHelper, err := cmd.Flags().GetString("estargz-gzip-helper")
154+
if err != nil {
155+
return types.ImageConvertOptions{}, err
156+
}
152157
// #endregion
153158

154159
// #region zstd flags
@@ -275,6 +280,7 @@ func convertOptions(cmd *cobra.Command) (types.ImageConvertOptions, error) {
275280
EstargzMinChunkSize: estargzMinChunkSize,
276281
EstargzExternalToc: estargzExternalTOC,
277282
EstargzKeepDiffID: estargzKeepDiffID,
283+
EstargzGzipHelper: estargzGzipHelper,
278284
},
279285
ZstdOptions: types.ZstdOptions{
280286
Zstd: zstd,

docs/stargz.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,20 @@ Stargz Snapshotter is not needed for building stargz images.
9292

9393
## Tips for image conversion
9494

95-
### Tips 1: Creating smaller eStargz images
95+
### Tips 1: Using gzip helper to speed up image conversion
96+
97+
When converting a traditional overlayfs image encoded as tar.gz to an estargz format image, nerdctl supports specifying an additional command‑line decompression tool to speed up the conversion process. You can set `--estargz-gzip-helper` to choose different CLI gzip tools. Even using the gzip command corresponding to the Go gzip library can achieve approximately 32% speed improvement. For more details, see: [Using decompression commands to improve the layer decompression speed of gzip-formatted images](https://github.com/containerd/stargz-snapshotter/pull/2117). Currently, `--estargz-gzip-helper` supports `pigz`, `igzip`, and `gzip`. The recommended order is `pigz` > `igzip` > `gzip`.
98+
99+
```console
100+
# nerdctl image convert --oci --estargz --estargz-gzip-helper pigz ghcr.io/stargz-containers/ubuntu:22.04 ghcr.io/stargz-containers/ubuntu:22.04-esgz
101+
sha256:aa6543b9885867b8b485925b6ec69d8e018e8fce40835ea6359cbb573683a014
102+
# nerdctl image ls
103+
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE
104+
ghcr.io/stargz-containers/ubuntu 22.04-esgz aa6543b98858 About a minute ago linux/amd64 0B 32.43MB
105+
ghcr.io/stargz-containers/ubuntu 22.04 20fa2d7bb4de 2 minutes ago linux/amd64 87.47MB 30.43MB
106+
```
107+
108+
### Tips 2: Creating smaller eStargz images
96109

97110
`nerdctl image convert` allows the following flags for optionally creating a smaller eStargz image.
98111
The result image requires stargz-snapshotter >= v0.13.0 for lazy pulling.
@@ -167,7 +180,7 @@ sha256:7f5cbd8cc787c8d628630756bcc7240e6c96b876c2882e6fc980a8b60cdfa274
167180
sha256:7f5cbd8cc787c8d628630756bcc7240e6c96b876c2882e6fc980a8b60cdfa274
168181
```
169182

170-
### Tips 2: Using zstd instead of gzip (a.k.a. zstd:chunked)
183+
### Tips 3: Using zstd instead of gzip (a.k.a. zstd:chunked)
171184

172185
You can use zstd compression with lazy pulling support (a.k.a zstd:chunked) instead of gzip.
173186

pkg/api/types/image_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ type EstargzOptions struct {
9292
EstargzExternalToc bool
9393
// EstargzKeepDiffID convert to esgz without changing diffID (cannot be used in conjunction with '--estargz-record-in'. must be specified with '--estargz-external-toc')
9494
EstargzKeepDiffID bool
95+
// EstargzGzipHelper helper command for decompressing layers compressed with gzip. Options: pigz, igzip, or gzip
96+
EstargzGzipHelper string
9597
}
9698

9799
// ZstdOptions contains zstd conversion options

pkg/cmd/image/convert.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
estargzexternaltocconvert "github.com/containerd/stargz-snapshotter/nativeconverter/estargz/externaltoc"
4242
zstdchunkedconvert "github.com/containerd/stargz-snapshotter/nativeconverter/zstdchunked"
4343
"github.com/containerd/stargz-snapshotter/recorder"
44+
estargzdecompressutil "github.com/containerd/stargz-snapshotter/util/decompressutil"
4445

4546
"github.com/containerd/nerdctl/v2/pkg/api/types"
4647
"github.com/containerd/nerdctl/v2/pkg/clientutil"
@@ -285,6 +286,13 @@ func getESGZConvertOpts(options types.ImageConvertOptions) ([]estargz.Option, er
285286
var ignored []string
286287
esgzOpts = append(esgzOpts, estargz.WithAllowPrioritizeNotFound(&ignored))
287288
}
289+
if options.EstargzGzipHelper != "" {
290+
gzipHelperFunc, err := estargzdecompressutil.GetGzipHelperFunc(options.EstargzGzipHelper)
291+
if err != nil {
292+
return nil, err
293+
}
294+
esgzOpts = append(esgzOpts, estargz.WithGzipHelperFunc(gzipHelperFunc))
295+
}
288296
return esgzOpts, nil
289297
}
290298

0 commit comments

Comments
 (0)