Merge pull request #26303 from yongtang/26300-docker-images-3-fractional-digits

Restrict size to 2 fractional digits for `docker images`
This commit is contained in:
Vincent Demeester 2016-09-10 11:32:45 +02:00 committed by GitHub
commit 2dc3e0341b
5 changed files with 7 additions and 7 deletions

View File

@ -194,8 +194,8 @@ func (s *containerStats) Display(w io.Writer) error {
s.CPUPercentage, s.CPUPercentage,
units.BytesSize(s.Memory), units.BytesSize(s.MemoryLimit), units.BytesSize(s.Memory), units.BytesSize(s.MemoryLimit),
s.MemoryPercentage, s.MemoryPercentage,
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx), units.HumanSizeWithPrecision(s.NetworkRx, 3), units.HumanSizeWithPrecision(s.NetworkTx, 3),
units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite), units.HumanSizeWithPrecision(s.BlockRead, 3), units.HumanSizeWithPrecision(s.BlockWrite, 3),
s.PidsCurrent) s.PidsCurrent)
return nil return nil
} }

View File

@ -25,7 +25,7 @@ func TestDisplay(t *testing.T) {
t.Fatalf("c.Display() gave error: %s", err) t.Fatalf("c.Display() gave error: %s", err)
} }
got := b.String() got := b.String()
want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\t1\n" want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t105 MB / 839 MB\t105 MB / 839 MB\t1\n"
if got != want { if got != want {
t.Fatalf("c.Display() = %q, want %q", got, want) t.Fatalf("c.Display() = %q, want %q", got, want)
} }

View File

@ -152,8 +152,8 @@ func (c *containerContext) Status() string {
func (c *containerContext) Size() string { func (c *containerContext) Size() string {
c.addHeader(sizeHeader) c.addHeader(sizeHeader)
srw := units.HumanSize(float64(c.c.SizeRw)) srw := units.HumanSizeWithPrecision(float64(c.c.SizeRw), 3)
sv := units.HumanSize(float64(c.c.SizeRootFs)) sv := units.HumanSizeWithPrecision(float64(c.c.SizeRootFs), 3)
sf := srw sf := srw
if c.c.SizeRootFs > 0 { if c.c.SizeRootFs > 0 {

View File

@ -225,5 +225,5 @@ func (c *imageContext) CreatedAt() string {
func (c *imageContext) Size() string { func (c *imageContext) Size() string {
c.addHeader(sizeHeader) c.addHeader(sizeHeader)
return units.HumanSize(float64(c.i.Size)) return units.HumanSizeWithPrecision(float64(c.i.Size), 3)
} }

View File

@ -86,7 +86,7 @@ func runHistory(dockerCli *command.DockerCli, opts historyOptions) error {
if opts.human { if opts.human {
created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago" created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago"
size = units.HumanSize(float64(entry.Size)) size = units.HumanSizeWithPrecision(float64(entry.Size), 3)
} else { } else {
created = time.Unix(entry.Created, 0).Format(time.RFC3339) created = time.Unix(entry.Created, 0).Format(time.RFC3339)
size = strconv.FormatInt(entry.Size, 10) size = strconv.FormatInt(entry.Size, 10)