Skip to content

Commit

Permalink
Don't use Docker adjective if we don't have to
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rhatdan committed Nov 9, 2021
1 parent c342e49 commit c1cc6b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 9 additions & 9 deletions libimage/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions libimage/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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)
Expand Down

0 comments on commit c1cc6b7

Please sign in to comment.