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.
This commit is contained in:
Alex Pyrgiotis 2024-03-05 12:18:29 +02:00
parent a31f3370d0
commit be8e2aa36b
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -28,6 +28,13 @@ def main():
action="store_true", action="store_true",
help="Do not save the container image as a tarball in share/container.tar.gz", 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() args = parser.parse_args()
print("Exporting container pip dependencies") print("Exporting container pip dependencies")
@ -71,7 +78,11 @@ def main():
print("Compressing container image") print("Compressing container image")
chunk_size = 4 << 20 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: while True:
chunk = cmd.stdout.read(chunk_size) chunk = cmd.stdout.read(chunk_size)
if len(chunk) > 0: if len(chunk) > 0: