Skip to content

Commit edf0eef

Browse files
committed
cmd: support nerdctl manifeset inspect
Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
1 parent 38596c8 commit edf0eef

File tree

8 files changed

+555
-18
lines changed

8 files changed

+555
-18
lines changed

cmd/nerdctl/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/containerd/nerdctl/v2/cmd/nerdctl/internal"
4141
"github.com/containerd/nerdctl/v2/cmd/nerdctl/ipfs"
4242
"github.com/containerd/nerdctl/v2/cmd/nerdctl/login"
43+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/manifest"
4344
"github.com/containerd/nerdctl/v2/cmd/nerdctl/namespace"
4445
"github.com/containerd/nerdctl/v2/cmd/nerdctl/network"
4546
"github.com/containerd/nerdctl/v2/cmd/nerdctl/system"
@@ -344,6 +345,10 @@ Config file ($NERDCTL_TOML): %s
344345

345346
// IPFS
346347
ipfs.NewIPFSCommand(),
348+
349+
// Manifest
350+
manifest.Command(),
351+
manifest.InspectCommand(),
347352
)
348353
addApparmorCommand(rootCmd)
349354
container.AddCpCommand(rootCmd)

cmd/nerdctl/manifest/manifest.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package manifest
18+
19+
import (
20+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
func Command() *cobra.Command {
25+
cmd := &cobra.Command{
26+
Annotations: map[string]string{helpers.Category: helpers.Management},
27+
Use: "manifest",
28+
Short: "Manage image manifests and manifest lists.",
29+
RunE: helpers.UnknownSubcommandAction,
30+
SilenceUsage: true,
31+
SilenceErrors: true,
32+
}
33+
34+
cmd.AddCommand(
35+
InspectCommand(),
36+
)
37+
38+
return cmd
39+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package manifest
18+
19+
import (
20+
"github.com/containerd/log"
21+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/completion"
22+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
23+
"github.com/containerd/nerdctl/v2/pkg/api/types"
24+
"github.com/containerd/nerdctl/v2/pkg/clientutil"
25+
"github.com/containerd/nerdctl/v2/pkg/cmd/manifest"
26+
"github.com/containerd/nerdctl/v2/pkg/formatter"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
func InspectCommand() *cobra.Command {
31+
var cmd = &cobra.Command{
32+
Use: "inspect MANIFEST",
33+
Short: "Display the contents of a manifest list or manifest",
34+
Args: cobra.MinimumNArgs(1),
35+
RunE: inspectAction,
36+
ValidArgsFunction: inspectShellComplete,
37+
SilenceUsage: true,
38+
SilenceErrors: true,
39+
}
40+
cmd.Flags().Bool("verbose", false, "Verbose output additional info including layers and platform")
41+
42+
return cmd
43+
}
44+
45+
func processInspectFlags(cmd *cobra.Command) (types.ManifestInspectOptions, error) {
46+
globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
47+
if err != nil {
48+
return types.ManifestInspectOptions{}, err
49+
}
50+
verbose, err := cmd.Flags().GetBool("verbose")
51+
if err != nil {
52+
return types.ManifestInspectOptions{}, err
53+
}
54+
return types.ManifestInspectOptions{
55+
Stdout: cmd.OutOrStdout(),
56+
GOptions: globalOptions,
57+
Verbose: verbose,
58+
}, nil
59+
}
60+
61+
func inspectAction(cmd *cobra.Command, args []string) error {
62+
inspectOptions, err := processInspectFlags(cmd)
63+
if err != nil {
64+
return err
65+
}
66+
rawRef := args[0]
67+
68+
client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), inspectOptions.GOptions.Namespace, inspectOptions.GOptions.Address)
69+
if err != nil {
70+
return err
71+
}
72+
defer cancel()
73+
74+
res, err := manifest.Inspect(ctx, client, rawRef, inspectOptions)
75+
if err != nil {
76+
return err
77+
}
78+
if formatErr := formatter.FormatSlice("", inspectOptions.Stdout, res); formatErr != nil {
79+
log.G(ctx).Error(formatErr)
80+
}
81+
return nil
82+
}
83+
84+
func inspectShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
85+
return completion.ImageNames(cmd)
86+
}

pkg/api/types/manifest_types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package types
18+
19+
import "io"
20+
21+
// ManifestInspectOptions specifies options for `nerdctl manifest inspect`.
22+
type ManifestInspectOptions struct {
23+
Stdout io.Writer
24+
GOptions GlobalCommandOptions
25+
// Verbose output additional info including layers and platform
26+
Verbose bool
27+
}

0 commit comments

Comments
 (0)