mirror of
https://github.com/containers/podman.git
synced 2025-11-29 01:28:22 +08:00
Merge pull request #27352 from rhatdan/artifact
Add CreatedAt format option to podman artifact ls
This commit is contained in:
@@ -38,12 +38,29 @@ type listFlagType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type artifactListOutput struct {
|
type artifactListOutput struct {
|
||||||
Digest string
|
Digest string
|
||||||
Repository string
|
Repository string
|
||||||
Size string
|
Size string
|
||||||
Tag string
|
Tag string
|
||||||
Created string
|
created time.Time
|
||||||
VirtualSize string
|
VirtualSize string
|
||||||
|
virtualBytes int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Created returns human-readable elapsed time since artifact was created
|
||||||
|
func (a artifactListOutput) Created() string {
|
||||||
|
if a.created.IsZero() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return units.HumanDuration(time.Since(a.created)) + " ago"
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt returns the full timestamp string of when the artifact was created
|
||||||
|
func (a artifactListOutput) CreatedAt() string {
|
||||||
|
if a.created.IsZero() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return a.created.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -109,23 +126,23 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
|
|||||||
artifactHash = artifactDigest.Encoded()
|
artifactHash = artifactDigest.Encoded()
|
||||||
}
|
}
|
||||||
|
|
||||||
var created string
|
var createdTime time.Time
|
||||||
createdAnnotation, ok := lr.Manifest.Annotations[imgspecv1.AnnotationCreated]
|
createdAnnotation, ok := lr.Manifest.Annotations[imgspecv1.AnnotationCreated]
|
||||||
if ok {
|
if ok {
|
||||||
createdTime, err := time.Parse(time.RFC3339Nano, createdAnnotation)
|
createdTime, err = time.Parse(time.RFC3339Nano, createdAnnotation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
created = units.HumanDuration(time.Since(createdTime)) + " ago"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts = append(artifacts, artifactListOutput{
|
artifacts = append(artifacts, artifactListOutput{
|
||||||
Digest: artifactHash,
|
Digest: artifactHash,
|
||||||
Repository: named.Name(),
|
Repository: named.Name(),
|
||||||
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
|
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Created: created,
|
created: createdTime,
|
||||||
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
|
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
|
||||||
|
virtualBytes: lr.Artifact.TotalSizeBytes(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Print results with a Go template.
|
|||||||
| **Placeholder** | **Description** |
|
| **Placeholder** | **Description** |
|
||||||
|-----------------|------------------------------------------------|
|
|-----------------|------------------------------------------------|
|
||||||
| .Created | Elapsed time since the artifact was created |
|
| .Created | Elapsed time since the artifact was created |
|
||||||
|
| .CreatedAt | Full timestamp of when the artifact was created|
|
||||||
| .Digest | The computed digest of the artifact's manifest |
|
| .Digest | The computed digest of the artifact's manifest |
|
||||||
| .Repository | Repository name of the artifact |
|
| .Repository | Repository name of the artifact |
|
||||||
| .Size | Size artifact in human readable units |
|
| .Size | Size artifact in human readable units |
|
||||||
|
|||||||
@@ -88,6 +88,16 @@ var _ = Describe("Podman artifact", func() {
|
|||||||
// Assuming the test runs less than a minute
|
// Assuming the test runs less than a minute
|
||||||
humanReadableDurationRegexp := `^(Less than a second|1 second|\d+ seconds) ago$`
|
humanReadableDurationRegexp := `^(Less than a second|1 second|\d+ seconds) ago$`
|
||||||
Expect(created).To(ContainElements(MatchRegexp(humanReadableDurationRegexp), MatchRegexp(humanReadableDurationRegexp)))
|
Expect(created).To(ContainElements(MatchRegexp(humanReadableDurationRegexp), MatchRegexp(humanReadableDurationRegexp)))
|
||||||
|
|
||||||
|
// Check if .CreatedAt is reported correctly
|
||||||
|
createdAtFormatSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--format", "{{.CreatedAt}}")
|
||||||
|
createdAt := createdAtFormatSession.OutputToStringArray()
|
||||||
|
|
||||||
|
Expect(createdAt).To(HaveLen(2))
|
||||||
|
|
||||||
|
// Verify the timestamp format looks like "2025-10-23 12:34:56.789 +0000 UTC"
|
||||||
|
timestampRegexp := `^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)? \+\d{4} UTC$`
|
||||||
|
Expect(createdAt).To(ContainElements(MatchRegexp(timestampRegexp), MatchRegexp(timestampRegexp)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman artifact simple add", func() {
|
It("podman artifact simple add", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user