Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module(

# Required dependencies
bazel_dep(name = "platforms", version = "0.0.11")

bazel_dep(name = "zstd", version = "1.5.7")
bazel_dep(name = "rules_multitool", version = "1.11.1")

multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
Expand Down
4 changes: 3 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion minidock/container_data.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ def __container_data_impl(
args.add(ctx.attr.zstd_compression_level, format = "--zstd_compression_level=%s")
args.add(compression, format = "--compression=%s")
args.add(ctx.attr.mtime, format = "--mtime=%s")
args.add(ctx.executable._zstd_tool.path, format = "--zstd_path=%s")

ctx.actions.run(
executable = ctx.executable._build_tar,
arguments = [args],
inputs = ctx.files.tars + [manifest_file] + files,
inputs = ctx.files.tars + [manifest_file] + files + [ctx.executable._zstd_tool],
outputs = [layer],
use_default_shell_env = True,
mnemonic = "ContainerData",
Expand All @@ -144,6 +145,12 @@ container_data = rule(
cfg = "exec",
executable = True,
),
"_zstd_tool": attr.label(
default = Label("@zstd//:zstd_cli"),
cfg = "exec",
executable = True,
allow_single_file = True,
),
"data_path": attr.string(
doc = """Root path of the files.

Expand Down
1 change: 1 addition & 0 deletions minidock/container_data_tools/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
py_binary(
name = "build_tar",
srcs = ["build_tar.py"],
data = ["@zstd//:zstd_cli"],
visibility = ["//visibility:public"],
)
26 changes: 17 additions & 9 deletions minidock/container_data_tools/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self,
compression='',
gzip_compression_level=9,
zstd_compression_level=3,
zstd_path='zstd',
root_directory='./',
default_mtime=None,
preserve_tar_mtimes=True):
Expand All @@ -56,6 +57,7 @@ def __init__(self,
compression: compression type: bzip2, bz2, gz, tgz, xz, lzma, zstd.
gzip_compression_level: compression level for gzip (1-9).
zstd_compression_level: compression level for zstd (1-22).
zstd_path: path to the zstd executable.
root_directory: virtual root to prepend to elements in the archive.
default_mtime: default mtime to use for elements in the archive.
May be an integer or the value 'portable' to use the date
Expand All @@ -72,6 +74,7 @@ def __init__(self,
# Support zstd compression through zstd command line tool
self.zstd = compression == 'zstd'
self.zstd_compression_level = zstd_compression_level
self.zstd_path = zstd_path
self.name = name
self.root_directory = root_directory.rstrip('/')
self.preserve_mtime = preserve_tar_mtimes
Expand Down Expand Up @@ -320,10 +323,10 @@ def add_tar(self,
# Note that we buffer the file in memory and it can have an important
# memory footprint but it's probably fine as we don't use them for really
# large files.
if subprocess.call('which zstd', shell=True, stdout=subprocess.PIPE):
if not os.path.exists(self.zstd_path):
raise self.Error('Cannot handle .zstd compression: '
'zstd command not found.')
p = subprocess.Popen('zstd -dc %s' % tar,
'zstd command not found at %s.' % self.zstd_path)
p = subprocess.Popen('%s -dc %s' % (self.zstd_path, tar),
shell=True,
stdout=subprocess.PIPE)
f = io.BytesIO(p.stdout.read())
Expand Down Expand Up @@ -405,12 +408,12 @@ def close(self):
if self.zstd:
# Support zstd compression through zstd command line tool
# Following same pattern as xz to maintain no-external-dependencies principle
if subprocess.call('which zstd', shell=True, stdout=subprocess.PIPE):
if not os.path.exists(self.zstd_path):
raise self.Error('Cannot handle .zstd compression: '
'zstd command not found.')
'zstd command not found at %s.' % self.zstd_path)
subprocess.call(
'mv {0} {0}.d && zstd -z -{1} {0}.d && mv {0}.d.zst {0}'.format(
self.name, self.zstd_compression_level),
'mv {0} {0}.d && {2} -z -{1} {0}.d && mv {0}.d.zst {0}'.format(
self.name, self.zstd_compression_level, self.zstd_path),
shell=True,
stdout=subprocess.PIPE)

Expand Down Expand Up @@ -446,12 +449,13 @@ def parse_pkg_name(metadata, filename):

def __init__(self, output, directory, root_directory,
default_mtime, enable_mtime_preservation,
force_posixpath, gzip_compression_level, zstd_compression_level=3, compression='gz'):
force_posixpath, gzip_compression_level, zstd_compression_level=3, zstd_path='zstd', compression='gz'):
self.directory = directory
self.output = output
self.compression = compression
self.gzip_compression_level = gzip_compression_level
self.zstd_compression_level = zstd_compression_level
self.zstd_path = zstd_path
self.root_directory = root_directory
self.default_mtime = default_mtime
self.enable_mtime_preservation = enable_mtime_preservation
Expand All @@ -463,6 +467,7 @@ def __enter__(self):
self.compression,
self.gzip_compression_level,
self.zstd_compression_level,
self.zstd_path,
self.root_directory,
self.default_mtime,
self.enable_mtime_preservation,
Expand Down Expand Up @@ -717,7 +722,7 @@ def main(FLAGS):
FLAGS.root_directory, FLAGS.mtime,
FLAGS.enable_mtime_preservation,
FLAGS.force_posixpath, FLAGS.gzip_compression_level,
FLAGS.zstd_compression_level, FLAGS.compression) as output:
FLAGS.zstd_compression_level, FLAGS.zstd_path, FLAGS.compression) as output:
def file_attributes(filename):
if filename.startswith('/'):
filename = filename[1:]
Expand Down Expand Up @@ -831,6 +836,9 @@ def validate_link(l):
parser.add_argument('--zstd_compression_level', type=int, default=3,
help='Set the zstd compression level to use (1-22).')

parser.add_argument('--zstd_path', type=str, default='zstd',
help='Path to the zstd executable.')

parser.add_argument('--compression', type=str, default='gz',
help='Set the compression type: gz, bz2, xz, lzma, zstd, or empty string for no compression.')

Expand Down