Skip to content
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

podman save: add --uncompressed #11678

Merged
merged 1 commit into from
Sep 22, 2021
Merged
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
2 changes: 2 additions & 0 deletions cmd/podman/images/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func saveFlags(cmd *cobra.Command) {

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")

formatFlagName := "format"
flags.StringVar(&saveOpts.Format, formatFlagName, define.V2s2Archive, "Save image to oci-archive, oci-dir (directory with oci manifest type), docker-archive, docker-dir (directory with v2s2 manifest type)")
_ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteImageSaveFormat)
Expand Down
4 changes: 4 additions & 0 deletions docs/source/markdown/podman-save.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Note: `:` is a restricted character and cannot be part of the file name.
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 i.e --format=oci-dir or --format=docker-dir

#### **--uncompressed**

Accept uncompressed layers when copying OCI images.

#### **--output**, **-o**=*file*

Write to a file, default is STDOUT
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/containers/buildah v1.23.0
github.com/containers/common v0.44.1-0.20210920093543-bf187ada7d0e
github.com/containers/common v0.44.1-0.20210921143342-f2f10e650c73
github.com/containers/conmon v2.0.20+incompatible
github.com/containers/image/v5 v5.16.0
github.com/containers/ocicrypt v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRD
github.com/containers/buildah v1.23.0 h1:qGIeSNOczUHzvnaaOS29HSMiYAjw6JgIXYksAyvqnLs=
github.com/containers/buildah v1.23.0/go.mod h1:K0iMKgy/MffkkgELBXhSXwTy2HTT6hM0X8qruDR1FwU=
github.com/containers/common v0.44.0/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo=
github.com/containers/common v0.44.1-0.20210920093543-bf187ada7d0e h1:p21+CJSeryr0Vb3dottjXRNYTaRND1QSPm36NogQ7cQ=
github.com/containers/common v0.44.1-0.20210920093543-bf187ada7d0e/go.mod h1:zxv7KjdYddSGoWuLUVp6eSb++Ow1zmSMB2jwxuNB4cU=
github.com/containers/common v0.44.1-0.20210921143342-f2f10e650c73 h1:+qKOyTHbuFo3GPsrUksphfHxYMIJQmPgwpDdQnARGAI=
github.com/containers/common v0.44.1-0.20210921143342-f2f10e650c73/go.mod h1:zxv7KjdYddSGoWuLUVp6eSb++Ow1zmSMB2jwxuNB4cU=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/image/v5 v5.16.0 h1:WQcNSzb7+ngS2cfynx0vUwhk+scpgiKlldVcsF8GPbI=
Expand Down
18 changes: 10 additions & 8 deletions pkg/api/handlers/libpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Compress bool `schema:"compress"`
Format string `schema:"format"`
References []string `schema:"references"`
Compress bool `schema:"compress"`
Format string `schema:"format"`
OciAcceptUncompressedLayers bool `schema:"ociAcceptUncompressedLayers"`
References []string `schema:"references"`
}{
Format: define.OCIArchive,
}
Expand Down Expand Up @@ -353,11 +354,12 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {

// Use the ABI image engine to share as much code as possible.
opts := entities.ImageSaveOptions{
Compress: query.Compress,
Format: query.Format,
MultiImageArchive: len(query.References) > 1,
Output: output,
RemoveSignatures: true,
Compress: query.Compress,
Format: query.Format,
MultiImageArchive: len(query.References) > 1,
OciAcceptUncompressedLayers: query.OciAcceptUncompressedLayers,
Output: output,
RemoveSignatures: true,
}

imageEngine := abi.ImageEngine{Libpod: runtime}
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,10 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// name: compress
// type: boolean
// description: use compression on image
// - in: query
// name: ociAcceptUncompressedLayers
// type: boolean
// description: accept uncompressed layers when copying OCI images
// produces:
// - application/json
// responses:
Expand Down
2 changes: 2 additions & 0 deletions pkg/bindings/images/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type ExportOptions struct {
Compress *bool
// Format of the output
Format *string
// Accept uncompressed layers when copying OCI images.
OciAcceptUncompressedLayers *bool
}

//go:generate go run ../generator/generator.go PruneOptions
Expand Down
15 changes: 15 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.

2 changes: 2 additions & 0 deletions pkg/domain/entities/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ type ImageSaveOptions struct {
// than one image. Additional tags will be interpreted as references
// to images which are added to the archive.
MultiImageArchive bool
// Accept uncompressed layers when copying OCI images.
OciAcceptUncompressedLayers bool
// Output - write image to the specified path.
Output string
// Do not save the signature from the source image
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (ir *ImageEngine) Load(ctx context.Context, options entities.ImageLoadOptio
func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string, options entities.ImageSaveOptions) error {
saveOptions := &libimage.SaveOptions{}
saveOptions.DirForceCompress = options.Compress
saveOptions.OciAcceptUncompressedLayers = options.OciAcceptUncompressedLayers
saveOptions.RemoveSignatures = options.RemoveSignatures

if !options.Quiet {
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/infra/tunnel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string,
err error
)
options := new(images.ExportOptions).WithFormat(opts.Format).WithCompress(opts.Compress)
options = options.WithOciAcceptUncompressedLayers(opts.OciAcceptUncompressedLayers)

switch opts.Format {
case "oci-dir", "docker-dir":
Expand Down
12 changes: 12 additions & 0 deletions test/system/120-load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,16 @@ verify_iid_and_name() {
run_podman rmi -f $img1 $img2
}

@test "podman save --oci-accept-uncompressed-layers" {
archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar
untar=$PODMAN_TMPDIR/myuntar-$(random_string 8)
mkdir -p $untar

# Create a tarball, unpack it and make sure the layers are uncompressed.
run_podman save -o $archive --format oci-archive --uncompressed $IMAGE
run tar -C $untar -xvf $archive
run file $untar/blobs/sha256/*
is "$output" ".*POSIX tar archive" "layers are uncompressed"
}

# vim: filetype=sh
18 changes: 18 additions & 0 deletions vendor/github.com/containers/common/libimage/copier.go

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

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

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

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ github.com/containers/buildah/pkg/rusage
github.com/containers/buildah/pkg/sshagent
github.com/containers/buildah/pkg/util
github.com/containers/buildah/util
# github.com/containers/common v0.44.1-0.20210920093543-bf187ada7d0e
# github.com/containers/common v0.44.1-0.20210921143342-f2f10e650c73
github.com/containers/common/libimage
github.com/containers/common/libimage/manifests
github.com/containers/common/pkg/apparmor
Expand Down