diff --git a/go/cmd/ocitool/createlayer_cmd.go b/go/cmd/ocitool/createlayer_cmd.go index eb4c9a5..d5947f0 100644 --- a/go/cmd/ocitool/createlayer_cmd.go +++ b/go/cmd/ocitool/createlayer_cmd.go @@ -41,7 +41,7 @@ func CreateLayerCmd(c *cli.Context) error { var gzipWriter *gzip.Writer var mediaType string - if config.UseZstd { + if config.Compression == "COMPRESSION_ZSTD" { zstdWriter = zstd.NewWriter(wc) mediaType = ocispec.MediaTypeImageLayerZstd tw = tar.NewWriter(zstdWriter) @@ -82,7 +82,7 @@ func CreateLayerCmd(c *cli.Context) error { // Need to flush before we count bytes and digest, might as well close since // it's not needed anymore. tw.Close() - if config.UseZstd { + if config.Compression == "COMPRESSION_ZSTD" { zstdWriter.Close() } else { gzipWriter.Close() @@ -118,7 +118,7 @@ type createLayerConfig struct { FileMapping map[string]string `json:"file-map" toml:"file-map" yaml:"file-map"` OutputLayer string `json:"out" toml:"out" yaml:"out"` SymlinkMapping map[string]string `json:"symlink" toml:"symlink" yaml:"symlink"` - UseZstd bool `json:"zstd-compression" toml:"zstd-compression" yaml:"zstd-compression"` + Compression string `json:"compression" toml:"compression" yaml:"compression"` } func newCreateLayerConfig(c *cli.Context) *createLayerConfig { @@ -130,7 +130,7 @@ func newCreateLayerConfig(c *cli.Context) *createLayerConfig { OutputLayer: c.String("out"), Descriptor: c.String("outd"), SymlinkMapping: c.Generic("symlink").(*flagutil.KeyValueFlag).Map, - UseZstd: c.Bool("zstd-compression"), + Compression: c.String("compression"), } } diff --git a/go/cmd/ocitool/main.go b/go/cmd/ocitool/main.go index d14ec50..2982657 100644 --- a/go/cmd/ocitool/main.go +++ b/go/cmd/ocitool/main.go @@ -70,10 +70,9 @@ var app = &cli.App{ Name: "file-map", Value: &flagutil.KeyValueFlag{}, }, - &cli.BoolFlag{ - Name: "zstd-compression", - Usage: "Use the zstd library for compression.", - Value: false, + &cli.StringFlag{ + Name: "compression", + Usage: "Select a library to use for compression.", }, }, }, diff --git a/oci/image.bzl b/oci/image.bzl index f2e4cf5..8d2e8db 100755 --- a/oci/image.bzl +++ b/oci/image.bzl @@ -27,7 +27,7 @@ def _oci_image_layer_impl(ctx): descriptor_file = ctx.actions.declare_file("{}.descriptor.json".format(ctx.label.name)) archive = None - if ctx.attr.zstd_compression: + if ctx.attr.compression == "COMPRESSION_ZSTD": archive = ctx.actions.declare_file(ctx.label.name + ".tar.zst") else: archive = ctx.actions.declare_file(ctx.label.name + ".tar.gz") @@ -40,7 +40,7 @@ def _oci_image_layer_impl(ctx): "--outd={}".format(descriptor_file.path), "--dir={}".format(ctx.attr.directory), "--bazel-label={}".format(ctx.label), - "--zstd-compression={}".format(ctx.attr.zstd_compression), + "--compression={}".format(ctx.attr.compression), ] + ["--file={}".format(f.path) for f in ctx.files.files] + ["--symlink={}={}".format(k, v) for k, v in ctx.attr.symlinks.items()] + @@ -78,9 +78,9 @@ oci_image_layer = rule( doc = "Dictionary of file -> file location in tarball", allow_files = True, ), - "zstd_compression": attr.bool( - doc = "Indicates whether zstd compression should be used.", - default = False, + "compression": attr.string( + doc = "Indicates which compression library should be used. Options include COMPRESSION_GZIP and COMPRESSION_ZSTD.", + default = "COMPRESSION_GZIP", ), }, toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],