Skip to content

Commit

Permalink
Support specify conf path of toolv2
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal committed Dec 18, 2023
1 parent fbcf0b2 commit dd5b1ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 6 additions & 4 deletions cli/command/install/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ var (
)

type installOptions struct {
host string
path string
host string
path string
confPath string
}

func NewInstallToolCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -38,6 +39,7 @@ func NewInstallToolCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.path, "path", "/usr/local/bin/curve", "Specify target install path of tool v2")
flags.StringVar(&options.confPath, "confPath", "~/.curve/curve.yaml", "Specify target config path of tool v2")

return cmd
}
Expand All @@ -57,8 +59,8 @@ func genInstallToolPlaybook(curveadm *cli.CurveAdm,
Type: step,
Configs: configs,
Options: map[string]interface{}{
comm.KEY_INSTALL_HOST: options.host,
comm.KEY_INSTALL_PATH: options.path,
comm.KEY_INSTALL_PATH: options.path,
comm.KEY_INSTALL_CONF_PATH: options.confPath,
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ const (
KEY_WEBSITE_STATUS = "WEBSITE_STATUS"

// install
KEY_INSTALL_HOST = "INSTALL_HOST"
KEY_INSTALL_PATH = "INSTALL_PATH"
KEY_INSTALL_PATH = "INSTALL_PATH"
KEY_INSTALL_CONF_PATH = "INSTALL_CONF_PATH"
)

// others
Expand Down
14 changes: 9 additions & 5 deletions internal/task/task/install/install_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/opencurve/curveadm/internal/task/task"
tui "github.com/opencurve/curveadm/internal/tui/common"
"github.com/opencurve/curveadm/pkg/module"
"path/filepath"
)

func checkPathExist(path string, sshConfig *module.SSHConfig, curveadm *cli.CurveAdm) error {
Expand All @@ -30,9 +31,9 @@ func checkPathExist(path string, sshConfig *module.SSHConfig, curveadm *cli.Curv

func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) {
layout := dc.GetProjectLayout()
host := curveadm.MemStorage().Get(comm.KEY_INSTALL_HOST).(string)
path := curveadm.MemStorage().Get(comm.KEY_INSTALL_PATH).(string)
hc, err := curveadm.GetHost(host)
confPath := curveadm.MemStorage().Get(comm.KEY_INSTALL_CONF_PATH).(string)
hc, err := curveadm.GetHost(dc.GetHost())
if err != nil {
return nil, err
}
Expand All @@ -46,8 +47,11 @@ func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*tas
if err = checkPathExist(path, hc.GetSSHConfig(), curveadm); err != nil {
return nil, err
}
if err = checkPathExist(confPath, hc.GetSSHConfig(), curveadm); err != nil {
return nil, err
}

subname := fmt.Sprintf("host=%s", host)
subname := fmt.Sprintf("host=%s", dc.GetHost())
t := task.NewTask("Install tool v2", subname, hc.GetSSHConfig())

t.AddStep(&step.CopyFromContainer{
Expand All @@ -57,13 +61,13 @@ func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*tas
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CreateDirectory{
Paths: []string{"~/.curve"},
Paths: []string{filepath.Dir(confPath)},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CopyFromContainer{
ContainerSrcPath: layout.ToolsV2ConfSystemPath,
ContainerId: containerId,
HostDestPath: "~/.curve/curve.yaml",
HostDestPath: confPath,
ExecOptions: curveadm.ExecOptions(),
})

Expand Down

0 comments on commit dd5b1ec

Please sign in to comment.