From ae37ebb286beb8c8951a3332fee0d2a9534b43b2 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Mon, 7 Nov 2022 16:35:31 +0100 Subject: [PATCH] image: support compression on all live image types Apply "xz" compression to any artifact pipeline if it's specified in the image type. The image filename should be applied to the pipeline only if it's the last one, so we need to skip this assignment if we're going to add a compression pipeline at the end. This is a bit dirty but the plan is to remove artifact compression from manifests and perform it during the export in osbuild-composer, so this should go away soon. --- internal/image/live.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/internal/image/live.go b/internal/image/live.go index 795600b97..c6f785573 100644 --- a/internal/image/live.go +++ b/internal/image/live.go @@ -46,33 +46,46 @@ func (img *LiveImage) InstantiateManifest(m *manifest.Manifest, imagePipeline := manifest.NewRawImage(m, buildPipeline, osPipeline) var artifact *artifact.Artifact + var artifactPipeline manifest.Pipeline switch img.Platform.GetImageFormat() { case platform.FORMAT_RAW: - switch img.Compression { - case "xz": - xzPipeline := manifest.NewXZ(m, buildPipeline, imagePipeline) - xzPipeline.Filename = img.Filename - artifact = xzPipeline.Export() - default: + if img.Compression == "" { imagePipeline.Filename = img.Filename - artifact = imagePipeline.Export() } + artifactPipeline = imagePipeline + artifact = imagePipeline.Export() case platform.FORMAT_QCOW2: qcow2Pipeline := manifest.NewQCOW2(m, buildPipeline, imagePipeline) - qcow2Pipeline.Filename = img.Filename + if img.Compression == "" { + qcow2Pipeline.Filename = img.Filename + } qcow2Pipeline.Compat = img.Platform.GetQCOW2Compat() + artifactPipeline = qcow2Pipeline artifact = qcow2Pipeline.Export() case platform.FORMAT_VHD: vpcPipeline := manifest.NewVPC(m, buildPipeline, imagePipeline) - vpcPipeline.Filename = img.Filename + if img.Compression == "" { + vpcPipeline.Filename = img.Filename + } + artifactPipeline = vpcPipeline artifact = vpcPipeline.Export() case platform.FORMAT_VMDK: vmdkPipeline := manifest.NewVMDK(m, buildPipeline, imagePipeline) - vmdkPipeline.Filename = img.Filename + if img.Compression == "" { + vmdkPipeline.Filename = img.Filename + } + artifactPipeline = vmdkPipeline artifact = vmdkPipeline.Export() default: panic("invalid image format for image kind") } + switch img.Compression { + case "xz": + xzPipeline := manifest.NewXZ(m, buildPipeline, artifactPipeline) + xzPipeline.Filename = img.Filename + artifact = xzPipeline.Export() + } + return artifact, nil }