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 {
|
||||
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()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
|
|
|
@ -1272,6 +1272,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
|||
return "", err
|
||||
}
|
||||
|
||||
out.Write(sf.FormatProgress(utils.TruncateID(imgData.ID), "Image successfully pushed", nil))
|
||||
return imgData.Checksum, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ func (p *JSONProgress) String() string {
|
|||
}
|
||||
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))
|
||||
perEntry := fromStart / time.Duration(p.Current)
|
||||
left := time.Duration(p.Total-p.Current) * perEntry
|
||||
|
|
|
@ -7,21 +7,18 @@ import (
|
|||
|
||||
// Reader with progress bar
|
||||
type progressReader struct {
|
||||
reader io.ReadCloser // Stream to read from
|
||||
output io.Writer // Where to send progress bar to
|
||||
progress JSONProgress
|
||||
// readTotal int // Expected stream length (bytes)
|
||||
// readProgress int // How much has been read so far (bytes)
|
||||
reader io.ReadCloser // Stream to read from
|
||||
output io.Writer // Where to send progress bar to
|
||||
progress JSONProgress
|
||||
lastUpdate int // How many bytes read at least update
|
||||
ID string
|
||||
action string
|
||||
// template string // Template to print. Default "%v/%v (%v)"
|
||||
sf *StreamFormatter
|
||||
newLine bool
|
||||
sf *StreamFormatter
|
||||
newLine bool
|
||||
}
|
||||
|
||||
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
|
||||
updateEvery := 1024 * 512 //512kB
|
||||
if r.progress.Total > 0 {
|
||||
|
@ -41,7 +38,9 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
|
|||
return read, err
|
||||
}
|
||||
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 {
|
||||
return &progressReader{
|
||||
|
|
Loading…
Reference in a new issue