Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop compressing applehv and hyperv by default #3982

Merged
merged 2 commits into from
Dec 4, 2024
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
28 changes: 18 additions & 10 deletions src/cmd-compress
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ else:
print(f"Targeting build: {build}")

# common extensions for known compressors
ext_dict = {'xz': '.xz', 'gzip': '.gz', 'zstd': '.zst'}
ext_dict = {'xz': '.xz', 'gzip': '.gz', 'zstd': '.zst', 'zip': '.zip'}


def get_cpu_param(param):
Expand All @@ -65,7 +65,7 @@ def strip_ext(path):
return path.rsplit(".", 1)[0]


def compress_one_builddir(builddir):
def compress_one_builddir(builddir, platform_compressors):
print(f"Compressing: {builddir}")
buildmeta_path = os.path.join(builddir, 'meta.json')
# In the case where we are doing builds for different architectures
Expand All @@ -77,9 +77,6 @@ def compress_one_builddir(builddir):
with open(buildmeta_path) as f:
buildmeta = json.load(f)

# Find what extension to use based on the selected compressor
ext = ext_dict[args.compressor]

tmpdir = 'tmp/compress'
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
Expand All @@ -106,6 +103,10 @@ def compress_one_builddir(builddir):
if only_artifacts is not None and img_format not in only_artifacts:
continue

compressor = platform_compressors.get(img_format) or args.compressor
# Find what extension to use based on the selected compressor
ext = ext_dict[compressor]

file = img['path']
filepath = os.path.join(builddir, file)
if img.get('uncompressed-sha256') is None:
Expand All @@ -116,12 +117,16 @@ def compress_one_builddir(builddir):
img['uncompressed-size'] = img['size']
with open(tmpfile, 'wb') as f:
t = ncpu()
if args.compressor == 'xz':
if compressor == 'xz':
runcmd(['xz', '-c9', f'-T{t}', filepath], stdout=f)
elif args.compressor == 'zstd':
elif compressor == 'zstd':
runcmd(['zstd', '-10', '-c', f'-T{t}', filepath], stdout=f)
else:
elif compressor == 'gzip':
runcmd(['gzip', f'-{gzip_level}', '-c', filepath], stdout=f) # pylint: disable=E0606
Comment on lines +124 to 125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noting here that this gzip-level is not the same as the one used previously from qemuvariants.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we care, just noting the change

elif compressor == 'zip':
runcmd(['zip', '-9j', '-', filepath], stdout=f) # pylint: disable=E0606
else:
raise Exception(f"Unknown compressor: {compressor}")
file_with_ext = file + ext
filepath_with_ext = filepath + ext
compressed_size = os.path.getsize(tmpfile)
Expand Down Expand Up @@ -202,6 +207,8 @@ def uncompress_one_builddir(builddir):
runcmd(['zstd', '-dc', filepath], stdout=f)
elif file.endswith('gz'):
runcmd(['gzip', '-dc', filepath], stdout=f)
elif file.endswith('zip'):
runcmd(['unzip', '-p', filepath], stdout=f)
else:
print(f"Unknown sufix of file {file}")
file_without_ext = strip_ext(file)
Expand Down Expand Up @@ -266,16 +273,17 @@ changed = []
if args.mode == "compress":
# Find what compressor we should use, either picking it up from
# CLI args or from image.json
image_json = get_image_json()
gzip_level = 6
if args.fast:
args.compressor = 'gzip'
gzip_level = 1
elif not args.compressor:
image_json = get_image_json()
args.compressor = image_json.get('compressor', DEFAULT_COMPRESSOR)
for arch in builds.get_build_arches(build):
builddir = builds.get_build_dir(build, arch)
changed.append(compress_one_builddir(builddir))
changed.append(compress_one_builddir(builddir,
image_json.get('platform-compressor', {})))
if not any(changed):
print("All builds already compressed")
elif args.mode == "uncompress":
Expand Down
6 changes: 3 additions & 3 deletions src/cmd-osbuild
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ dn=$(dirname "$0")
# A list of supported platforms and the filename suffix of the main
# artifact that platform produces.
declare -A SUPPORTED_PLATFORMS=(
['applehv']='raw.gz'
['applehv']='raw'
['gcp']='tar.gz'
['hyperv']='vhdx.zip'
['hyperv']='vhdx'
['metal4k']='raw'
['metal']='raw'
['qemu']='qcow2'
Expand Down Expand Up @@ -384,7 +384,7 @@ main() {

# Perform postprocessing
case "$platform" in
applehv|gcp|hyperv)
gcp)
# Update the meta.json and builddir with the generated artifact.
# Skip Compression on these platforms as they are already compressed.
postprocess_artifact "${platform}" "${imgpath}" "${imgname}" 'True'
Expand Down
8 changes: 2 additions & 6 deletions src/cosalib/qemuvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
},
"applehv": {
"image_format": "raw",
"image_suffix": "raw.gz",
"platform": "applehv",
"compression": "gzip"
"platform": "applehv"
},
"azure": {
"image_format": "vpc",
Expand Down Expand Up @@ -99,9 +97,7 @@
},
"hyperv": {
"image_format": "vhdx",
"image_suffix": "vhdx.zip",
"platform": "hyperv",
"compression": "zip"
"platform": "hyperv"
},
"kubevirt": {
"image_format": "qcow2",
Expand Down
16 changes: 8 additions & 8 deletions src/osbuild-manifests/platform.applehv.ipp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ pipelines:
build:
mpp-format-string: '{buildroot}'
stages:
- type: org.osbuild.gzip
- type: org.osbuild.copy
inputs:
file:
type: org.osbuild.files
tree:
type: org.osbuild.tree
origin: org.osbuild.pipeline
references:
name:raw-applehv-image:
file: disk.img
- name:raw-applehv-image
options:
level: 9
filename:
mpp-format-string: '{artifact_name_prefix}-applehv.{arch}.raw.gz'
paths:
- from: input://tree/disk.img
to:
mpp-format-string: 'tree:///{artifact_name_prefix}-applehv.{arch}.raw'
17 changes: 1 addition & 16 deletions src/osbuild-manifests/platform.hyperv.ipp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipelines:
partition:
mpp-format-int: '{image.layout[''boot''].partnum}'
target: /boot
- name: raw-hyperv-image-vhdx
- name: hyperv
build:
mpp-format-string: '{host_as_buildroot}'
stages:
Expand All @@ -68,18 +68,3 @@ pipelines:
mpp-format-string: '{artifact_name_prefix}-hyperv.{arch}.vhdx'
format:
type: vhdx
- name: hyperv
build:
mpp-format-string: '{host_as_buildroot}'
stages:
- type: org.osbuild.zip
inputs:
tree:
type: org.osbuild.tree
origin: org.osbuild.pipeline
references:
- name:raw-hyperv-image-vhdx
options:
level: 9
filename:
mpp-format-string: '{artifact_name_prefix}-hyperv.{arch}.vhdx.zip'
Loading