@@ -29,11 +29,12 @@ const (
2929// DiskUsageContext contains disk usage specific information required by the formatter, encapsulate a Context struct.
3030type DiskUsageContext struct {
3131 Context
32- Verbose bool
33- LayersSize int64
34- Images []* types.ImageSummary
35- Containers []* types.Container
36- Volumes []* types.Volume
32+ Verbose bool
33+ LayersSize int64
34+ Images []* types.ImageSummary
35+ Containers []* types.Container
36+ Volumes []* types.Volume
37+ BuilderSize int64
3738}
3839
3940func (ctx * DiskUsageContext ) startSubsection (format string ) (* template.Template , error ) {
@@ -65,49 +66,59 @@ reclaimable: {{.Reclaimable}}
6566}
6667
6768func (ctx * DiskUsageContext ) Write () (err error ) {
68- if ! ctx .Verbose {
69- ctx .buffer = bytes .NewBufferString ("" )
70- ctx .preFormat ()
71-
72- tmpl , err := ctx .parseFormat ()
73- if err != nil {
74- return err
75- }
69+ if ctx .Verbose {
70+ return ctx .verboseWrite ()
71+ }
72+ ctx .buffer = bytes .NewBufferString ("" )
73+ ctx .preFormat ()
7674
77- err = ctx .contextFormat (tmpl , & diskUsageImagesContext {
78- totalSize : ctx .LayersSize ,
79- images : ctx .Images ,
80- })
81- if err != nil {
82- return err
83- }
84- err = ctx .contextFormat (tmpl , & diskUsageContainersContext {
85- containers : ctx .Containers ,
86- })
87- if err != nil {
88- return err
89- }
75+ tmpl , err := ctx .parseFormat ()
76+ if err != nil {
77+ return err
78+ }
9079
91- err = ctx .contextFormat (tmpl , & diskUsageVolumesContext {
92- volumes : ctx .Volumes ,
93- })
94- if err != nil {
95- return err
96- }
80+ err = ctx .contextFormat (tmpl , & diskUsageImagesContext {
81+ totalSize : ctx .LayersSize ,
82+ images : ctx .Images ,
83+ })
84+ if err != nil {
85+ return err
86+ }
87+ err = ctx .contextFormat (tmpl , & diskUsageContainersContext {
88+ containers : ctx .Containers ,
89+ })
90+ if err != nil {
91+ return err
92+ }
9793
98- diskUsageContainersCtx := diskUsageContainersContext {containers : []* types.Container {}}
99- diskUsageContainersCtx .header = map [string ]string {
100- "Type" : typeHeader ,
101- "TotalCount" : totalHeader ,
102- "Active" : activeHeader ,
103- "Size" : sizeHeader ,
104- "Reclaimable" : reclaimableHeader ,
105- }
106- ctx .postFormat (tmpl , & diskUsageContainersCtx )
94+ err = ctx .contextFormat (tmpl , & diskUsageVolumesContext {
95+ volumes : ctx .Volumes ,
96+ })
97+ if err != nil {
98+ return err
99+ }
107100
101+ err = ctx .contextFormat (tmpl , & diskUsageBuilderContext {
102+ builderSize : ctx .BuilderSize ,
103+ })
104+ if err != nil {
108105 return err
109106 }
110107
108+ diskUsageContainersCtx := diskUsageContainersContext {containers : []* types.Container {}}
109+ diskUsageContainersCtx .header = map [string ]string {
110+ "Type" : typeHeader ,
111+ "TotalCount" : totalHeader ,
112+ "Active" : activeHeader ,
113+ "Size" : sizeHeader ,
114+ "Reclaimable" : reclaimableHeader ,
115+ }
116+ ctx .postFormat (tmpl , & diskUsageContainersCtx )
117+
118+ return err
119+ }
120+
121+ func (ctx * DiskUsageContext ) verboseWrite () (err error ) {
111122 // First images
112123 tmpl , err := ctx .startSubsection (defaultDiskUsageImageTableFormat )
113124 if err != nil {
@@ -176,6 +187,9 @@ func (ctx *DiskUsageContext) Write() (err error) {
176187 }
177188 }
178189 ctx .postFormat (tmpl , newVolumeContext ())
190+
191+ // And build cache
192+ fmt .Fprintf (ctx .Output , "\n Build cache usage: %s\n \n " , units .HumanSize (float64 (ctx .BuilderSize )))
179193 return
180194}
181195
@@ -354,3 +368,32 @@ func (c *diskUsageVolumesContext) Reclaimable() string {
354368
355369 return fmt .Sprintf ("%s" , units .HumanSize (float64 (reclaimable )))
356370}
371+
372+ type diskUsageBuilderContext struct {
373+ HeaderContext
374+ builderSize int64
375+ }
376+
377+ func (c * diskUsageBuilderContext ) MarshalJSON () ([]byte , error ) {
378+ return marshalJSON (c )
379+ }
380+
381+ func (c * diskUsageBuilderContext ) Type () string {
382+ return "Build Cache"
383+ }
384+
385+ func (c * diskUsageBuilderContext ) TotalCount () string {
386+ return ""
387+ }
388+
389+ func (c * diskUsageBuilderContext ) Active () string {
390+ return ""
391+ }
392+
393+ func (c * diskUsageBuilderContext ) Size () string {
394+ return units .HumanSize (float64 (c .builderSize ))
395+ }
396+
397+ func (c * diskUsageBuilderContext ) Reclaimable () string {
398+ return c .Size ()
399+ }
0 commit comments