From ff282b120c3400df8aa4727a6c79a4be6ea00c95 Mon Sep 17 00:00:00 2001 From: James Hewitt Date: Mon, 25 Nov 2024 13:52:00 +0000 Subject: [PATCH] Only reset compression if its not valid If we reset the default compression method, force compression no longer works. Signed-off-by: James Hewitt --- libimage/push.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libimage/push.go b/libimage/push.go index dc9934480..692e76bc9 100644 --- a/libimage/push.go +++ b/libimage/push.go @@ -86,8 +86,16 @@ func (r *Runtime) Push(ctx context.Context, source, destination string, options destRef = dockerRef } - // docker-archive and only DockerV2Schema2MediaType support Gzip compression - if options.CompressionFormat != nil && + // docker-archive and DockerV2Schema2MediaType support only Gzip compression + // If the CompressionFormat has come from containers.conf (set as a default), + // but isn't supported for this push, we want to ignore it. + // If the CompressionFormat has come from the CLI (ForceCompressionFormat + // requires CompressionFormat to be set), we want to strip the invalid value + // so that the push attempt fails. + // + // Ideally this should all happen at a much higher layer, where the code can differentiate + // between a value coming from containers.conf vs. the CLI. + if options.CompressionFormat != nil && options.CompressionFormat.Name() != "gzip" && (destRef.Transport().Name() == dockerArchiveTransport.Transport.Name() || destRef.Transport().Name() == dockerDaemonTransport.Transport.Name() || options.ManifestMIMEType == manifest.DockerV2Schema2MediaType) {