Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
system: add buildcache formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: b19294ee42b9077b065bd0d16d362a7b05c724ee
Component: cli
  • Loading branch information
tonistiigi authored and Tibor Vass committed Jun 9, 2018
1 parent f1e0dd5 commit 1d7ec4c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
38 changes: 35 additions & 3 deletions components/cli/cli/command/formatter/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ const (
defaultDiskUsageContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.RunningFor}} ago\t{{.Status}}\t{{.Names}}"
defaultDiskUsageVolumeTableFormat = "table {{.Name}}\t{{.Links}}\t{{.Size}}"
defaultDiskUsageTableFormat = "table {{.Type}}\t{{.TotalCount}}\t{{.Active}}\t{{.Size}}\t{{.Reclaimable}}"
defaultBuildCacheVerboseFormat = `
ID: {{.ID}}
Description: {{.Description}}
Mutable: {{.Mutable}}
Size: {{.Size}}
CreatedAt: {{.CreatedAt}}
LastUsedAt: {{.LastUsedAt}}
UsageCount: {{.UsageCount}}
`

typeHeader = "TYPE"
totalHeader = "TOTAL"
Expand All @@ -34,6 +43,7 @@ type DiskUsageContext struct {
Images []*types.ImageSummary
Containers []*types.Container
Volumes []*types.Volume
BuildCache []*types.BuildCache
BuilderSize int64
}

Expand Down Expand Up @@ -100,6 +110,7 @@ func (ctx *DiskUsageContext) Write() (err error) {

err = ctx.contextFormat(tmpl, &diskUsageBuilderContext{
builderSize: ctx.BuilderSize,
buildCache: ctx.BuildCache,
})
if err != nil {
return err
Expand Down Expand Up @@ -184,6 +195,13 @@ func (ctx *DiskUsageContext) verboseWrite() error {

// And build cache
fmt.Fprintf(ctx.Output, "\nBuild cache usage: %s\n\n", units.HumanSize(float64(ctx.BuilderSize)))

t := template.Must(template.New("buildcache").Parse(defaultBuildCacheVerboseFormat))

for _, v := range ctx.BuildCache {
t.Execute(ctx.Output, *v)
}

return nil
}

Expand Down Expand Up @@ -366,6 +384,7 @@ func (c *diskUsageVolumesContext) Reclaimable() string {
type diskUsageBuilderContext struct {
HeaderContext
builderSize int64
buildCache []*types.BuildCache
}

func (c *diskUsageBuilderContext) MarshalJSON() ([]byte, error) {
Expand All @@ -377,17 +396,30 @@ func (c *diskUsageBuilderContext) Type() string {
}

func (c *diskUsageBuilderContext) TotalCount() string {
return ""
return fmt.Sprintf("%d", len(c.buildCache))
}

func (c *diskUsageBuilderContext) Active() string {
return ""
numActive := 0
for _, bc := range c.buildCache {
if bc.InUse {
numActive++
}
}
return fmt.Sprintf("%d", numActive)
}

func (c *diskUsageBuilderContext) Size() string {
return units.HumanSize(float64(c.builderSize))
}

func (c *diskUsageBuilderContext) Reclaimable() string {
return c.Size()
inUseBytes := int64(0)
for _, bc := range c.buildCache {
if bc.InUse {
inUseBytes += bc.Size
}
}

return units.HumanSize(float64(c.builderSize - inUseBytes))
}
1 change: 1 addition & 0 deletions components/cli/cli/command/system/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func runDiskUsage(dockerCli command.Cli, opts diskUsageOptions) error {
},
LayersSize: du.LayersSize,
BuilderSize: du.BuilderSize,
BuildCache: du.BuildCache,
Images: du.Images,
Containers: du.Containers,
Volumes: du.Volumes,
Expand Down

0 comments on commit 1d7ec4c

Please sign in to comment.