Skip to content

Commit

Permalink
copy: add --dest-compress-format and --dest-compress-level
Browse files Browse the repository at this point in the history
add the possibility to specify the format and the level to use when
compressing blobs.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Aug 2, 2019
1 parent 70ed1d8 commit c744144
Show file tree
Hide file tree
Showing 351 changed files with 74,432 additions and 29,366 deletions.
30 changes: 27 additions & 3 deletions cmd/skopeo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"strings"

"github.com/containers/image/pkg/compression"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
"github.com/urfave/cli"
Expand Down Expand Up @@ -153,9 +154,11 @@ func (opts *imageOptions) newSystemContext() (*types.SystemContext, error) {
// imageDestOptions is a superset of imageOptions specialized for iamge destinations.
type imageDestOptions struct {
*imageOptions
osTreeTmpDir string // A directory to use for OSTree temporary files
dirForceCompression bool // Compress layers when saving to the dir: transport
ociAcceptUncompressedLayers bool // Whether to accept uncompressed layers in the oci: transport
osTreeTmpDir string // A directory to use for OSTree temporary files
dirForceCompression bool // Compress layers when saving to the dir: transport
ociAcceptUncompressedLayers bool // Whether to accept uncompressed layers in the oci: transport
compressionFormat string // Format to use for the compression
compressionLevel optionalInt // Level to use for the compression
}

// imageDestFlags prepares a collection of CLI flags writing into imageDestOptions, and the managed imageDestOptions structure.
Expand All @@ -179,6 +182,16 @@ func imageDestFlags(global *globalOptions, shared *sharedImageOptions, flagPrefi
Usage: "Allow uncompressed image layers when saving to an OCI image using the 'oci' transport. (default is to compress things that aren't compressed)",
Destination: &opts.ociAcceptUncompressedLayers,
},
cli.StringFlag{
Name: flagPrefix + "compress-format",
Usage: "`FORMAT` to use for the compression",
Destination: &opts.compressionFormat,
},
cli.GenericFlag{
Name: flagPrefix + "compress-level",
Usage: "`LEVEL` to use for the compression",
Value: newOptionalIntValue(&opts.compressionLevel),
},
}...), &opts
}

Expand All @@ -193,6 +206,17 @@ func (opts *imageDestOptions) newSystemContext() (*types.SystemContext, error) {
ctx.OSTreeTmpDirPath = opts.osTreeTmpDir
ctx.DirForceCompress = opts.dirForceCompression
ctx.OCIAcceptUncompressedLayers = opts.ociAcceptUncompressedLayers
if opts.compressionFormat == "" {
opts.compressionFormat = "gzip"
}
cf, err := compression.AlgorithmByName(opts.compressionFormat)
if err != nil {
return nil, err
}
ctx.CompressionFormat = cf
if opts.compressionLevel.present {
ctx.CompressionLevel = &opts.compressionLevel.value
}
return ctx, err
}

Expand Down
4 changes: 4 additions & 0 deletions docs/skopeo-copy.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ If the authorization state is not found there, $HOME/.docker/config.json is chec

Existing signatures, if any, are preserved as well.

**--dest-compress-format** _format_ Specifies the compression format to use.

**--dest-compress-level** _format_ 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). Algorithms that don't support the setting, will ignore it.

## EXAMPLES

To copy the layers of the docker.io busybox image to a local directory:
Expand Down
32 changes: 7 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ module github.com/containers/skopeo
go 1.12

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/containerd/continuity v0.0.0-20180216233310-d8fb8589b0e8 // indirect
github.com/containers/buildah v1.8.4
github.com/containers/image v1.5.2-0.20190725091050-48acc3dcbb76
github.com/containers/storage v1.12.10
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/containers/storage v1.12.14
github.com/docker/distribution v0.0.0-20170817175659-5f6282db7d65 // indirect
github.com/docker/docker v0.0.0-20180522102801-da99009bbb11
github.com/docker/docker-credential-helpers v0.6.0 // indirect
github.com/docker/go-connections v0.0.0-20180212134524-7beb39f0b969 // indirect
github.com/docker/go-units v0.0.0-20161020213227-8a7beacffa30 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/etcd-io/bbolt v1.3.2 // indirect
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 // indirect
Expand All @@ -25,42 +20,29 @@ require (
github.com/gorilla/context v0.0.0-20140604161150-14f550f51af5 // indirect
github.com/gorilla/mux v0.0.0-20140926153814-e444e69cbd2e // indirect
github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 // indirect
github.com/klauspost/compress v1.4.1 // indirect
github.com/klauspost/cpuid v1.2.0 // indirect
github.com/klauspost/pgzip v1.2.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mattn/go-shellwords v1.0.5 // indirect
github.com/mistifyio/go-zfs v0.0.0-20160425201758-22c9b32c84eb // indirect
github.com/mtrmac/gpgme v0.0.0-20170102180018-b2432428689c // indirect
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/image-spec v0.0.0-20180918080442-7b1e489870ac
github.com/opencontainers/image-tools v0.0.0-20170926011501-6d941547fa1d
github.com/opencontainers/runc v1.0.0-rc6 // indirect
github.com/opencontainers/runtime-spec v1.0.0 // indirect
github.com/opencontainers/selinux v0.0.0-20190118194635-b707dfcb00a1 // indirect
github.com/ostreedev/ostree-go v0.0.0-20181204105935-56f3a639dbc0 // indirect
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa // indirect
github.com/pkg/errors v0.8.1
github.com/pmezard/go-difflib v0.0.0-20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/ffjson v0.0.0-20171002144729-d49c2bc1aa13 // indirect
github.com/sirupsen/logrus v1.0.0
github.com/stretchr/testify v1.1.3
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.3.0
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2
github.com/tchap/go-patricia v2.2.6+incompatible // indirect
github.com/ulikunitz/xz v0.5.4 // indirect
github.com/urfave/cli v1.20.0
github.com/vbatts/tar-split v0.10.2 // indirect
github.com/vbauerster/mpb v3.4.0+incompatible // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.1.0 // indirect
go4.org v0.0.0-20190218023631-ce4c26f7be8e // indirect
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2 // indirect
golang.org/x/net v0.0.0-20190107210223-45ffb0cd1ba0 // indirect
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
golang.org/x/sys v0.0.0-20170817234608-43e60d72a8e2 // indirect
golang.org/x/text v0.0.0-20181227161524-e6919f6577db // indirect
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e // indirect
gopkg.in/yaml.v2 v2.0.0-20141029210843-d466437aa4ad // indirect
k8s.io/client-go v0.0.0-20181219152756-3dd551c0f083 // indirect
)

replace github.com/containers/image => github.com/giuseppe/image v0.0.0-20190723195852-da7a70cbb5f1
Loading

0 comments on commit c744144

Please sign in to comment.