Skip to content

Commit

Permalink
podman, push: expose --compression-format
Browse files Browse the repository at this point in the history
support overriding the compression format at push time.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Dec 1, 2021
1 parent 8de68b1 commit 6673ff7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,9 @@ func AutocompleteCheckpointCompressType(cmd *cobra.Command, args []string, toCom
types := []string{"gzip", "none", "zstd"}
return types, cobra.ShellCompDirectiveNoFileComp
}

// AutocompleteCompressionFormat - Autocomplete compression-format type options.
func AutocompleteCompressionFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
types := []string{"gzip", "zstd", "zstd:chunked"}
return types, cobra.ShellCompDirectiveNoFileComp
}
4 changes: 4 additions & 0 deletions cmd/podman/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func pushFlags(cmd *cobra.Command) {

flags.BoolVar(&pushOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")

compressionFormat := "compression-format"
flags.StringVar(&pushOptions.CompressionFormat, compressionFormat, "", "compression format to use")
_ = cmd.RegisterFlagCompletionFunc(compressionFormat, common.AutocompleteCompressionFormat)

if registry.IsRemote() {
_ = flags.MarkHidden("cert-dir")
_ = flags.MarkHidden("compress")
Expand Down
4 changes: 4 additions & 0 deletions docs/source/markdown/podman-push.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Please refer to containers-certs.d(5) for details. (This option is not available
Compress tarball image layers when pushing to a directory using the 'dir' transport. (default is same compression type, compressed or uncompressed, as source)
Note: This flag can only be set when using the **dir** transport

#### **--compression-format** *COMPRESSION*

Specifies the compression format to use. Supported values are: `gzip`, `zstd` and `zstd:chunked`. The default is `gzip`.

#### **--digestfile** *Digestfile*

After copying the image, write the digest of the resulting image to the file. (This option is not available with the remote Podman client)
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ type ImagePushOptions struct {
SkipTLSVerify types.OptionalBool
// Progress to get progress notifications
Progress chan types.ProgressProperties
// CompressionFormat is the format to use for the compression of the blobs
CompressionFormat string
}

// ImageSearchOptions are the arguments for searching images.
Expand Down
9 changes: 9 additions & 0 deletions pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/containers/image/v5/docker"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/pkg/compression"
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/transports"
"github.com/containers/image/v5/transports/alltransports"
Expand Down Expand Up @@ -305,6 +306,14 @@ func (ir *ImageEngine) Push(ctx context.Context, source string, destination stri
pushOptions.SignBy = options.SignBy
pushOptions.InsecureSkipTLSVerify = options.SkipTLSVerify

if options.CompressionFormat != "" {
algo, err := compression.AlgorithmByName(options.CompressionFormat)
if err != nil {
return err
}
pushOptions.CompressionFormat = &algo
}

if !options.Quiet {
pushOptions.Writer = os.Stderr
}
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package integration

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/containers/podman/v3/pkg/rootless"
. "github.com/containers/podman/v3/test/utils"
"github.com/containers/storage/pkg/archive"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -63,6 +65,36 @@ var _ = Describe("Podman push", func() {
Expect(session).Should(Exit(0))
})

It("podman push to oci with compression-format", 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,
fmt.Sprintf("oci:%s", bbdir)})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

foundZstdFile := false

blobsDir := filepath.Join(bbdir, "blobs/sha256")

blobs, err := ioutil.ReadDir(blobsDir)
Expect(err).To(BeNil())

for _, f := range blobs {
blobPath := filepath.Join(blobsDir, f.Name())

sourceFile, err := ioutil.ReadFile(blobPath)
Expect(err).To(BeNil())

compressionType := archive.DetectCompression(sourceFile)
if compressionType == archive.Zstd {
foundZstdFile = true
break
}
}
Expect(foundZstdFile).To(BeTrue())
})

It("podman push to local registry", func() {
SkipIfRemote("Remote does not support --digestfile or --remove-signatures")
if podmanTest.Host.Arch == "ppc64le" {
Expand Down

0 comments on commit 6673ff7

Please sign in to comment.