Skip to content

Commit 538229d

Browse files
artifact: added CREATED column to artifact ls
Fixes: containers#27314 Signed-off-by: Volodymyr Pankin <[email protected]>
1 parent f2a559a commit 538229d

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

cmd/podman/artifact/list.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package artifact
33
import (
44
"fmt"
55
"os"
6+
"time"
67

78
"github.com/containers/podman/v5/cmd/podman/common"
89
"github.com/containers/podman/v5/cmd/podman/registry"
910
"github.com/containers/podman/v5/cmd/podman/validate"
1011
"github.com/containers/podman/v5/pkg/domain/entities"
1112
"github.com/docker/go-units"
13+
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
1214
"github.com/spf13/cobra"
1315
"go.podman.io/common/pkg/completion"
1416
"go.podman.io/common/pkg/report"
@@ -40,11 +42,12 @@ type artifactListOutput struct {
4042
Repository string
4143
Size string
4244
Tag string
45+
Created string
4346
VirtualSize string
4447
}
4548

4649
var (
47-
defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Size}}\n{{end -}}"
50+
defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Created}}\t{{.Size}}\n{{end -}}"
4851
)
4952

5053
func init() {
@@ -106,18 +109,30 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
106109
artifactHash = artifactDigest.Encoded()
107110
}
108111

112+
var created string
113+
createdAnnotation, ok := lr.Manifest.Annotations[imgspecv1.AnnotationCreated]
114+
if ok {
115+
createdTime, err := time.Parse(time.RFC3339Nano, createdAnnotation)
116+
if err != nil {
117+
return err
118+
}
119+
created = units.HumanDuration(time.Since(createdTime)) + " ago"
120+
}
121+
109122
artifacts = append(artifacts, artifactListOutput{
110123
Digest: artifactHash,
111124
Repository: named.Name(),
112125
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
113126
Tag: tag,
127+
Created: created,
114128
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
115129
})
116130
}
117131

118132
headers := report.Headers(artifactListOutput{}, map[string]string{
119133
"REPOSITORY": "REPOSITORY",
120134
"Tag": "TAG",
135+
"Created": "CREATED",
121136
"Size": "SIZE",
122137
"Digest": "DIGEST",
123138
})

docs/source/markdown/podman-artifact-ls.1.md.in

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Print results with a Go template.
1818

1919
| **Placeholder** | **Description** |
2020
|-----------------|------------------------------------------------|
21+
| .Created | Elapsed time since the artifact was created |
2122
| .Digest | The computed digest of the artifact's manifest |
2223
| .Repository | Repository name of the artifact |
2324
| .Size | Size artifact in human readable units |
@@ -33,24 +34,24 @@ Print results with a Go template.
3334
List artifacts in the local store
3435
```
3536
$ podman artifact ls
36-
REPOSITORY TAG DIGEST SIZE
37-
quay.io/artifact/foobar1 latest ab609fad386d 2.097GB
38-
quay.io/artifact/foobar2 special cd734b558ceb 12.58MB
37+
REPOSITORY TAG DIGEST CREATED SIZE
38+
quay.io/artifact/foobar1 latest ab609fad386d 6 hours ago 2.097GB
39+
quay.io/artifact/foobar2 special cd734b558ceb 53 seconds ago 12.58MB
3940
```
4041

4142
List artifacts in the local store without truncating the digest
4243
```
4344
$ podman artifact ls --no-trunc
44-
REPOSITORY TAG DIGEST SIZE
45-
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 2.097GB
46-
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 12.58MB
45+
REPOSITORY TAG DIGEST CREATED SIZE
46+
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 6 hours ago 2.097GB
47+
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 53 seconds ago 12.58MB
4748
```
4849

4950
List artifacts in the local store without the title header
5051
```
5152
$ podman artifact ls --noheading
52-
quay.io/artifact/foobar1 latest ab609fad386d 2.097GB
53-
quay.io/artifact/foobar2 special cd734b558ceb 12.58MB
53+
quay.io/artifact/foobar1 latest ab609fad386d 6 hours ago 2.097GB
54+
quay.io/artifact/foobar2 special cd734b558ceb 53 seconds ago 12.58MB
5455
```
5556

5657
List artifact digests and size using a --format

test/e2e/artifact_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ var _ = Describe("Podman artifact", func() {
7878
// Verify if the virtual size values are present in the output
7979
Expect(virtualSizes).To(ContainElement("4192"))
8080
Expect(virtualSizes).To(ContainElement("10240"))
81+
82+
// Check if .Created is reported correctly
83+
createdFormatSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--format", "{{.Created}}")
84+
created := createdFormatSession.OutputToStringArray()
85+
86+
Expect(created).To(HaveLen(2))
87+
88+
// Assuming the test runs less than a minute
89+
humanReadableDurationRegexp := `^(Less than a second|1 second|\d+ seconds) ago$`
90+
Expect(created).To(ContainElements(MatchRegexp(humanReadableDurationRegexp), MatchRegexp(humanReadableDurationRegexp)))
8191
})
8292

8393
It("podman artifact simple add", func() {

0 commit comments

Comments
 (0)