Skip to content

WIP TarCompression #24211

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,12 @@ func AutocompleteCompressionFormat(cmd *cobra.Command, args []string, toComplete
return types, cobra.ShellCompDirectiveNoFileComp
}

// AutocompleteTarCompressionFormat - Autocomplete tar-compression-format type options.
func AutocompleteTarCompressionFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
types := []string{"gzip", "zstd"}
return types, cobra.ShellCompDirectiveNoFileComp
}

// AutocompleteClone - Autocomplete container and image names
func AutocompleteClone(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if !validCurrentCmdLine(cmd, args, toComplete) {
Expand Down
36 changes: 36 additions & 0 deletions cmd/podman/common/tarcompress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package common

import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/spf13/cobra"
)

func DefineTarCompressFlags(cmd *cobra.Command, tarCompFormat *string) {
flags := cmd.Flags()

tarCompFormatStr := "tar-compression-format"
flags.StringVar(tarCompFormat, tarCompFormatStr, tarCompressionFormat(), "compression format to use for archives")
_ = cmd.RegisterFlagCompletionFunc(tarCompFormatStr, AutocompleteTarCompressionFormat)

tarCompLevel := "tar-compression-level"
flags.Int(tarCompLevel, tarCompressionLevel(), "compression level to use for archives")
_ = cmd.RegisterFlagCompletionFunc(tarCompLevel, completion.AutocompleteNone)

}

func tarCompressionFormat() string {
if registry.IsRemote() {
return ""
}

return podmanConfig.ContainersConfDefaultsRO.Engine.TarCompressionFormat
}

func tarCompressionLevel() int {
if registry.IsRemote() || podmanConfig.ContainersConfDefaultsRO.Engine.TarCompressionLevel == nil {
return 0
}

return *podmanConfig.ContainersConfDefaultsRO.Engine.TarCompressionLevel
}
10 changes: 10 additions & 0 deletions cmd/podman/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func init() {
func pushFlags(cmd *cobra.Command) {
flags := cmd.Flags()

common.DefineTarCompressFlags(cmd, &pushOptions.TarCompressionFormat)

// For now default All flag to true, for pushing of manifest lists
pushOptions.All = true
authfileFlagName := "authfile"
Expand Down Expand Up @@ -249,6 +251,14 @@ func imagePush(cmd *cobra.Command, args []string) error {
}
}

if cmd.Flags().Changed("tar-compression-level") {
val, err := cmd.Flags().GetInt("tar-compression-level")
if err != nil {
return err
}
pushOptions.TarCompressionLevel = &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)
Expand Down
9 changes: 9 additions & 0 deletions cmd/podman/images/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func init() {
func saveFlags(cmd *cobra.Command) {
flags := cmd.Flags()

common.DefineTarCompressFlags(cmd, &saveOpts.TarCompressionFormat)

flags.BoolVar(&saveOpts.Compress, "compress", false, "Compress tarball image layers when saving to a directory using the 'dir' transport. (default is same compression type as source)")

flags.BoolVar(&saveOpts.OciAcceptUncompressedLayers, "uncompressed", false, "Accept uncompressed layers when copying OCI images")
Expand Down Expand Up @@ -111,6 +113,13 @@ func save(cmd *cobra.Command, args []string) (finalErr error) {
if cmd.Flag("compress").Changed && saveOpts.Format != define.V2s2ManifestDir {
return errors.New("--compress can only be set when --format is 'docker-dir'")
}
if cmd.Flags().Changed("tar-compression-level") {
val, err := cmd.Flags().GetInt("tar-compression-level")
if err != nil {
return err
}
saveOpts.TarCompressionLevel = &val
}
if len(saveOpts.Output) == 0 {
saveOpts.Quiet = true
fi := os.Stdout
Expand Down
10 changes: 9 additions & 1 deletion cmd/podman/images/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/containers/common/pkg/ssh"
"github.com/containers/podman/v5/cmd/podman/common"
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -73,7 +74,14 @@ func scp(cmd *cobra.Command, args []string) (finalErr error) {
}

sshEngine := ssh.DefineMode(sshType)
err = registry.ImageEngine().Scp(registry.Context(), src, dst, parentFlags, quiet, sshEngine)
err = registry.ImageEngine().Scp(registry.Context(), src, dst, entities.ImageScpBaseOptions{
ImageExecuteTransferOptions: entities.ImageExecuteTransferOptions{
ParentFlags: parentFlags,
Quiet: quiet,
SshMode: sshEngine,
TarCompressionFormat: "gzip",
},
})
if err != nil {
return err
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/bindings/images/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type ExportOptions struct {
Format *string
// Accept uncompressed layers when copying OCI images.
OciAcceptUncompressedLayers *bool
TarCompressionFormat *string
TarCompressionLevel *int
}

// PruneOptions are optional options for pruning images
Expand Down Expand Up @@ -151,7 +153,9 @@ type PushOptions struct {
// algorithms are not reused.
ForceCompressionFormat *bool
// Add existing instances with requested compression algorithms to manifest list
AddCompression []string
AddCompression []string
TarCompressionFormat *string
TarCompressionLevel *int
// Manifest type of the pushed image
Format *string
// Password for authenticating against the registry.
Expand Down Expand Up @@ -245,6 +249,8 @@ type ExistsOptions struct {
}

type ScpOptions struct {
Quiet *bool
Destination *string
TarCompressionFormat *string
TarCompressionLevel *int
Quiet *bool
Destination *string
}
30 changes: 30 additions & 0 deletions pkg/bindings/images/types_export_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/bindings/images/types_push_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/domain/entities/engine_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/containers/common/libimage/define"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/ssh"
"github.com/containers/podman/v5/pkg/domain/entities/reports"
)

Expand All @@ -24,7 +23,7 @@ type ImageEngine interface { //nolint:interfacebloat
Push(ctx context.Context, source string, destination string, opts ImagePushOptions) (*ImagePushReport, error)
Remove(ctx context.Context, images []string, opts ImageRemoveOptions) (*ImageRemoveReport, []error)
Save(ctx context.Context, nameOrID string, tags []string, options ImageSaveOptions) error
Scp(ctx context.Context, src, dst string, parentFlags []string, quiet bool, sshMode ssh.EngineMode) error
Scp(ctx context.Context, src, dst string, opts ImageScpBaseOptions) error
Search(ctx context.Context, term string, opts ImageSearchOptions) ([]ImageSearchReport, error)
SetTrust(ctx context.Context, args []string, options SetTrustOptions) error
ShowTrust(ctx context.Context, args []string, options ShowTrustOptions) (*ShowTrustReport, error)
Expand Down
28 changes: 26 additions & 2 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"

"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/ssh"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/signature/signer"
"github.com/containers/image/v5/types"
Expand Down Expand Up @@ -199,6 +200,8 @@ type ImagePushOptions struct {
// CompressionFormat is used exclusively, and blobs of other compression
// algorithms are not reused.
ForceCompressionFormat bool
TarCompressionFormat string
TarCompressionLevel *int
}

// ImagePushReport is the response from pushing an image.
Expand Down Expand Up @@ -301,8 +304,10 @@ type ImageSaveOptions struct {
// Output - write image to the specified path.
Output string
// Quiet - suppress output when copying images
Quiet bool
SignaturePolicy string
Quiet bool
SignaturePolicy string
TarCompressionFormat string
TarCompressionLevel *int
}

// ImageScpOptions provide options for securely copying images to and from a remote host
Expand Down Expand Up @@ -331,6 +336,25 @@ type ImageScpConnections struct {
Identities []string
}

type ImageScpBaseOptions struct {
ImageExecuteTransferOptions
}

type ImageExecuteTransferOptions struct {
ParentFlags []string
Quiet bool
SshMode ssh.EngineMode
TarCompressionFormat string
TarCompressionLevel *int
}

type ImageExecuteTransferReport struct {
LoadReport *ImageLoadReport
Source *ImageScpOptions
Dest *ImageScpOptions
ParentFlags []string
}

// ImageTreeOptions provides options for ImageEngine.Tree()
type ImageTreeOptions struct {
WhatRequires bool // Show all child images and layers of the specified image
Expand Down
Loading