From b95ae3b4a3abafaa8ca1fb8fbb4b3d74633ee9b5 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Tue, 29 Aug 2023 15:35:17 +0530 Subject: [PATCH] manifest,push: support add_compression from containers.conf Use `add_compression` field from `containers.conf` if found instead and `CLI` field `--add-compression` is not set. Signed-off-by: Aditya R --- cmd/podman/manifest/push.go | 3 ++- test/e2e/manifest_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/podman/manifest/push.go b/cmd/podman/manifest/push.go index baefb81564..726ede5564 100644 --- a/cmd/podman/manifest/push.go +++ b/cmd/podman/manifest/push.go @@ -42,6 +42,7 @@ var ( ) func init() { + podmanConfig := registry.PodmanConfig() registry.Commands = append(registry.Commands, registry.CliCommand{ Command: pushCmd, Parent: manifestCmd, @@ -57,7 +58,7 @@ func init() { _ = pushCmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault) addCompressionFlagName := "add-compression" - flags.StringSliceVar(&manifestPushOpts.AddCompression, addCompressionFlagName, nil, "add instances with selected compression while pushing") + flags.StringSliceVar(&manifestPushOpts.AddCompression, addCompressionFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.AddCompression, "add instances with selected compression while pushing") _ = pushCmd.RegisterFlagCompletionFunc(addCompressionFlagName, common.AutocompleteCompressionFormat) certDirFlagName := "cert-dir" diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index a20522aa10..351d097cf5 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -230,6 +230,32 @@ var _ = Describe("Podman manifest", func() { Expect(verifyInstanceCompression(index.Manifests, "gzip", "arm64")).Should(BeTrue()) Expect(verifyInstanceCompression(index.Manifests, "gzip", "amd64")).Should(BeTrue()) + // same thing with add_compression from config file should work and without --add-compression flag in CLI + confFile := filepath.Join(podmanTest.TempDir, "containers.conf") + err = os.WriteFile(confFile, []byte(`[engine] +add_compression = ["zstd"]`), 0o644) + Expect(err).ToNot(HaveOccurred()) + os.Setenv("CONTAINERS_CONF", confFile) + + push = podmanTest.Podman([]string{"manifest", "push", "--all", "--tls-verify=false", "--compression-format", "gzip", "--force-compression", "--remove-signatures", "foobar", "localhost:5000/list"}) + push.WaitWithDefaultTimeout() + Expect(push).Should(Exit(0)) + output = push.ErrorToString() + // 4 images must be pushed two for gzip and two for zstd + Expect(output).To(ContainSubstring("Copying 4 images generated from 2 images in list")) + + session = podmanTest.Podman([]string{"run", "--rm", "--net", "host", "quay.io/skopeo/stable", "inspect", "--tls-verify=false", "--raw", "docker://localhost:5000/list:latest"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + inspectData = []byte(session.OutputToString()) + err = json.Unmarshal(inspectData, &index) + Expect(err).ToNot(HaveOccurred()) + + Expect(verifyInstanceCompression(index.Manifests, "zstd", "amd64")).Should(BeTrue()) + Expect(verifyInstanceCompression(index.Manifests, "zstd", "arm64")).Should(BeTrue()) + Expect(verifyInstanceCompression(index.Manifests, "gzip", "arm64")).Should(BeTrue()) + Expect(verifyInstanceCompression(index.Manifests, "gzip", "amd64")).Should(BeTrue()) + // Note: Pushing again with --force-compression=false should produce in-correct/wrong result since blobs are already present in registry so they will be reused // ignoring our compression priority ( this is expected behaviour of c/image and --force-compression is introduced to mitigate this behaviour ). push = podmanTest.Podman([]string{"manifest", "push", "--all", "--add-compression", "zstd", "--force-compression=false", "--tls-verify=false", "--remove-signatures", "foobar", "localhost:5000/list"})