Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions cmd/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,27 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
if opts.Format == "json" {

type img struct {
ID string `json:"ID"`
ContainerName string `json:"ContainerName"`
Repository string `json:"Repository"`
Tag string `json:"Tag"`
Platform string `json:"Platform"`
Size int64 `json:"Size"`
LastTagTime time.Time `json:"LastTagTime"`
ID string `json:"ID"`
ContainerName string `json:"ContainerName"`
Repository string `json:"Repository"`
Tag string `json:"Tag"`
Platform string `json:"Platform"`
Size int64 `json:"Size"`
Created *time.Time `json:"Created,omitempty"`
LastTagTime time.Time `json:"LastTagTime,omitzero"`
}
// Convert map to slice
var imageList []img
for ctr, i := range images {
lastTagTime := i.LastTagTime
if lastTagTime.IsZero() {
lastTagTime = i.Created
}
imageList = append(imageList, img{
ContainerName: ctr,
ID: i.ID,
Repository: i.Repository,
Tag: i.Tag,
Platform: platforms.Format(i.Platform),
Size: i.Size,
Created: i.Created,
LastTagTime: lastTagTime,
})
}
Expand All @@ -142,7 +141,10 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
if tag == "" {
tag = "<none>"
}
created := units.HumanDuration(time.Now().UTC().Sub(img.LastTagTime)) + " ago"
created := "N/A"
if img.Created != nil {
created = units.HumanDuration(time.Now().UTC().Sub(*img.Created)) + " ago"
}
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
container, repo, tag, platforms.Format(img.Platform), id, size, created)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ type ImageSummary struct {
Tag string
Platform platforms.Platform
Size int64
Created time.Time
Created *time.Time
LastTagTime time.Time
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
}
}

created, err := time.Parse(time.RFC3339Nano, image.Created)
if err != nil {
return err
var created *time.Time
if image.Created != "" {
t, err := time.Parse(time.RFC3339Nano, image.Created)
if err != nil {
return err
}
created = &t
}

mux.Lock()
Expand Down
6 changes: 3 additions & 3 deletions pkg/compose/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ func TestImages(t *testing.T) {
Repository: "foo",
Tag: "1",
Size: 12345,
Created: created1,
Created: &created1,
},
"456": {
ID: "image2",
Repository: "bar",
Tag: "2",
Size: 67890,
Created: created2,
Created: &created2,
},
"789": {
ID: "image1",
Repository: "foo",
Tag: "1",
Size: 12345,
Created: created1,
Created: &created1,
},
}
assert.NilError(t, err)
Expand Down