From be8e2aa36b95ec7de7cedadb2e7b748c853c84e9 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 5 Mar 2024 12:18:29 +0200 Subject: [PATCH] Allow setting the compression level of the image There are times where we may want to build the container image for testing, but compression takes too much time. If we don't plan to use this image for production builds, we can specify instead a compression level that is so low, that the image will be compressed instantly. In this commit, we allow the user to specify the Gzip compression level, and even set it to 0. The default will always be 9, so that we don't make a mistake during release. --- install/common/build-image.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/install/common/build-image.py b/install/common/build-image.py index 4f75bfc..4308c3b 100644 --- a/install/common/build-image.py +++ b/install/common/build-image.py @@ -28,6 +28,13 @@ def main(): action="store_true", help="Do not save the container image as a tarball in share/container.tar.gz", ) + parser.add_argument( + "--compress-level", + type=int, + choices=range(0, 10), + default=9, + help="The Gzip compression level, from 0 (lowest) to 9 (highest, default)", + ) args = parser.parse_args() print("Exporting container pip dependencies") @@ -71,7 +78,11 @@ def main(): print("Compressing container image") chunk_size = 4 << 20 - with gzip.open("share/container.tar.gz", "wb") as gzip_f: + with gzip.open( + "share/container.tar.gz", + "wb", + compresslevel=args.compress_level, + ) as gzip_f: while True: chunk = cmd.stdout.read(chunk_size) if len(chunk) > 0: