@@ -27,6 +27,7 @@ import (
27
27
"strings"
28
28
"time"
29
29
30
+ "github.com/cheggaaa/pb/v3"
30
31
"github.com/docker/docker/client"
31
32
"github.com/google/go-containerregistry/pkg/authn"
32
33
"github.com/google/go-containerregistry/pkg/name"
@@ -137,6 +138,9 @@ func Tag(img string) string {
137
138
138
139
// WriteImageToDaemon write img to the local docker daemon
139
140
func WriteImageToDaemon (img string ) error {
141
+ // buffered channel
142
+ c := make (chan v1.Update , 200 )
143
+
140
144
klog .Infof ("Writing %s to local daemon" , img )
141
145
ref , err := name .ParseReference (img )
142
146
if err != nil {
@@ -156,12 +160,38 @@ func WriteImageToDaemon(img string) error {
156
160
return errors .Wrap (err , "getting remote image" )
157
161
}
158
162
klog .V (3 ).Infof ("Writing image %v" , ref )
159
- _ , err = daemon .Write (ref , i )
160
- if err != nil {
161
- return errors .Wrap (err , "writing daemon image" )
163
+ errchan := make (chan error )
164
+ p := pb .Full .Start64 (0 )
165
+ fn := strings .Split (ref .Name (), "@" )[0 ]
166
+ // abbreviate filename for progress
167
+ maxwidth := 30 - len ("..." )
168
+ if len (fn ) > maxwidth {
169
+ fn = fn [0 :maxwidth ] + "..."
162
170
}
171
+ p .Set ("prefix" , " > " + fn + ": " )
172
+ p .Set (pb .Bytes , true )
163
173
164
- return nil
174
+ // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
175
+ p .SetWidth (79 )
176
+
177
+ go func () {
178
+ _ , err = daemon .Write (ref , i , tarball .WithProgress (c ))
179
+ errchan <- err
180
+ }()
181
+ var update v1.Update
182
+ for {
183
+ select {
184
+ case update = <- c :
185
+ p .SetCurrent (update .Complete )
186
+ p .SetTotal (update .Total )
187
+ case err = <- errchan :
188
+ p .Finish ()
189
+ if err != nil {
190
+ return errors .Wrap (err , "writing daemon image" )
191
+ }
192
+ return nil
193
+ }
194
+ }
165
195
}
166
196
167
197
func retrieveImage (ref name.Reference ) (v1.Image , error ) {
0 commit comments