4
4
package image
5
5
6
6
import (
7
+ "bytes"
7
8
"context"
8
9
"encoding/json"
9
10
"fmt"
@@ -18,8 +19,10 @@ import (
18
19
"github.com/docker/cli/cli/streams"
19
20
"github.com/docker/docker/api/types/auxprogress"
20
21
"github.com/docker/docker/api/types/image"
22
+ imagetypes "github.com/docker/docker/api/types/image"
21
23
registrytypes "github.com/docker/docker/api/types/registry"
22
24
"github.com/docker/docker/pkg/jsonmessage"
25
+ "github.com/docker/docker/pkg/stringid"
23
26
"github.com/docker/docker/registry"
24
27
"github.com/morikuni/aec"
25
28
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -144,28 +147,86 @@ To push the complete multi-platform image, remove the --platform flag.
144
147
}
145
148
146
149
if opts .quiet {
147
- err = jsonmessage .DisplayJSONMessagesToStream (responseBody , streams .NewOut (io .Discard ), handleAux (dockerCli ))
150
+ err = jsonmessage .DisplayJSONMessagesToStream (responseBody , streams .NewOut (io .Discard ), handleAux (dockerCli . Out () ))
148
151
if err == nil {
149
152
fmt .Fprintln (dockerCli .Out (), ref .String ())
150
153
}
151
154
return err
152
155
}
153
- return jsonmessage .DisplayJSONMessagesToStream (responseBody , dockerCli .Out (), handleAux (dockerCli ))
156
+ return jsonmessage .DisplayJSONMessagesToStream (responseBody , dockerCli .Out (), handleAux (dockerCli . Out () ))
154
157
}
155
158
156
159
var notes []string
157
160
158
- func handleAux (dockerCli command. Cli ) func (jm jsonmessage.JSONMessage ) {
161
+ func handleAux (out * streams. Out ) func (jm jsonmessage.JSONMessage ) {
159
162
return func (jm jsonmessage.JSONMessage ) {
160
163
b := []byte (* jm .Aux )
161
164
162
165
var stripped auxprogress.ManifestPushedInsteadOfIndex
163
166
err := json .Unmarshal (b , & stripped )
164
167
if err == nil && stripped .ManifestPushedInsteadOfIndex {
165
- note := fmt .Sprintf ("Not all multiplatform-content is present and only the available single-platform image was pushed\n %s -> %s" ,
166
- aec .RedF .Apply (stripped .OriginalIndex .Digest .String ()),
167
- aec .GreenF .Apply (stripped .SelectedManifest .Digest .String ()),
168
- )
168
+ highlightColor := aec .NewBuilder (aec .GreenF , aec .Bold )
169
+
170
+ note := fmt .Sprintf ("Not all multiplatform-content is present, pushing single-platform image." )
171
+ note += "\n No platform selected, using host platform " + highlightColor .ANSI .Apply (stripped .SelectedManifest .Platform .OS + "/" + stripped .SelectedManifest .Platform .Architecture + "/" + stripped .SelectedManifest .Platform .Variant + "\n \n " )
172
+ topNameColor := aec .NewBuilder (aec .BlueF , aec .Bold ).ANSI
173
+ normalColor := aec .NewBuilder (aec .DefaultF ).ANSI
174
+ untaggedColor := aec .NewBuilder (aec .Faint ).ANSI
175
+ // Print images
176
+ columns := []imgColumn {
177
+ {
178
+ Title : "Image" ,
179
+ Align : alignLeft ,
180
+ Width : 10 ,
181
+ },
182
+ {
183
+ Title : "ID" ,
184
+ Align : alignLeft ,
185
+ Width : 12 ,
186
+ DetailsValue : func (d * rowDetails ) string {
187
+ return stringid .TruncateID (d .ID )
188
+ },
189
+ },
190
+ {
191
+ Title : "Disk usage" ,
192
+ Align : alignRight ,
193
+ Width : 10 ,
194
+ DetailsValue : func (d * rowDetails ) string {
195
+ return d .DiskUsage
196
+ },
197
+ },
198
+ {
199
+ Title : "Content size" ,
200
+ Align : alignRight ,
201
+ Width : 12 ,
202
+ DetailsValue : func (d * rowDetails ) string {
203
+ return d .ContentSize
204
+ },
205
+ },
206
+ }
207
+
208
+ imageRows , spacing := buildTableRows ([]imagetypes.Summary {* stripped .ImageSummary })
209
+ for i , child := range imageRows [0 ].Children {
210
+ if child .Platform == stripped .SelectedManifest .Platform .OS + "/" + stripped .SelectedManifest .Platform .Architecture + "/" + stripped .SelectedManifest .Platform .Variant {
211
+ imageRows [0 ].Children [i ].Highlight = true
212
+ }
213
+ }
214
+
215
+ _ , width := out .GetTtySize ()
216
+ columns = formatColumnsForOutput (int (width ), columns , imageRows )
217
+
218
+ table := imageTreeTable {
219
+ columns : columns ,
220
+ headerColor : topNameColor ,
221
+ indexNameColor : topNameColor ,
222
+ untaggedColor : untaggedColor ,
223
+ normalColor : normalColor ,
224
+ spacing : spacing ,
225
+ }
226
+
227
+ treeB := bytes.Buffer {}
228
+ table .printTable (& treeB , imageRows )
229
+ note += treeB .String ()
169
230
notes = append (notes , note )
170
231
}
171
232
0 commit comments