summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-01-15 03:49:42 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2021-01-15 13:24:34 -0500
commitcf51c7ed9f955390a0e417f208046e0b8fbadb26 (patch)
treee20cf39ccab111aa9a86745fc9951f0a5f45ecf8 /pkg/domain/infra/abi
parent5a166b297339d547d89fbf14248c3aff129eb960 (diff)
downloadpodman-cf51c7ed9f955390a0e417f208046e0b8fbadb26.tar.gz
podman-cf51c7ed9f955390a0e417f208046e0b8fbadb26.tar.bz2
podman-cf51c7ed9f955390a0e417f208046e0b8fbadb26.zip
Allow podman push to push manifest lists
When doing a podman images, manifests lists look just like images, so it is logical that users would assume that they can just podman push them to a registry. The problem is we throw out weird errors when this happens and users need to somehow figure out this is a manifest list rather then an image, and frankly the user will not understand the difference. This PR will make podman push just do the right thing, by failing over and attempting to push the manifest if it fails to push the image. Fix up handling of manifest push Protocol should bring back a digest string, which can either be printed or stored in a file. We should not reimplement the manifest push setup code in the tunnel code but take advantage of the api path, to make sure remote and local work the same way. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi')
-rw-r--r--pkg/domain/infra/abi/images.go40
-rw-r--r--pkg/domain/infra/abi/manifest.go27
2 files changed, 21 insertions, 46 deletions
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index 1c233d9d5..1288ab09b 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -367,7 +367,7 @@ func (ir *ImageEngine) Push(ctx context.Context, source string, destination stri
return err
}
- return newImage.PushImageToHeuristicDestination(
+ err = newImage.PushImageToHeuristicDestination(
ctx,
destination,
manifestType,
@@ -379,39 +379,15 @@ func (ir *ImageEngine) Push(ctx context.Context, source string, destination stri
signOptions,
&dockerRegistryOptions,
nil)
+ if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
+ // Image might be a manifest list so attempt a manifest push
+ if _, manifestErr := ir.ManifestPush(ctx, source, destination, options); manifestErr == nil {
+ return nil
+ }
+ }
+ return err
}
-// func (r *imageRuntime) Delete(ctx context.Context, nameOrID string, opts entities.ImageDeleteOptions) (*entities.ImageDeleteReport, error) {
-// image, err := r.libpod.ImageEngine().NewFromLocal(nameOrID)
-// if err != nil {
-// return nil, err
-// }
-//
-// results, err := r.libpod.RemoveImage(ctx, image, opts.Force)
-// if err != nil {
-// return nil, err
-// }
-//
-// report := entities.ImageDeleteReport{}
-// if err := domainUtils.DeepCopy(&report, results); err != nil {
-// return nil, err
-// }
-// return &report, nil
-// }
-//
-// func (r *imageRuntime) Prune(ctx context.Context, opts entities.ImagePruneOptions) (*entities.ImagePruneReport, error) {
-// // TODO: map FilterOptions
-// id, err := r.libpod.ImageEngine().PruneImages(ctx, opts.All, []string{})
-// if err != nil {
-// return nil, err
-// }
-//
-// // TODO: Determine Size
-// report := entities.ImagePruneReport{}
-// copy(report.Report.ID, id)
-// return &report, nil
-// }
-
func (ir *ImageEngine) Tag(ctx context.Context, nameOrID string, tags []string, options entities.ImageTagOptions) error {
newImage, err := ir.Libpod.ImageRuntime().NewFromLocal(nameOrID)
if err != nil {
diff --git a/pkg/domain/infra/abi/manifest.go b/pkg/domain/infra/abi/manifest.go
index a68ed8788..139032ad6 100644
--- a/pkg/domain/infra/abi/manifest.go
+++ b/pkg/domain/infra/abi/manifest.go
@@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"fmt"
- "io/ioutil"
"os"
"strings"
@@ -24,9 +23,8 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
- "github.com/sirupsen/logrus"
-
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
// ManifestCreate implements logic for creating manifest lists via ImageEngine
@@ -243,14 +241,20 @@ func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (stri
}
// ManifestPush pushes a manifest list or image index to the destination
-func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination string, opts entities.ManifestPushOptions) error {
+func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination string, opts entities.ImagePushOptions) (string, error) {
listImage, err := ir.Libpod.ImageRuntime().NewFromLocal(name)
if err != nil {
- return errors.Wrapf(err, "error retrieving local image from image name %s", name)
+ return "", errors.Wrapf(err, "error retrieving local image from image name %s", name)
}
dest, err := alltransports.ParseImageName(destination)
if err != nil {
- return err
+ oldErr := err
+ // Try adding the images default transport
+ destination2 := libpodImage.DefaultTransport + destination
+ dest, err = alltransports.ParseImageName(destination2)
+ if err != nil {
+ return "", oldErr
+ }
}
var manifestType string
@@ -261,7 +265,7 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination strin
case "v2s2", "docker":
manifestType = manifest.DockerV2Schema2MediaType
default:
- return errors.Errorf("unknown format %q. Choose one of the supported formats: 'oci' or 'v2s2'", opts.Format)
+ return "", errors.Errorf("unknown format %q. Choose one of the supported formats: 'oci' or 'v2s2'", opts.Format)
}
}
@@ -297,13 +301,8 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination strin
options.ReportWriter = os.Stderr
}
manDigest, err := listImage.PushManifest(dest, options)
- if err == nil && opts.Purge {
+ if err == nil && opts.Rm {
_, err = ir.Libpod.GetStore().DeleteImage(listImage.ID(), true)
}
- if opts.DigestFile != "" {
- if err = ioutil.WriteFile(opts.DigestFile, []byte(manDigest.String()), 0644); err != nil {
- return buildahUtil.GetFailureCause(err, errors.Wrapf(err, "failed to write digest to file %q", opts.DigestFile))
- }
- }
- return err
+ return manDigest.String(), err
}