aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings/manifests
diff options
context:
space:
mode:
authorNaoto Kobayashi <naoto.kobayashi4c@gmail.com>2022-08-11 20:35:13 +0900
committerNaoto Kobayashi <naoto.kobayashi4c@gmail.com>2022-08-11 20:35:13 +0900
commita4efd401cd87d98dced4f4eda41a8a1b86e72379 (patch)
tree3300101275e016f34ec2bbf889041e46a8593d8f /pkg/bindings/manifests
parent59ab5cce7d20be703f5528a12a971b2ef1e2a784 (diff)
downloadpodman-a4efd401cd87d98dced4f4eda41a8a1b86e72379.tar.gz
podman-a4efd401cd87d98dced4f4eda41a8a1b86e72379.tar.bz2
podman-a4efd401cd87d98dced4f4eda41a8a1b86e72379.zip
remote manifest push: show copy progress
`podman-remote manifest push` has shown absolutely no progress at all. Fix that by doing the same as the remote-push code does. Like remote-push, `quiet` parameter is true by default for backwards compatibility. Signed-off-by: Naoto Kobayashi <naoto.kobayashi4c@gmail.com>
Diffstat (limited to 'pkg/bindings/manifests')
-rw-r--r--pkg/bindings/manifests/manifests.go43
1 files changed, 41 insertions, 2 deletions
diff --git a/pkg/bindings/manifests/manifests.go b/pkg/bindings/manifests/manifests.go
index 80153c4b4..49e4089f5 100644
--- a/pkg/bindings/manifests/manifests.go
+++ b/pkg/bindings/manifests/manifests.go
@@ -2,10 +2,13 @@ package manifests
import (
"context"
+ "encoding/json"
"errors"
"fmt"
+ "io"
"io/ioutil"
"net/http"
+ "os"
"strconv"
"strings"
@@ -142,7 +145,6 @@ func Delete(ctx context.Context, name string) (*entities.ManifestRemoveReport, e
// the name will be used instead. If the optional all boolean is specified, all images specified
// in the list will be pushed as well.
func Push(ctx context.Context, name, destination string, options *images.PushOptions) (string, error) {
- var idr entities.IDResponse
if options == nil {
options = new(images.PushOptions)
}
@@ -176,7 +178,44 @@ func Push(ctx context.Context, name, destination string, options *images.PushOpt
}
defer response.Body.Close()
- return idr.ID, response.Process(&idr)
+ if !response.IsSuccess() {
+ return "", response.Process(err)
+ }
+
+ // Historically push writes status to stderr
+ writer := io.Writer(os.Stderr)
+ if options.GetQuiet() {
+ writer = io.Discard
+ } else if progressWriter := options.GetProgressWriter(); progressWriter != nil {
+ writer = progressWriter
+ }
+
+ dec := json.NewDecoder(response.Body)
+ for {
+ var report entities.ManifestPushReport
+ if err := dec.Decode(&report); err != nil {
+ return "", err
+ }
+
+ select {
+ case <-response.Request.Context().Done():
+ break
+ default:
+ // non-blocking select
+ }
+
+ switch {
+ case report.ID != "":
+ return report.ID, nil
+ case report.Stream != "":
+ fmt.Fprint(writer, report.Stream)
+ case report.Error != "":
+ // There can only be one error.
+ return "", errors.New(report.Error)
+ default:
+ return "", fmt.Errorf("failed to parse push results stream, unexpected input: %v", report)
+ }
+ }
}
// Modify modifies the given manifest list using options and the optional list of images