Skip to content

Commit

Permalink
Changing configuration option to utilize strings to specify which com…
Browse files Browse the repository at this point in the history
…pression library to use.
  • Loading branch information
alandonham committed Dec 3, 2024
1 parent 2c3a2f0 commit 04188d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions go/cmd/ocitool/createlayer_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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"),
}
}

Expand Down
7 changes: 3 additions & 4 deletions go/cmd/ocitool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions oci/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()] +
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 04188d8

Please sign in to comment.