diff --git a/cmd/podman/artifact/inspect.go b/cmd/podman/artifact/inspect.go index a252e71f65..45452213c6 100644 --- a/cmd/podman/artifact/inspect.go +++ b/cmd/podman/artifact/inspect.go @@ -2,8 +2,8 @@ package artifact import ( "github.com/containers/podman/v5/cmd/podman/common" + "github.com/containers/podman/v5/cmd/podman/inspect" "github.com/containers/podman/v5/cmd/podman/registry" - "github.com/containers/podman/v5/cmd/podman/utils" "github.com/containers/podman/v5/pkg/domain/entities" "github.com/spf13/cobra" ) @@ -13,11 +13,12 @@ var ( Use: "inspect [ARTIFACT...]", Short: "Inspect an OCI artifact", Long: "Provide details on an OCI artifact", - RunE: inspect, + RunE: artifactInspect, Args: cobra.MinimumNArgs(1), ValidArgsFunction: common.AutocompleteArtifacts, Example: `podman artifact inspect quay.io/myimage/myartifact:latest`, } + inspectOpts *entities.InspectOptions ) func init() { @@ -26,10 +27,11 @@ func init() { Parent: artifactCmd, }) - // TODO When things firm up on inspect looks, we can do a format implementation - // flags := inspectCmd.Flags() - // formatFlagName := "format" - // flags.StringVar(&inspectFlag.format, formatFlagName, "", "Format volume output using JSON or a Go template") + inspectOpts = new(entities.InspectOptions) + + flags := inspectCmd.Flags() + formatFlagName := "format" + flags.StringVarP(&inspectOpts.Format, formatFlagName, "f", "json", "Format volume output using JSON or a Go template") // This is something we wanted to do but did not seem important enough for initial PR // remoteFlagName := "remote" @@ -37,14 +39,10 @@ func init() { // TODO When the inspect structure has been defined, we need to uncomment and redirect this. Reminder, this // will also need to be reflected in the podman-artifact-inspect man page - // _ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&machine.InspectInfo{})) + _ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.ArtifactInspectReport{})) } -func inspect(_ *cobra.Command, args []string) error { - artifactOptions := entities.ArtifactInspectOptions{} - inspectData, err := registry.ImageEngine().ArtifactInspect(registry.Context(), args[0], artifactOptions) - if err != nil { - return err - } - return utils.PrintGenericJSON(inspectData) +func artifactInspect(_ *cobra.Command, args []string) error { + inspectOpts.Type = common.ArtifactType + return inspect.Inspect(args, *inspectOpts) } diff --git a/docs/source/markdown/podman-artifact-inspect.1.md b/docs/source/markdown/podman-artifact-inspect.1.md index 5d4cf47f8d..815a101156 100644 --- a/docs/source/markdown/podman-artifact-inspect.1.md +++ b/docs/source/markdown/podman-artifact-inspect.1.md @@ -20,15 +20,60 @@ annotation using RFC3339Nano format, showing when the artifact was initially cre ## OPTIONS -#### **--help** +#### **--format**, **-f**=*format* -Print usage statement. +Format the output using the given Go template. +The keys of the returned JSON can be used as the values for the --format flag (see examples below). + +Valid placeholders for the Go template are listed below: + +| **Placeholder** | **Description** | +| ------------------------ | -------------------------------------------------- | +| .Artifact ... | Artifact details (nested struct) | +| .Digest | Artifact digest (sha256:+64-char hash) | +| .Manifest ... | Artifact manifest details (struct) | +| .Name | Artifact name (string) | +| .TotalSizeBytes | Total Size of the artifact in bytes | ## EXAMPLES Inspect an OCI image in the local store. -``` + +```shell $ podman artifact inspect quay.io/myartifact/myml:latest +[ + { + "Manifest": { + "schemaVersion": 2, + "mediaType": "application/vnd.oci.image.manifest.v1+json", + "config": { + "mediaType": "application/vnd.oci.empty.v1+json", + "digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a", + "size": 2, + "data": "e30=" + }, + "layers": [ + { + "mediaType": "text/plain; charset=utf-8", + "digest": "sha256:f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2", + "size": 5, + "annotations": { + "org.opencontainers.image.title": "foobar.txt" + } + } + ] + }, + "Name": "quay.io/myartifact/mytxt:latest", + "Digest": "sha256:6c28fa07a5b0a1cee29862c1f6ea38a66df982495b14da2c052427eb628ed8c6" + } +] +``` + +Inspect artifact digest for the specified artifact: + +```shell +$ podman artifact inspect quay.io/myartifact/mytxt:latest --format {{.Digest}} +sha256:6c28fa07a5b0a1cee29862c1f6ea38a66df982495b14da2c052427eb628ed8c6 ``` ## SEE ALSO