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
6 changes: 5 additions & 1 deletion cmd/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ func runImages(ctx context.Context, dockerCli command.Cli, backend api.Service,
// 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,
LastTagTime: i.LastTagTime,
LastTagTime: lastTagTime,
})
}
json, err := formatter.ToJSON(imageList, "", "")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ type ImageSummary struct {
Tag string
Platform platforms.Platform
Size int64
Created time.Time
LastTagTime time.Time
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"slices"
"strings"
"sync"
"time"

"github.com/containerd/errdefs"
"github.com/containerd/platforms"
Expand Down Expand Up @@ -90,6 +91,11 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
}
}

created, err := time.Parse(time.RFC3339Nano, image.Created)
if err != nil {
return err
}

mux.Lock()
defer mux.Unlock()
summary[getCanonicalContainerName(c)] = api.ImageSummary{
Expand All @@ -103,6 +109,7 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
Variant: image.Variant,
},
Size: image.Size,
Created: created,
LastTagTime: image.Metadata.LastTagTime,
}
return nil
Expand Down
17 changes: 13 additions & 4 deletions pkg/compose/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand All @@ -44,8 +45,12 @@ func TestImages(t *testing.T) {
args := filters.NewArgs(projectFilter(strings.ToLower(testProject)))
listOpts := container.ListOptions{All: true, Filters: args}
api.EXPECT().ServerVersion(gomock.Any()).Return(types.Version{APIVersion: "1.96"}, nil).AnyTimes()
image1 := imageInspect("image1", "foo:1", 12345)
image2 := imageInspect("image2", "bar:2", 67890)
timeStr1 := "2025-06-06T06:06:06.000000000Z"
created1, _ := time.Parse(time.RFC3339Nano, timeStr1)
timeStr2 := "2025-03-03T03:03:03.000000000Z"
created2, _ := time.Parse(time.RFC3339Nano, timeStr2)
image1 := imageInspect("image1", "foo:1", 12345, timeStr1)
image2 := imageInspect("image2", "bar:2", 67890, timeStr2)
api.EXPECT().ImageInspect(anyCancellableContext(), "foo:1").Return(image1, nil).MaxTimes(2)
api.EXPECT().ImageInspect(anyCancellableContext(), "bar:2").Return(image2, nil)
c1 := containerDetail("service1", "123", "running", "foo:1")
Expand All @@ -62,32 +67,36 @@ func TestImages(t *testing.T) {
Repository: "foo",
Tag: "1",
Size: 12345,
Created: created1,
},
"456": {
ID: "image2",
Repository: "bar",
Tag: "2",
Size: 67890,
Created: created2,
},
"789": {
ID: "image1",
Repository: "foo",
Tag: "1",
Size: 12345,
Created: created1,
},
}
assert.NilError(t, err)
assert.DeepEqual(t, images, expected)
}

func imageInspect(id string, imageReference string, size int64) image.InspectResponse {
func imageInspect(id string, imageReference string, size int64, created string) image.InspectResponse {
return image.InspectResponse{
ID: id,
RepoTags: []string{
"someRepo:someTag",
imageReference,
},
Size: size,
Size: size,
Created: created,
}
}

Expand Down