mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix progressbar in docker push
This commit is contained in:
parent
f21bd80e90
commit
85f9b778f5
4 changed files with 16 additions and 11 deletions
|
@ -448,6 +448,11 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to upload layer: %s", err)
|
return "", fmt.Errorf("Failed to upload layer: %s", err)
|
||||||
}
|
}
|
||||||
|
if rc, ok := layer.(io.Closer); ok {
|
||||||
|
if err := rc.Close(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
|
|
|
@ -1272,6 +1272,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out.Write(sf.FormatProgress(utils.TruncateID(imgData.ID), "Image successfully pushed", nil))
|
||||||
return imgData.Checksum, nil
|
return imgData.Checksum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (p *JSONProgress) String() string {
|
||||||
}
|
}
|
||||||
numbersBox = fmt.Sprintf("%8v/%v", current, total)
|
numbersBox = fmt.Sprintf("%8v/%v", current, total)
|
||||||
|
|
||||||
if p.Start > 0 {
|
if p.Start > 0 && percentage < 50 {
|
||||||
fromStart := time.Now().UTC().Sub(time.Unix(int64(p.Start), 0))
|
fromStart := time.Now().UTC().Sub(time.Unix(int64(p.Start), 0))
|
||||||
perEntry := fromStart / time.Duration(p.Current)
|
perEntry := fromStart / time.Duration(p.Current)
|
||||||
left := time.Duration(p.Total-p.Current) * perEntry
|
left := time.Duration(p.Total-p.Current) * perEntry
|
||||||
|
|
|
@ -10,18 +10,15 @@ type progressReader struct {
|
||||||
reader io.ReadCloser // Stream to read from
|
reader io.ReadCloser // Stream to read from
|
||||||
output io.Writer // Where to send progress bar to
|
output io.Writer // Where to send progress bar to
|
||||||
progress JSONProgress
|
progress JSONProgress
|
||||||
// readTotal int // Expected stream length (bytes)
|
|
||||||
// readProgress int // How much has been read so far (bytes)
|
|
||||||
lastUpdate int // How many bytes read at least update
|
lastUpdate int // How many bytes read at least update
|
||||||
ID string
|
ID string
|
||||||
action string
|
action string
|
||||||
// template string // Template to print. Default "%v/%v (%v)"
|
|
||||||
sf *StreamFormatter
|
sf *StreamFormatter
|
||||||
newLine bool
|
newLine bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *progressReader) Read(p []byte) (n int, err error) {
|
func (r *progressReader) Read(p []byte) (n int, err error) {
|
||||||
read, err := io.ReadCloser(r.reader).Read(p)
|
read, err := r.reader.Read(p)
|
||||||
r.progress.Current += read
|
r.progress.Current += read
|
||||||
updateEvery := 1024 * 512 //512kB
|
updateEvery := 1024 * 512 //512kB
|
||||||
if r.progress.Total > 0 {
|
if r.progress.Total > 0 {
|
||||||
|
@ -41,7 +38,9 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
|
||||||
return read, err
|
return read, err
|
||||||
}
|
}
|
||||||
func (r *progressReader) Close() error {
|
func (r *progressReader) Close() error {
|
||||||
return io.ReadCloser(r.reader).Close()
|
r.progress.Current = r.progress.Total
|
||||||
|
r.output.Write(r.sf.FormatProgress(r.ID, r.action, &r.progress))
|
||||||
|
return r.reader.Close()
|
||||||
}
|
}
|
||||||
func ProgressReader(r io.ReadCloser, size int, output io.Writer, sf *StreamFormatter, newline bool, ID, action string) *progressReader {
|
func ProgressReader(r io.ReadCloser, size int, output io.Writer, sf *StreamFormatter, newline bool, ID, action string) *progressReader {
|
||||||
return &progressReader{
|
return &progressReader{
|
||||||
|
|
Loading…
Add table
Reference in a new issue