Skip to content
Closed
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
23 changes: 19 additions & 4 deletions cmd/podman/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package artifact
import (
"fmt"
"os"
"time"

"github.com/containers/podman/v5/cmd/podman/common"
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/docker/go-units"
imgspec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"go.podman.io/common/pkg/completion"
"go.podman.io/common/pkg/report"
Expand Down Expand Up @@ -36,6 +38,7 @@ type listFlagType struct {
}

type artifactListOutput struct {
Created string
Digest string
Repository string
Size string
Expand All @@ -44,7 +47,7 @@ type artifactListOutput struct {
}

var (
defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Size}}\n{{end -}}"
defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Created}}\t{{.Size}}\n{{end -}}"
)

func init() {
Expand Down Expand Up @@ -106,7 +109,18 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
artifactHash = artifactDigest.Encoded()
}

// Get the created time from the manifest annotations
created := ""
if lr.Artifact.Manifest != nil && lr.Artifact.Manifest.Annotations != nil {
if createdStr, ok := lr.Artifact.Manifest.Annotations[imgspec.AnnotationCreated]; ok {
if createdTime, err := time.Parse(time.RFC3339Nano, createdStr); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we logrus if we find "bad" input?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, I am fine with moving to "" for created time.

created = units.HumanDuration(time.Since(createdTime)) + " ago"
}
}
}

artifacts = append(artifacts, artifactListOutput{
Created: created,
Digest: artifactHash,
Repository: named.Name(),
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
Expand All @@ -116,10 +130,11 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
}

headers := report.Headers(artifactListOutput{}, map[string]string{
"REPOSITORY": "REPOSITORY",
"Tag": "TAG",
"Size": "SIZE",
"Created": "CREATED",
"Digest": "DIGEST",
"Repository": "REPOSITORY",
"Size": "SIZE",
"Tag": "TAG",
})

rpt := report.New(os.Stdout, cmd.Name())
Expand Down
17 changes: 9 additions & 8 deletions docs/source/markdown/podman-artifact-ls.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Print results with a Go template.

| **Placeholder** | **Description** |
|-----------------|------------------------------------------------|
| .Created | Artifact creation time in human readable units |
| .Digest | The computed digest of the artifact's manifest |
| .Repository | Repository name of the artifact |
| .Size | Size artifact in human readable units |
Expand All @@ -33,24 +34,24 @@ Print results with a Go template.
List artifacts in the local store
```
$ podman artifact ls
REPOSITORY TAG DIGEST SIZE
quay.io/artifact/foobar1 latest ab609fad386d 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb 12.58MB
REPOSITORY TAG DIGEST CREATED SIZE
quay.io/artifact/foobar1 latest ab609fad386d 3 weeks ago 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb 2 days ago 12.58MB
```

List artifacts in the local store without truncating the digest
```
$ podman artifact ls --no-trunc
REPOSITORY TAG DIGEST SIZE
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 12.58MB
REPOSITORY TAG DIGEST CREATED SIZE
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 3 weeks ago 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 2 days ago 12.58MB
```

List artifacts in the local store without the title header
```
$ podman artifact ls --noheading
quay.io/artifact/foobar1 latest ab609fad386d 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb 12.58MB
quay.io/artifact/foobar1 latest ab609fad386d 3 weeks ago 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb 2 days ago 12.58MB
```

List artifact digests and size using a --format
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ var _ = Describe("Podman artifact", func() {
// Verify if the virtual size values are present in the output
Expect(virtualSizes).To(ContainElement("4192"))
Expect(virtualSizes).To(ContainElement("10240"))

// Check if .Created is reported and is not "<unknown>"
createdFormatSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--format", "{{.Created}}")
createdTimes := createdFormatSession.OutputToStringArray()

// Should list 2 lines (without the header)
Expect(createdTimes).To(HaveLen(2))

// Verify the created times are not "<unknown>" and end with " ago"
for _, created := range createdTimes {
Expect(created).ToNot(Equal("<unknown>"))
Expect(created).To(HaveSuffix(" ago"))
}
})

It("podman artifact simple add", func() {
Expand Down