mirror of
https://github.com/docker/compose.git
synced 2025-11-15 03:09:54 +01:00
images command should display image Created time or N/A if not available
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
2b4543935c
commit
d7e5f20eb6
@ -95,21 +95,19 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
|
|||||||
if opts.Format == "json" {
|
if opts.Format == "json" {
|
||||||
|
|
||||||
type img struct {
|
type img struct {
|
||||||
ID string `json:"ID"`
|
ID string `json:"ID"`
|
||||||
ContainerName string `json:"ContainerName"`
|
ContainerName string `json:"ContainerName"`
|
||||||
Repository string `json:"Repository"`
|
Repository string `json:"Repository"`
|
||||||
Tag string `json:"Tag"`
|
Tag string `json:"Tag"`
|
||||||
Platform string `json:"Platform"`
|
Platform string `json:"Platform"`
|
||||||
Size int64 `json:"Size"`
|
Size int64 `json:"Size"`
|
||||||
LastTagTime time.Time `json:"LastTagTime"`
|
Created *time.Time `json:"Created,omitempty"`
|
||||||
|
LastTagTime time.Time `json:"LastTagTime,omitzero"`
|
||||||
}
|
}
|
||||||
// Convert map to slice
|
// Convert map to slice
|
||||||
var imageList []img
|
var imageList []img
|
||||||
for ctr, i := range images {
|
for ctr, i := range images {
|
||||||
lastTagTime := i.LastTagTime
|
lastTagTime := i.LastTagTime
|
||||||
if lastTagTime.IsZero() {
|
|
||||||
lastTagTime = i.Created
|
|
||||||
}
|
|
||||||
imageList = append(imageList, img{
|
imageList = append(imageList, img{
|
||||||
ContainerName: ctr,
|
ContainerName: ctr,
|
||||||
ID: i.ID,
|
ID: i.ID,
|
||||||
@ -117,6 +115,7 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
|
|||||||
Tag: i.Tag,
|
Tag: i.Tag,
|
||||||
Platform: platforms.Format(i.Platform),
|
Platform: platforms.Format(i.Platform),
|
||||||
Size: i.Size,
|
Size: i.Size,
|
||||||
|
Created: i.Created,
|
||||||
LastTagTime: lastTagTime,
|
LastTagTime: lastTagTime,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -142,7 +141,10 @@ func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
|
|||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = "<none>"
|
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",
|
_, _ = 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)
|
container, repo, tag, platforms.Format(img.Platform), id, size, created)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -603,7 +603,7 @@ type ImageSummary struct {
|
|||||||
Tag string
|
Tag string
|
||||||
Platform platforms.Platform
|
Platform platforms.Platform
|
||||||
Size int64
|
Size int64
|
||||||
Created time.Time
|
Created *time.Time
|
||||||
LastTagTime time.Time
|
LastTagTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,9 +91,13 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
created, err := time.Parse(time.RFC3339Nano, image.Created)
|
var created *time.Time
|
||||||
if err != nil {
|
if image.Created != "" {
|
||||||
return err
|
t, err := time.Parse(time.RFC3339Nano, image.Created)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
created = &t
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.Lock()
|
mux.Lock()
|
||||||
|
|||||||
@ -66,21 +66,21 @@ func TestImages(t *testing.T) {
|
|||||||
Repository: "foo",
|
Repository: "foo",
|
||||||
Tag: "1",
|
Tag: "1",
|
||||||
Size: 12345,
|
Size: 12345,
|
||||||
Created: created1,
|
Created: &created1,
|
||||||
},
|
},
|
||||||
"456": {
|
"456": {
|
||||||
ID: "image2",
|
ID: "image2",
|
||||||
Repository: "bar",
|
Repository: "bar",
|
||||||
Tag: "2",
|
Tag: "2",
|
||||||
Size: 67890,
|
Size: 67890,
|
||||||
Created: created2,
|
Created: &created2,
|
||||||
},
|
},
|
||||||
"789": {
|
"789": {
|
||||||
ID: "image1",
|
ID: "image1",
|
||||||
Repository: "foo",
|
Repository: "foo",
|
||||||
Tag: "1",
|
Tag: "1",
|
||||||
Size: 12345,
|
Size: 12345,
|
||||||
Created: created1,
|
Created: &created1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user