github.com/containerd/Containerd@v1.4.13/cmd/ctr/commands/install/install.go (about) 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 install 18 19 import ( 20 "github.com/containerd/containerd" 21 "github.com/containerd/containerd/cmd/ctr/commands" 22 "github.com/urfave/cli" 23 ) 24 25 // Command to install binary packages 26 var Command = cli.Command{ 27 Name: "install", 28 Usage: "install a new package", 29 ArgsUsage: "<ref>", 30 Description: "install a new package", 31 Flags: []cli.Flag{ 32 cli.BoolFlag{ 33 Name: "libs,l", 34 Usage: "install libs from the image", 35 }, 36 cli.BoolFlag{ 37 Name: "replace,r", 38 Usage: "replace any binaries or libs in the opt directory", 39 }, 40 cli.StringFlag{ 41 Name: "path", 42 Usage: "set an optional install path other than the managed opt directory", 43 }, 44 }, 45 Action: func(context *cli.Context) error { 46 client, ctx, cancel, err := commands.NewClient(context) 47 if err != nil { 48 return err 49 } 50 defer cancel() 51 ref := context.Args().First() 52 image, err := client.GetImage(ctx, ref) 53 if err != nil { 54 return err 55 } 56 var opts []containerd.InstallOpts 57 if context.Bool("libs") { 58 opts = append(opts, containerd.WithInstallLibs) 59 } 60 if context.Bool("replace") { 61 opts = append(opts, containerd.WithInstallReplace) 62 } 63 if path := context.String("path"); path != "" { 64 opts = append(opts, containerd.WithInstallPath(path)) 65 } 66 return client.Install(ctx, image, opts...) 67 }, 68 }