Skip to content

Commit 5a0b74b

Browse files
Merge pull request #27352 from rhatdan/artifact
Add CreatedAt format option to podman artifact ls
2 parents cfe5bdb + 96ab027 commit 5a0b74b

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

cmd/podman/artifact/list.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,29 @@ type listFlagType struct {
3838
}
3939

4040
type artifactListOutput struct {
41-
Digest string
42-
Repository string
43-
Size string
44-
Tag string
45-
Created string
46-
VirtualSize string
41+
Digest string
42+
Repository string
43+
Size string
44+
Tag string
45+
created time.Time
46+
VirtualSize string
47+
virtualBytes int64
48+
}
49+
50+
// Created returns human-readable elapsed time since artifact was created
51+
func (a artifactListOutput) Created() string {
52+
if a.created.IsZero() {
53+
return ""
54+
}
55+
return units.HumanDuration(time.Since(a.created)) + " ago"
56+
}
57+
58+
// CreatedAt returns the full timestamp string of when the artifact was created
59+
func (a artifactListOutput) CreatedAt() string {
60+
if a.created.IsZero() {
61+
return ""
62+
}
63+
return a.created.String()
4764
}
4865

4966
var (
@@ -109,23 +126,23 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
109126
artifactHash = artifactDigest.Encoded()
110127
}
111128

112-
var created string
129+
var createdTime time.Time
113130
createdAnnotation, ok := lr.Manifest.Annotations[imgspecv1.AnnotationCreated]
114131
if ok {
115-
createdTime, err := time.Parse(time.RFC3339Nano, createdAnnotation)
132+
createdTime, err = time.Parse(time.RFC3339Nano, createdAnnotation)
116133
if err != nil {
117134
return err
118135
}
119-
created = units.HumanDuration(time.Since(createdTime)) + " ago"
120136
}
121137

122138
artifacts = append(artifacts, artifactListOutput{
123-
Digest: artifactHash,
124-
Repository: named.Name(),
125-
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
126-
Tag: tag,
127-
Created: created,
128-
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
139+
Digest: artifactHash,
140+
Repository: named.Name(),
141+
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
142+
Tag: tag,
143+
created: createdTime,
144+
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
145+
virtualBytes: lr.Artifact.TotalSizeBytes(),
129146
})
130147
}
131148

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Print results with a Go template.
1919
| **Placeholder** | **Description** |
2020
|-----------------|------------------------------------------------|
2121
| .Created | Elapsed time since the artifact was created |
22+
| .CreatedAt | Full timestamp of when the artifact was created|
2223
| .Digest | The computed digest of the artifact's manifest |
2324
| .Repository | Repository name of the artifact |
2425
| .Size | Size artifact in human readable units |

test/e2e/artifact_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ var _ = Describe("Podman artifact", func() {
8888
// Assuming the test runs less than a minute
8989
humanReadableDurationRegexp := `^(Less than a second|1 second|\d+ seconds) ago$`
9090
Expect(created).To(ContainElements(MatchRegexp(humanReadableDurationRegexp), MatchRegexp(humanReadableDurationRegexp)))
91+
92+
// Check if .CreatedAt is reported correctly
93+
createdAtFormatSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--format", "{{.CreatedAt}}")
94+
createdAt := createdAtFormatSession.OutputToStringArray()
95+
96+
Expect(createdAt).To(HaveLen(2))
97+
98+
// Verify the timestamp format looks like "2025-10-23 12:34:56.789 +0000 UTC"
99+
timestampRegexp := `^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)? \+\d{4} UTC$`
100+
Expect(createdAt).To(ContainElements(MatchRegexp(timestampRegexp), MatchRegexp(timestampRegexp)))
91101
})
92102

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

0 commit comments

Comments
 (0)