Skip to content

Commit 83668f4

Browse files
Merge pull request #2630 from crosbymichael/install-path
Add optional install path
2 parents ed2bf6d + 60d13d6 commit 83668f4

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

cmd/ctr/commands/install/install.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ var Command = cli.Command{
3737
Name: "replace,r",
3838
Usage: "replace any binaries or libs in the opt directory",
3939
},
40+
cli.StringFlag{
41+
Name: "path",
42+
Usage: "set an optional install path other than the managed opt directory",
43+
},
4044
},
4145
Action: func(context *cli.Context) error {
4246
client, ctx, cancel, err := commands.NewClient(context)
@@ -56,6 +60,9 @@ var Command = cli.Command{
5660
if context.Bool("replace") {
5761
opts = append(opts, containerd.WithInstallReplace)
5862
}
63+
if path := context.String("path"); path != "" {
64+
opts = append(opts, containerd.WithInstallPath(path))
65+
}
5966
return client.Install(ctx, image, opts...)
6067
},
6168
}

install.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,14 @@ import (
3333

3434
// Install a binary image into the opt service
3535
func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) error {
36-
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
37-
Filters: []string{
38-
"id==opt",
39-
},
40-
})
41-
if err != nil {
42-
return err
43-
}
44-
if len(resp.Plugins) != 1 {
45-
return errors.New("opt service not enabled")
46-
}
47-
path := resp.Plugins[0].Exports["path"]
48-
if path == "" {
49-
return errors.New("opt path not exported")
50-
}
5136
var config InstallConfig
5237
for _, o := range opts {
5338
o(&config)
5439
}
40+
path, err := c.getInstallPath(ctx, config)
41+
if err != nil {
42+
return err
43+
}
5544
var (
5645
cs = image.ContentStore()
5746
platform = platforms.Default()
@@ -89,3 +78,25 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
8978
}
9079
return nil
9180
}
81+
82+
func (c *Client) getInstallPath(ctx context.Context, config InstallConfig) (string, error) {
83+
if config.Path != "" {
84+
return config.Path, nil
85+
}
86+
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
87+
Filters: []string{
88+
"id==opt",
89+
},
90+
})
91+
if err != nil {
92+
return "", err
93+
}
94+
if len(resp.Plugins) != 1 {
95+
return "", errors.New("opt service not enabled")
96+
}
97+
path := resp.Plugins[0].Exports["path"]
98+
if path == "" {
99+
return "", errors.New("opt path not exported")
100+
}
101+
return path, nil
102+
}

install_opts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type InstallConfig struct {
2525
Libs bool
2626
// Replace will overwrite existing binaries or libs in the opt directory
2727
Replace bool
28+
// Path to install libs and binaries to
29+
Path string
2830
}
2931

3032
// WithInstallLibs installs libs from the image
@@ -36,3 +38,10 @@ func WithInstallLibs(c *InstallConfig) {
3638
func WithInstallReplace(c *InstallConfig) {
3739
c.Replace = true
3840
}
41+
42+
// WithInstallPath sets the optional install path
43+
func WithInstallPath(path string) InstallOpts {
44+
return func(c *InstallConfig) {
45+
c.Path = path
46+
}
47+
}

0 commit comments

Comments
 (0)