Skip to content

Commit d7e5f20

Browse files
ndeloofglours
authored andcommitted
images command should display image Created time or N/A if not available
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 2b45439 commit d7e5f20

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

cmd/compose/images.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,27 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
9595
if opts.Format == "json" {
9696

9797
type img struct {
98-
ID string `json:"ID"`
99-
ContainerName string `json:"ContainerName"`
100-
Repository string `json:"Repository"`
101-
Tag string `json:"Tag"`
102-
Platform string `json:"Platform"`
103-
Size int64 `json:"Size"`
104-
LastTagTime time.Time `json:"LastTagTime"`
98+
ID string `json:"ID"`
99+
ContainerName string `json:"ContainerName"`
100+
Repository string `json:"Repository"`
101+
Tag string `json:"Tag"`
102+
Platform string `json:"Platform"`
103+
Size int64 `json:"Size"`
104+
Created *time.Time `json:"Created,omitempty"`
105+
LastTagTime time.Time `json:"LastTagTime,omitzero"`
105106
}
106107
// Convert map to slice
107108
var imageList []img
108109
for ctr, i := range images {
109110
lastTagTime := i.LastTagTime
110-
if lastTagTime.IsZero() {
111-
lastTagTime = i.Created
112-
}
113111
imageList = append(imageList, img{
114112
ContainerName: ctr,
115113
ID: i.ID,
116114
Repository: i.Repository,
117115
Tag: i.Tag,
118116
Platform: platforms.Format(i.Platform),
119117
Size: i.Size,
118+
Created: i.Created,
120119
LastTagTime: lastTagTime,
121120
})
122121
}
@@ -142,7 +141,10 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
142141
if tag == "" {
143142
tag = "<none>"
144143
}
145-
created := units.HumanDuration(time.Now().UTC().Sub(img.LastTagTime)) + " ago"
144+
created := "N/A"
145+
if img.Created != nil {
146+
created = units.HumanDuration(time.Now().UTC().Sub(*img.Created)) + " ago"
147+
}
146148
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
147149
container, repo, tag, platforms.Format(img.Platform), id, size, created)
148150
}

pkg/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ type ImageSummary struct {
603603
Tag string
604604
Platform platforms.Platform
605605
Size int64
606-
Created time.Time
606+
Created *time.Time
607607
LastTagTime time.Time
608608
}
609609

pkg/compose/images.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
9191
}
9292
}
9393

94-
created, err := time.Parse(time.RFC3339Nano, image.Created)
95-
if err != nil {
96-
return err
94+
var created *time.Time
95+
if image.Created != "" {
96+
t, err := time.Parse(time.RFC3339Nano, image.Created)
97+
if err != nil {
98+
return err
99+
}
100+
created = &t
97101
}
98102

99103
mux.Lock()

pkg/compose/images_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ func TestImages(t *testing.T) {
6666
Repository: "foo",
6767
Tag: "1",
6868
Size: 12345,
69-
Created: created1,
69+
Created: &created1,
7070
},
7171
"456": {
7272
ID: "image2",
7373
Repository: "bar",
7474
Tag: "2",
7575
Size: 67890,
76-
Created: created2,
76+
Created: &created2,
7777
},
7878
"789": {
7979
ID: "image1",
8080
Repository: "foo",
8181
Tag: "1",
8282
Size: 12345,
83-
Created: created1,
83+
Created: &created1,
8484
},
8585
}
8686
assert.NilError(t, err)

0 commit comments

Comments
 (0)