Add optional install path
This allows users to consume the install functionality but also install to other areas instead of the managed `/opt` dir. ```bash > ctr install --path /usr/local ``` Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
41
install.go
41
install.go
@@ -33,25 +33,14 @@ import (
|
||||
|
||||
// Install a binary image into the opt service
|
||||
func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) error {
|
||||
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
|
||||
Filters: []string{
|
||||
"id==opt",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(resp.Plugins) != 1 {
|
||||
return errors.New("opt service not enabled")
|
||||
}
|
||||
path := resp.Plugins[0].Exports["path"]
|
||||
if path == "" {
|
||||
return errors.New("opt path not exported")
|
||||
}
|
||||
var config InstallConfig
|
||||
for _, o := range opts {
|
||||
o(&config)
|
||||
}
|
||||
path, err := c.getInstallPath(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
cs = image.ContentStore()
|
||||
platform = platforms.Default()
|
||||
@@ -89,3 +78,25 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) getInstallPath(ctx context.Context, config InstallConfig) (string, error) {
|
||||
if config.Path != "" {
|
||||
return config.Path, nil
|
||||
}
|
||||
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
|
||||
Filters: []string{
|
||||
"id==opt",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(resp.Plugins) != 1 {
|
||||
return "", errors.New("opt service not enabled")
|
||||
}
|
||||
path := resp.Plugins[0].Exports["path"]
|
||||
if path == "" {
|
||||
return "", errors.New("opt path not exported")
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user