Skip to content

Commit 0133e13

Browse files
authored
Merge pull request #231 from tonistiigi/client-session-fssession
Incrementally sending build context
2 parents 2f58992 + b95638a commit 0133e13

140 files changed

Lines changed: 7943 additions & 312 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/command/cli.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
dopts "github.com/docker/cli/opts"
1616
"github.com/docker/docker/api"
1717
"github.com/docker/docker/api/types"
18-
"github.com/docker/docker/api/types/versions"
1918
"github.com/docker/docker/client"
2019
"github.com/docker/go-connections/sockets"
2120
"github.com/docker/go-connections/tlsconfig"
@@ -193,15 +192,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
193192
OSType: ping.OSType,
194193
}
195194

196-
// since the new header was added in 1.25, assume server is 1.24 if header is not present.
197-
if ping.APIVersion == "" {
198-
ping.APIVersion = "1.24"
199-
}
200-
201-
// if server version is lower than the current cli, downgrade
202-
if versions.LessThan(ping.APIVersion, cli.client.ClientVersion()) {
203-
cli.client.UpdateClientVersion(ping.APIVersion)
204-
}
195+
cli.client.NegotiateAPIVersionPing(ping)
205196
} else {
206197
// Default to true if we fail to connect to daemon
207198
cli.server = ServerInfo{HasExperimental: true}

cli/command/formatter/disk_usage.go

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ const (
2929
// DiskUsageContext contains disk usage specific information required by the formatter, encapsulate a Context struct.
3030
type 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

3940
func (ctx *DiskUsageContext) startSubsection(format string) (*template.Template, error) {
@@ -65,49 +66,59 @@ reclaimable: {{.Reclaimable}}
6566
}
6667

6768
func (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, "\nBuild 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+
}

cli/command/formatter/disk_usage_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestDiskUsageContextFormatWrite(t *testing.T) {
2323
Images 0 0 0B 0B
2424
Containers 0 0 0B 0B
2525
Local Volumes 0 0 0B 0B
26+
Build Cache 0B 0B
2627
`,
2728
},
2829
{
@@ -38,6 +39,9 @@ CONTAINER ID IMAGE COMMAND LOCAL VOLUMES
3839
Local Volumes space usage:
3940
4041
VOLUME NAME LINKS SIZE
42+
43+
Build cache usage: 0B
44+
4145
`,
4246
},
4347
// Errors
@@ -70,6 +74,7 @@ VOLUME NAME LINKS SIZE
7074
Images 0 0 0B 0B
7175
Containers 0 0 0B 0B
7276
Local Volumes 0 0 0B 0B
77+
Build Cache 0B 0B
7378
`,
7479
},
7580
{
@@ -82,6 +87,7 @@ Local Volumes 0 0 0B
8287
Images 0
8388
Containers 0
8489
Local Volumes 0
90+
Build Cache
8591
`,
8692
},
8793
// Raw Format
@@ -109,6 +115,12 @@ active: 0
109115
size: 0B
110116
reclaimable: 0B
111117
118+
type: Build Cache
119+
total:
120+
active:
121+
size: 0B
122+
reclaimable: 0B
123+
112124
`,
113125
},
114126
}

0 commit comments

Comments
 (0)