From 80a498ae3d563c52b71df4a99c265ac5b73ed403 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 8 Nov 2021 15:14:16 -0500 Subject: [PATCH] Don't use Docker adjective if we don't have to Start using dir instead of docker-dir for podman save. Use compat-archive rather then docker-archive. Use docker-dir and docker-archive for compatibility only. Signed-off-by: Daniel J Walsh --- libimage/save.go | 18 +++++++++--------- libimage/save_test.go | 9 +++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libimage/save.go b/libimage/save.go index e1b8c3f75..88aa2172c 100644 --- a/libimage/save.go +++ b/libimage/save.go @@ -27,9 +27,9 @@ type SaveOptions struct { } // Save saves one or more images indicated by `names` in the specified `format` -// to `path`. Supported formats are oci-archive, docker-archive, oci-dir and -// docker-dir. The latter two adhere to the dir transport in the corresponding -// oci or docker v2s2 format. Please note that only docker-archive supports +// to `path`. Supported formats are oci-archive, compat-archive, oci-dir and +// dir. The latter two adhere to the dir transport in the corresponding +// oci or docker v2s2 format. Please note that only compat-archive supports // saving more than one images. Other formats will yield an error attempting // to save more than one. func (r *Runtime) Save(ctx context.Context, names []string, format, path string, options *SaveOptions) error { @@ -46,8 +46,8 @@ func (r *Runtime) Save(ctx context.Context, names []string, format, path string, case 1: // All formats support saving 1. default: - if format != "docker-archive" { - return errors.Errorf("unsupported format %q for saving multiple images (only docker-archive)", format) + if format != "docker-archive" || format != "compat-archive" { + return errors.Errorf("unsupported format %q for saving multiple images (only compat-archive)", format) } if len(options.AdditionalTags) > 0 { return errors.Errorf("cannot save multiple images with multiple tags") @@ -56,13 +56,13 @@ func (r *Runtime) Save(ctx context.Context, names []string, format, path string, // Dispatch the save operations. switch format { - case "oci-archive", "oci-dir", "docker-dir": + case "oci-archive", "oci-dir", "docker-dir", "dir": if len(names) > 1 { return errors.Errorf("%q does not support saving multiple images (%v)", format, names) } return r.saveSingleImage(ctx, names[0], format, path, options) - case "docker-archive": + case "docker-archive", "compat-archive": options.ManifestMIMEType = manifest.DockerV2Schema2MediaType return r.saveDockerArchive(ctx, names, path, options) } @@ -72,7 +72,7 @@ func (r *Runtime) Save(ctx context.Context, names []string, format, path string, } // saveSingleImage saves the specified image name to the specified path. -// Supported formats are "oci-archive", "oci-dir" and "docker-dir". +// Supported formats are "oci-archive", "oci-dir" and "docker-dir", "dir". func (r *Runtime) saveSingleImage(ctx context.Context, name, format, path string, options *SaveOptions) error { image, imageName, err := r.LookupImage(name, nil) if err != nil { @@ -105,7 +105,7 @@ func (r *Runtime) saveSingleImage(ctx context.Context, name, format, path string destRef, err = ociTransport.NewReference(path, tag) options.ManifestMIMEType = ociv1.MediaTypeImageManifest - case "docker-dir": + case "docker-dir", "dir": destRef, err = dirTransport.NewReference(path) options.ManifestMIMEType = manifest.DockerV2Schema2MediaType diff --git a/libimage/save_test.go b/libimage/save_test.go index 8d9d76015..26d1a907d 100644 --- a/libimage/save_test.go +++ b/libimage/save_test.go @@ -32,7 +32,7 @@ func TestSave(t *testing.T) { require.NoError(t, err) imageCache.Close() defer os.Remove(imageCache.Name()) - err = runtime.Save(ctx, []string{"alpine", "busybox"}, "docker-archive", imageCache.Name(), saveOptions) + err = runtime.Save(ctx, []string{"alpine", "busybox"}, "compat-archive", imageCache.Name(), saveOptions) require.NoError(t, err) loadOptions := &LoadOptions{} @@ -58,13 +58,18 @@ func TestSave(t *testing.T) { {[]string{"busybox"}, nil, "oci-archive", false, false}, // oci-archive doesn't support multi-image archives {[]string{"busybox", "alpine"}, nil, "oci-archive", false, true}, - // docker + // compat {[]string{"busybox"}, nil, "docker-archive", false, false}, + {[]string{"busybox"}, nil, "compat-archive", false, false}, {[]string{"busybox"}, []string{"localhost/tag:1", "quay.io/repo/image:tag"}, "docker-archive", false, false}, + {[]string{"busybox"}, []string{"localhost/tag:1", "quay.io/repo/image:tag"}, "compat-archive", false, false}, {[]string{"busybox"}, nil, "docker-dir", true, false}, + {[]string{"busybox"}, nil, "dir", true, false}, {[]string{"busybox", "alpine"}, nil, "docker-archive", false, false}, + {[]string{"busybox", "alpine"}, nil, "compat-archive", false, false}, // additional tags and multi-images conflict {[]string{"busybox", "alpine"}, []string{"tag"}, "docker-archive", false, true}, + {[]string{"busybox", "alpine"}, []string{"tag"}, "compat-archive", false, true}, } { // First clean up all images and load the cache. _, rmErrors := runtime.RemoveImages(ctx, nil, nil)