diff --git a/cmd/podman/images/push.go b/cmd/podman/images/push.go index 490fb6b406e3..f0858aee4243 100644 --- a/cmd/podman/images/push.go +++ b/cmd/podman/images/push.go @@ -130,6 +130,10 @@ func pushFlags(cmd *cobra.Command) { flags.StringVar(&pushOptions.CompressionFormat, compressionFormat, "", "compression format to use") _ = cmd.RegisterFlagCompletionFunc(compressionFormat, common.AutocompleteCompressionFormat) + compressionLevel := "compression-level" + flags.Int(compressionLevel, 0, "compression level to use") + _ = cmd.RegisterFlagCompletionFunc(compressionLevel, completion.AutocompleteNone) + encryptionKeysFlagName := "encryption-key" flags.StringSliceVar(&pushOptions.EncryptionKeys, encryptionKeysFlagName, nil, "Key with the encryption protocol to use to encrypt the image (e.g. jwe:/path/to/key.pem)") _ = cmd.RegisterFlagCompletionFunc(encryptionKeysFlagName, completion.AutocompleteDefault) @@ -201,6 +205,14 @@ func imagePush(cmd *cobra.Command, args []string) error { pushOptions.OciEncryptConfig = encConfig pushOptions.OciEncryptLayers = encLayers + if cmd.Flags().Changed("compression-level") { + val, err := cmd.Flags().GetInt("compression-level") + if err != nil { + return err + } + pushOptions.CompressionLevel = &val + } + // Let's do all the remaining Yoga in the API to prevent us from scattering // logic across (too) many parts of the code. report, err := registry.ImageEngine().Push(registry.GetContext(), source, destination, pushOptions.ImagePushOptions) diff --git a/cmd/podman/manifest/push.go b/cmd/podman/manifest/push.go index e61170333f63..24d0a7eebde9 100644 --- a/cmd/podman/manifest/push.go +++ b/cmd/podman/manifest/push.go @@ -100,6 +100,10 @@ func init() { flags.StringVar(&manifestPushOpts.CompressionFormat, compressionFormat, "", "compression format to use") _ = pushCmd.RegisterFlagCompletionFunc(compressionFormat, common.AutocompleteCompressionFormat) + compressionLevel := "compression-level" + flags.Int(compressionLevel, 0, "compression level to use") + _ = pushCmd.RegisterFlagCompletionFunc(compressionLevel, completion.AutocompleteNone) + if registry.IsRemote() { _ = flags.MarkHidden("cert-dir") _ = flags.MarkHidden(signByFlagName) @@ -155,6 +159,15 @@ func push(cmd *cobra.Command, args []string) error { } manifestPushOpts.SkipTLSVerify = types.NewOptionalBool(manifestPushOpts.Insecure) } + + if cmd.Flags().Changed("compression-level") { + val, err := cmd.Flags().GetInt("compression-level") + if err != nil { + return err + } + manifestPushOpts.CompressionLevel = &val + } + digest, err := registry.ImageEngine().ManifestPush(registry.Context(), listImageSpec, destSpec, manifestPushOpts.ImagePushOptions) if err != nil { return err diff --git a/docs/source/markdown/options/compression-level.md b/docs/source/markdown/options/compression-level.md new file mode 100644 index 000000000000..08d2c2723c3f --- /dev/null +++ b/docs/source/markdown/options/compression-level.md @@ -0,0 +1,7 @@ +####> This option file is used in: +####> podman manifest push, push +####> If file is edited, make sure the changes +####> are applicable to all of those. +#### **--compression-level**=*level* + +Specifies the compression level to use. The value is specific to the compression algorithm used, e.g. for zstd the accepted values are in the range 1-20 (inclusive), while for gzip it is 1-9 (inclusive). diff --git a/docs/source/markdown/podman-manifest-push.1.md.in b/docs/source/markdown/podman-manifest-push.1.md.in index 3064dd1558b9..97f899b8a816 100644 --- a/docs/source/markdown/podman-manifest-push.1.md.in +++ b/docs/source/markdown/podman-manifest-push.1.md.in @@ -25,6 +25,8 @@ the list or index itself. (Default true) @@option compression-format +@@option compression-level + @@option creds @@option digestfile diff --git a/docs/source/markdown/podman-push.1.md.in b/docs/source/markdown/podman-push.1.md.in index 3a5401282a82..58bf1afe8cad 100644 --- a/docs/source/markdown/podman-push.1.md.in +++ b/docs/source/markdown/podman-push.1.md.in @@ -54,6 +54,8 @@ Note: This flag can only be set when using the **dir** transport @@option compression-format +@@option compression-level + @@option creds @@option digestfile diff --git a/pkg/api/handlers/libpod/images_push.go b/pkg/api/handlers/libpod/images_push.go index 1241a07759f3..4bd8393d5dc8 100644 --- a/pkg/api/handlers/libpod/images_push.go +++ b/pkg/api/handlers/libpod/images_push.go @@ -27,6 +27,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) { query := struct { All bool `schema:"all"` CompressionFormat string `schema:"compressionFormat"` + CompressionLevel *int `schema:"compressionLevel"` Destination string `schema:"destination"` Format string `schema:"format"` RemoveSignatures bool `schema:"removeSignatures"` @@ -75,6 +76,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) { All: query.All, Authfile: authfile, CompressionFormat: query.CompressionFormat, + CompressionLevel: query.CompressionLevel, Format: query.Format, Password: password, Quiet: true, diff --git a/pkg/api/handlers/libpod/manifests.go b/pkg/api/handlers/libpod/manifests.go index 0702facb3a02..bc0f1c628c68 100644 --- a/pkg/api/handlers/libpod/manifests.go +++ b/pkg/api/handlers/libpod/manifests.go @@ -328,6 +328,7 @@ func ManifestPush(w http.ResponseWriter, r *http.Request) { query := struct { All bool `schema:"all"` CompressionFormat string `schema:"compressionFormat"` + CompressionLevel *int `schema:"compressionLevel"` Format string `schema:"format"` RemoveSignatures bool `schema:"removeSignatures"` TLSVerify bool `schema:"tlsVerify"` @@ -366,6 +367,7 @@ func ManifestPush(w http.ResponseWriter, r *http.Request) { All: query.All, Authfile: authfile, CompressionFormat: query.CompressionFormat, + CompressionLevel: query.CompressionLevel, Format: query.Format, Password: password, Quiet: true, diff --git a/pkg/bindings/images/types.go b/pkg/bindings/images/types.go index 36fc06ffcff6..9c3ed2b108a5 100644 --- a/pkg/bindings/images/types.go +++ b/pkg/bindings/images/types.go @@ -142,6 +142,8 @@ type PushOptions struct { Compress *bool // CompressionFormat is the format to use for the compression of the blobs CompressionFormat *string + // CompressionLevel is the level to use for the compression of the blobs + CompressionLevel *int // Manifest type of the pushed image Format *string // Password for authenticating against the registry. diff --git a/pkg/bindings/images/types_push_options.go b/pkg/bindings/images/types_push_options.go index 71f3d9e3eb78..550b1f407088 100644 --- a/pkg/bindings/images/types_push_options.go +++ b/pkg/bindings/images/types_push_options.go @@ -78,6 +78,21 @@ func (o *PushOptions) GetCompressionFormat() string { return *o.CompressionFormat } +// WithCompressionLevel set field CompressionLevel to given value +func (o *PushOptions) WithCompressionLevel(value int) *PushOptions { + o.CompressionLevel = &value + return o +} + +// GetCompressionLevel returns value of field CompressionLevel +func (o *PushOptions) GetCompressionLevel() int { + if o.CompressionLevel == nil { + var z int + return z + } + return *o.CompressionLevel +} + // WithFormat set field Format to given value func (o *PushOptions) WithFormat(value string) *PushOptions { o.Format = &value diff --git a/pkg/domain/entities/images.go b/pkg/domain/entities/images.go index 69bf748d83b1..c58594d98387 100644 --- a/pkg/domain/entities/images.go +++ b/pkg/domain/entities/images.go @@ -231,6 +231,8 @@ type ImagePushOptions struct { Progress chan types.ProgressProperties // CompressionFormat is the format to use for the compression of the blobs CompressionFormat string + // CompressionLevel is the level to use for the compression of the blobs + CompressionLevel *int // Writer is used to display copy information including progress bars. Writer io.Writer // OciEncryptConfig when non-nil indicates that an image should be encrypted. diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 0ba9471c2e24..1f6c414d55fb 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -316,6 +316,7 @@ func (ir *ImageEngine) Push(ctx context.Context, source string, destination stri pushOptions.Writer = options.Writer pushOptions.OciEncryptConfig = options.OciEncryptConfig pushOptions.OciEncryptLayers = options.OciEncryptLayers + pushOptions.CompressionLevel = options.CompressionLevel compressionFormat := options.CompressionFormat if compressionFormat == "" { diff --git a/pkg/domain/infra/abi/manifest.go b/pkg/domain/infra/abi/manifest.go index 1c894891beab..187fc7d63eea 100644 --- a/pkg/domain/infra/abi/manifest.go +++ b/pkg/domain/infra/abi/manifest.go @@ -340,6 +340,7 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination strin pushOptions.SignSigstorePrivateKeyPassphrase = opts.SignSigstorePrivateKeyPassphrase pushOptions.InsecureSkipTLSVerify = opts.SkipTLSVerify pushOptions.Writer = opts.Writer + pushOptions.CompressionLevel = opts.CompressionLevel compressionFormat := opts.CompressionFormat if compressionFormat == "" { diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index e2e6a24511f2..6ed8d18b2074 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -254,6 +254,10 @@ func (ir *ImageEngine) Push(ctx context.Context, source string, destination stri options := new(images.PushOptions) options.WithAll(opts.All).WithCompress(opts.Compress).WithUsername(opts.Username).WithPassword(opts.Password).WithAuthfile(opts.Authfile).WithFormat(opts.Format).WithRemoveSignatures(opts.RemoveSignatures).WithQuiet(opts.Quiet).WithCompressionFormat(opts.CompressionFormat).WithProgressWriter(opts.Writer) + if opts.CompressionLevel != nil { + options.WithCompressionLevel(*opts.CompressionLevel) + } + if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined { if s == types.OptionalBoolTrue { options.WithSkipTLSVerify(true) diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index 9219b8125777..17d60a538e6e 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -319,7 +319,7 @@ var _ = Describe("Podman manifest", func() { )) }) - It("push with compression-format", func() { + It("push with compression-format and compression-level", func() { SkipIfRemote("manifest push to dir not supported in remote mode") session := podmanTest.Podman([]string{"manifest", "create", "foo"}) session.WaitWithDefaultTimeout() @@ -373,6 +373,13 @@ var _ = Describe("Podman manifest", func() { os.RemoveAll(dest) }() + // Invalid compression format specified, it must fail + session = podmanTest.Podman([]string{"manifest", "push", "--compression-format=zstd", "--compression-level=50", "foo", "dir:" + dest}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(125)) + output := session.ErrorToString() + Expect(output).To(ContainSubstring("invalid compression level")) + session = podmanTest.Podman([]string{"push", "foo", "-q", "dir:" + dest}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -381,7 +388,7 @@ var _ = Describe("Podman manifest", func() { session = podmanTest.Podman([]string{"push", "foo", "dir:" + dest}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - output := session.ErrorToString() + output = session.ErrorToString() Expect(output).To(ContainSubstring("Writing manifest list to image destination")) Expect(output).To(ContainSubstring("Storing list signatures")) }) @@ -434,7 +441,7 @@ var _ = Describe("Podman manifest", func() { Expect(output).To(ContainSubstring("Writing manifest to image destination")) Expect(output).To(ContainSubstring("Storing signatures")) - push = podmanTest.Podman([]string{"manifest", "push", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"}) + push = podmanTest.Podman([]string{"manifest", "push", "--compress", "--compression-format=gzip", "--compression-level=2", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"}) push.WaitWithDefaultTimeout() Expect(push).To(ExitWithError()) Expect(push.ErrorToString()).To(ContainSubstring(": authentication required")) diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index 72ed8f1d7fdc..502781a20353 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -46,10 +46,18 @@ var _ = Describe("Podman push", func() { Expect(session).Should(Exit(0)) }) - It("podman push to oci with compression-format", func() { + It("podman push to oci with compression-format and compression-level", func() { SkipIfRemote("Remote push does not support dir transport") bbdir := filepath.Join(podmanTest.TempDir, "busybox-oci") - session := podmanTest.Podman([]string{"push", "--compression-format=zstd", "--remove-signatures", ALPINE, + + // Invalid compression format specified, it must fail + session := podmanTest.Podman([]string{"push", "--compression-format=gzip", "--compression-level=40", ALPINE, fmt.Sprintf("oci:%s", bbdir)}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(125)) + output := session.ErrorToString() + Expect(output).To(ContainSubstring("invalid compression level")) + + session = podmanTest.Podman([]string{"push", "--compression-format=zstd", "--remove-signatures", ALPINE, fmt.Sprintf("oci:%s", bbdir)}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -99,7 +107,7 @@ var _ = Describe("Podman push", func() { Expect(push).Should(Exit(0)) Expect(push.ErrorToString()).To(BeEmpty()) - push = podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) + push = podmanTest.Podman([]string{"push", "--compression-format=gzip", "--compression-level=1", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) push.WaitWithDefaultTimeout() Expect(push).Should(Exit(0)) output := push.ErrorToString()