From 71ce4503b54650434bfab2b5be4267a904671ead Mon Sep 17 00:00:00 2001 From: fredchenbj Date: Sat, 14 Mar 2020 15:28:09 +0800 Subject: [PATCH 1/5] ignore vendor Signed-off-by: fredchenbj --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eccebc3670..8700f03ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +vendor/ bin/ *.tar *.gz From a73bb49f4733b20d8c491c24015e4dbbc1535039 Mon Sep 17 00:00:00 2001 From: fredchenbj Date: Wed, 25 Mar 2020 14:10:38 +0800 Subject: [PATCH 2/5] specify the component binary path Signed-off-by: fredchenbj --- cmd/root.go | 15 +++++---- cmd/run.go | 35 ++++++++++++--------- components/playground/instance/instance.go | 9 ++---- components/playground/instance/pd.go | 4 +-- components/playground/instance/tidb.go | 4 +-- components/playground/instance/tikv.go | 4 +-- components/playground/main.go | 36 +++++++++++++++++++--- pkg/meta/meta.go | 13 ++++++++ 8 files changed, 83 insertions(+), 37 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 05be013ea1..78e81ebc06 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -52,21 +52,24 @@ the latest stable version will be downloaded from the repository. FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, Version: fmt.Sprintf("%s+%s(%s)", version.NewTiUPVersion().SemVer(), version.GitBranch, version.GitHash), Args: func(cmd *cobra.Command, args []string) error { - // Support `tiup ` + // Support `tiup :[]:[]` return nil }, RunE: func(cmd *cobra.Command, args []string) error { if binary != "" { - component, ver := meta.ParseCompVersion(binary) + component, ver, binPath := meta.ParseBinary(binary) selectedVer, err := meta.SelectInstalledVersion(component, ver) if err != nil { return err } - binaryPath, err := meta.BinaryPath(component, selectedVer) - if err != nil { - return err + if binPath == "" { + binPath, err = meta.BinaryPath(component, selectedVer) + if err != nil { + return err + } } - fmt.Println(binaryPath) + + fmt.Println(binPath) return nil } if len(args) > 0 { diff --git a/cmd/run.go b/cmd/run.go index 8b8939fba3..405ccd27b4 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -33,7 +33,7 @@ import ( ) func runComponent(tag, spec string, args []string, rm bool) error { - component, version := meta.ParseCompVersion(spec) + component, version, binPath := meta.ParseBinary(spec) if !isSupportedComponent(component) { return fmt.Errorf("unkonwn component `%s` (see supported components via `tiup list --refresh`)", component) } @@ -41,7 +41,7 @@ func runComponent(tag, spec string, args []string, rm bool) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - p, err := launchComponent(ctx, component, version, tag, args) + p, err := launchComponent(ctx, component, version, binPath, tag, args) // If the process has been launched, we must save the process info to meta directory if err == nil || (p != nil && p.Pid != 0) { defer cleanDataDir(rm, p.Dir) @@ -134,19 +134,26 @@ func base62Tag() string { return string(b) } -func launchComponent(ctx context.Context, component string, version repository.Version, tag string, args []string) (*process, error) { - selectVer, err := meta.DownloadComponentIfMissing(component, version) - if err != nil { - return nil, err - } - binPath, err := meta.BinaryPath(component, selectVer) - if err != nil { - return nil, err - } +func launchComponent(ctx context.Context, component string, version repository.Version, binPath string, tag string, args []string) (*process, error) { + var selectVer repository.Version + var installPath string + var err error - installPath, err := meta.ComponentInstalledDir(component, selectVer) - if err != nil { - return nil, err + if binPath == "" { + selectVer, err = meta.DownloadComponentIfMissing(component, version) + if err != nil { + return nil, err + } + + binPath, err = meta.BinaryPath(component, selectVer) + if err != nil { + return nil, err + } + + installPath, err = meta.ComponentInstalledDir(component, selectVer) + if err != nil { + return nil, err + } } wd := os.Getenv(localdata.EnvNameInstanceDataDir) diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index 53c865add2..f8d54bbe31 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -31,13 +31,10 @@ type instance struct { // Instance represent running component type Instance interface { Pid() int - Start(ctx context.Context, version repository.Version) error + Start(ctx context.Context, version repository.Version, binPath string) error Wait() error } -func compVersion(comp string, version repository.Version) string { - if version.IsEmpty() { - return comp - } - return fmt.Sprintf("%v:%v", comp, version) +func specifyBinary(comp string, version repository.Version, binPath string) string { + return fmt.Sprintf("%v:%v:%v", comp, version, binPath) } diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index 0d87b762ba..5cf2fe36a7 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -53,13 +53,13 @@ func (inst *PDInstance) Join(pds []*PDInstance) *PDInstance { } // Start calls set inst.cmd and Start -func (inst *PDInstance) Start(ctx context.Context, version repository.Version) error { +func (inst *PDInstance) Start(ctx context.Context, version repository.Version, binPath string) error { if err := os.MkdirAll(inst.Dir, 0755); err != nil { return err } uid := fmt.Sprintf("pd-%d", inst.ID) args := []string{ - "tiup", compVersion("pd", version), + "tiup", specifyBinary("pd", version, binPath), "--name=" + uid, fmt.Sprintf("--data-dir=%s", filepath.Join(inst.Dir, "data")), fmt.Sprintf("--peer-urls=http://%s:%d", inst.Host, inst.Port), diff --git a/components/playground/instance/tidb.go b/components/playground/instance/tidb.go index c8ed5f243e..afff4e1d48 100644 --- a/components/playground/instance/tidb.go +++ b/components/playground/instance/tidb.go @@ -49,7 +49,7 @@ func NewTiDBInstance(dir, host string, id int, pds []*PDInstance) *TiDBInstance } // Start calls set inst.cmd and Start -func (inst *TiDBInstance) Start(ctx context.Context, version repository.Version) error { +func (inst *TiDBInstance) Start(ctx context.Context, version repository.Version, binPath string) error { if err := os.MkdirAll(inst.Dir, 0755); err != nil { return err } @@ -58,7 +58,7 @@ func (inst *TiDBInstance) Start(ctx context.Context, version repository.Version) endpoints = append(endpoints, fmt.Sprintf("%s:%d", inst.Host, pd.StatusPort)) } args := []string{ - "tiup", compVersion("tidb", version), + "tiup", specifyBinary("tidb", version, binPath), "-P", strconv.Itoa(inst.Port), "--store=tikv", fmt.Sprintf("--host=%s", inst.Host), diff --git a/components/playground/instance/tikv.go b/components/playground/instance/tikv.go index 6afdf1c173..0445123d75 100644 --- a/components/playground/instance/tikv.go +++ b/components/playground/instance/tikv.go @@ -50,7 +50,7 @@ func NewTiKVInstance(dir, host string, id int, pds []*PDInstance) *TiKVInstance } // Start calls set inst.cmd and Start -func (inst *TiKVInstance) Start(ctx context.Context, version repository.Version) error { +func (inst *TiKVInstance) Start(ctx context.Context, version repository.Version, binPath string) error { if err := os.MkdirAll(inst.Dir, 0755); err != nil { return err } @@ -69,7 +69,7 @@ func (inst *TiKVInstance) Start(ctx context.Context, version repository.Version) endpoints = append(endpoints, fmt.Sprintf("http://%s:%d", inst.Host, pd.StatusPort)) } inst.cmd = exec.CommandContext(ctx, - "tiup", compVersion("tikv", version), + "tiup", specifyBinary("tikv", version, binPath), fmt.Sprintf("--addr=%s:%d", inst.Host, inst.Port), fmt.Sprintf("--status-addr=%s:%d", inst.Host, inst.StatusPort), fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), diff --git a/components/playground/main.go b/components/playground/main.go index ff25f628ea..65bca37fe5 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -73,6 +73,9 @@ func execute() error { pdNum := 1 host := "127.0.0.1" monitor := false + tidbBinPath := "" + tikvBinPath := "" + pdBinPath := "" rootCmd := &cobra.Command{ Use: "tiup playground [version]", @@ -82,14 +85,16 @@ if you don't specified a version. Examples: $ tiup playground nightly # Start a TiDB nightly version local cluster $ tiup playground v3.0.10 --db 3 --pd 3 --kv 3 # Start a local cluster with 10 nodes - $ tiup playground nightly --monitor # Start a local cluster with monitor system`, + $ tiup playground nightly --monitor # Start a local cluster with monitor system + $ tiup playground --db.binpath /xx/tidb-server --pd.binpath /xx/pd-server --kv.binpath /xx/tikv-server + # Start a local cluster with component binary path`, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { version := "" if len(args) > 0 { version = args[0] } - return bootCluster(version, pdNum, tidbNum, tikvNum, host, monitor) + return bootCluster(version, pdNum, tidbNum, tikvNum, host, monitor, tidbBinPath, tikvBinPath, pdBinPath) }, } @@ -98,6 +103,9 @@ Examples: rootCmd.Flags().IntVarP(&pdNum, "pd", "", 1, "PD instance number") rootCmd.Flags().StringVarP(&host, "host", "", host, "Playground cluster host") rootCmd.Flags().BoolVar(&monitor, "monitor", false, "Start prometheus component") + rootCmd.Flags().StringVarP(&tidbBinPath, "db.binpath", "", tidbBinPath, "TiDB instance binary path") + rootCmd.Flags().StringVarP(&tikvBinPath, "kv.binpath", "", tikvBinPath, "TiKV instance binary path") + rootCmd.Flags().StringVarP(&pdBinPath, "pd.binpath", "", pdBinPath, "PD instance binary path") return rootCmd.Execute() } @@ -147,12 +155,23 @@ func hasDashboard(pdAddr string) bool { return false } -func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monitor bool) error { +func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monitor bool, tidbBinPath, tikvBinPath, pdBinPath string) error { if pdNum < 1 || tidbNum < 1 || tikvNum < 1 { return fmt.Errorf("all components count must be great than 0 (tidb=%v, tikv=%v, pd=%v)", tidbNum, tikvNum, pdNum) } + var pathMap = make(map[string]string) + if tidbBinPath != "" { + pathMap["tidb"] = tidbBinPath + } + if tikvBinPath != "" { + pathMap["tikv"] = tikvBinPath + } + if pdBinPath != "" { + pathMap["pd"] = pdBinPath + } + // Initialize the profile profileRoot := os.Getenv(localdata.EnvNameHome) if profileRoot == "" { @@ -160,6 +179,9 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit } profile := localdata.NewProfile(profileRoot) for _, comp := range []string{"pd", "tikv", "tidb"} { + if pathMap[comp] != "" { + continue + } if err := installIfMissing(profile, comp, version); err != nil { return err } @@ -171,6 +193,7 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit } all := make([]instance.Instance, 0, pdNum+tikvNum+tidbNum) + allRole := make([]string, 0, pdNum+tikvNum+tidbNum) pds := make([]*instance.PDInstance, 0, pdNum) kvs := make([]*instance.TiKVInstance, 0, tikvNum) dbs := make([]*instance.TiDBInstance, 0, tidbNum) @@ -183,6 +206,7 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit inst := instance.NewPDInstance(dir, host, i) pds = append(pds, inst) all = append(all, inst) + allRole = append(allRole, "pd") } for _, pd := range pds { pd.Join(pds) @@ -193,6 +217,7 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit inst := instance.NewTiKVInstance(dir, host, i, pds) kvs = append(kvs, inst) all = append(all, inst) + allRole = append(allRole, "tikv") } for i := 0; i < tidbNum; i++ { @@ -200,6 +225,7 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit inst := instance.NewTiDBInstance(dir, host, i, pds) dbs = append(dbs, inst) all = append(all, inst) + allRole = append(allRole, "tidb") } fmt.Println("Playground Bootstrapping...") @@ -248,8 +274,8 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit }() } - for _, inst := range all { - if err := inst.Start(ctx, repository.Version(version)); err != nil { + for i, inst := range all { + if err := inst.Start(ctx, repository.Version(version), pathMap[allRole[i]]); err != nil { return err } } diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index def528eed2..4276bccb24 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -104,6 +104,19 @@ func LocalRoot() string { return profile.Root() } +// ParseBinary parses component part from :: specification +func ParseBinary(spec string) (string, repository.Version, string) { + if strings.Contains(spec, ":") { + parts := strings.Split(spec, ":") + var binPath = "" + if len(parts) == 3 { + binPath = parts[2] + } + return parts[0], repository.Version(parts[1]), binPath + } + return spec, "", "" +} + // ParseCompVersion parses component part from [:version] specification func ParseCompVersion(spec string) (string, repository.Version) { if strings.Contains(spec, ":") { From 158401d9566abc81591d309833d90be9da5abdcd Mon Sep 17 00:00:00 2001 From: fredchenbj Date: Thu, 26 Mar 2020 10:35:15 +0800 Subject: [PATCH 3/5] change protocal of component Signed-off-by: fredchenbj --- cmd/root.go | 31 ++++++++++++++-------- cmd/run.go | 4 +-- components/playground/instance/instance.go | 7 +++-- components/playground/instance/pd.go | 3 ++- components/playground/instance/tidb.go | 3 ++- components/playground/instance/tikv.go | 3 ++- pkg/meta/meta.go | 13 --------- tests/expected/tiup/tiup-h.output | 1 + tests/expected/tiup/tiup-help.output | 1 + tests/expected/tiup/tiup.output | 1 + 10 files changed, 36 insertions(+), 31 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 78e81ebc06..882ae0a193 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" "os" + "strings" "github.com/fatih/color" "github.com/pingcap-incubator/tiup/pkg/meta" @@ -31,6 +32,7 @@ func init() { var ( binary string + binPath string tag string rm bool repoOpts repository.Options @@ -52,24 +54,21 @@ the latest stable version will be downloaded from the repository. FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, Version: fmt.Sprintf("%s+%s(%s)", version.NewTiUPVersion().SemVer(), version.GitBranch, version.GitHash), Args: func(cmd *cobra.Command, args []string) error { - // Support `tiup :[]:[]` + // Support `tiup ` return nil }, RunE: func(cmd *cobra.Command, args []string) error { if binary != "" { - component, ver, binPath := meta.ParseBinary(binary) + component, ver := meta.ParseCompVersion(binary) selectedVer, err := meta.SelectInstalledVersion(component, ver) if err != nil { return err } - if binPath == "" { - binPath, err = meta.BinaryPath(component, selectedVer) - if err != nil { - return err - } + binaryPath, err := meta.BinaryPath(component, selectedVer) + if err != nil { + return err } - - fmt.Println(binPath) + fmt.Println(binaryPath) return nil } if len(args) > 0 { @@ -78,15 +77,24 @@ the latest stable version will be downloaded from the repository. // will be parsed correctly. // e.g: tiup --tag mytag --rm playground --db 3 --pd 3 --kv 4 // => run "playground" with parameters "--db 3 --pd 3 --kv 4" + // tiup --tag mytag --binpath /xxx/tikv-server tikv var transparentParams []string componentSpec := args[0] for i, arg := range os.Args { if arg == componentSpec { - transparentParams = os.Args[i+1:] + var num = 1 + if len(os.Args) > i+1 && strings.HasPrefix(os.Args[i+1], "--binpath=") { + num += 1 + flagLen := len("--binpath=") + if len(os.Args[i+1]) > flagLen { + binPath = os.Args[i+1][flagLen:] + } + } + transparentParams = os.Args[i+num:] break } } - return runComponent(tag, componentSpec, transparentParams, rm) + return runComponent(tag, componentSpec, binPath, transparentParams, rm) } return cmd.Help() }, @@ -104,6 +112,7 @@ the latest stable version will be downloaded from the repository. "and the latest version installed will be selected if no version specified") rootCmd.Flags().StringVarP(&tag, "tag", "T", "", "Specify a tag for component instance") rootCmd.Flags().BoolVar(&rm, "rm", false, "Remove the data directory when the component instance finishes its run") + rootCmd.Flags().StringVar(&binPath, "binpath", "", "Specify the binary path of component instance") rootCmd.AddCommand( newInstallCmd(), diff --git a/cmd/run.go b/cmd/run.go index 405ccd27b4..834c6244ca 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -32,8 +32,8 @@ import ( "github.com/pingcap/errors" ) -func runComponent(tag, spec string, args []string, rm bool) error { - component, version, binPath := meta.ParseBinary(spec) +func runComponent(tag, spec, binPath string, args []string, rm bool) error { + component, version := meta.ParseCompVersion(spec) if !isSupportedComponent(component) { return fmt.Errorf("unkonwn component `%s` (see supported components via `tiup list --refresh`)", component) } diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index f8d54bbe31..56b635280f 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -35,6 +35,9 @@ type Instance interface { Wait() error } -func specifyBinary(comp string, version repository.Version, binPath string) string { - return fmt.Sprintf("%v:%v:%v", comp, version, binPath) +func compVersion(comp string, version repository.Version) string { + if version.IsEmpty() { + return comp + } + return fmt.Sprintf("%v:%v", comp, version) } diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index 5cf2fe36a7..35e4084ae9 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -59,7 +59,8 @@ func (inst *PDInstance) Start(ctx context.Context, version repository.Version, b } uid := fmt.Sprintf("pd-%d", inst.ID) args := []string{ - "tiup", specifyBinary("pd", version, binPath), + "tiup", compVersion("pd", version), + fmt.Sprintf("--binpath=%s", binPath), "--name=" + uid, fmt.Sprintf("--data-dir=%s", filepath.Join(inst.Dir, "data")), fmt.Sprintf("--peer-urls=http://%s:%d", inst.Host, inst.Port), diff --git a/components/playground/instance/tidb.go b/components/playground/instance/tidb.go index afff4e1d48..911dbc8622 100644 --- a/components/playground/instance/tidb.go +++ b/components/playground/instance/tidb.go @@ -58,7 +58,8 @@ func (inst *TiDBInstance) Start(ctx context.Context, version repository.Version, endpoints = append(endpoints, fmt.Sprintf("%s:%d", inst.Host, pd.StatusPort)) } args := []string{ - "tiup", specifyBinary("tidb", version, binPath), + "tiup", compVersion("tidb", version), + fmt.Sprintf("--binpath=%s", binPath), "-P", strconv.Itoa(inst.Port), "--store=tikv", fmt.Sprintf("--host=%s", inst.Host), diff --git a/components/playground/instance/tikv.go b/components/playground/instance/tikv.go index 0445123d75..31456f9680 100644 --- a/components/playground/instance/tikv.go +++ b/components/playground/instance/tikv.go @@ -69,7 +69,8 @@ func (inst *TiKVInstance) Start(ctx context.Context, version repository.Version, endpoints = append(endpoints, fmt.Sprintf("http://%s:%d", inst.Host, pd.StatusPort)) } inst.cmd = exec.CommandContext(ctx, - "tiup", specifyBinary("tikv", version, binPath), + "tiup", compVersion("tikv", version), + fmt.Sprintf("--binpath=%s", binPath), fmt.Sprintf("--addr=%s:%d", inst.Host, inst.Port), fmt.Sprintf("--status-addr=%s:%d", inst.Host, inst.StatusPort), fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index 4276bccb24..def528eed2 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -104,19 +104,6 @@ func LocalRoot() string { return profile.Root() } -// ParseBinary parses component part from :: specification -func ParseBinary(spec string) (string, repository.Version, string) { - if strings.Contains(spec, ":") { - parts := strings.Split(spec, ":") - var binPath = "" - if len(parts) == 3 { - binPath = parts[2] - } - return parts[0], repository.Version(parts[1]), binPath - } - return spec, "", "" -} - // ParseCompVersion parses component part from [:version] specification func ParseCompVersion(spec string) (string, repository.Version) { if strings.Contains(spec, ":") { diff --git a/tests/expected/tiup/tiup-h.output b/tests/expected/tiup/tiup-h.output index 51042bc86c..591a31d182 100644 --- a/tests/expected/tiup/tiup-h.output +++ b/tests/expected/tiup/tiup-h.output @@ -33,6 +33,7 @@ Available Components: Flags: -B, --binary [:version] Print binary path of a specific version of a component [:version] and the latest version installed will be selected if no version specified + --binpath string Specify the binary path of component instance -h, --help help for tiup --rm Remove the data directory when the component instance finishes its run --skip-version-check Skip the strict version check, by default a version must be a valid SemVer string diff --git a/tests/expected/tiup/tiup-help.output b/tests/expected/tiup/tiup-help.output index eaa3610582..d841e5cde8 100644 --- a/tests/expected/tiup/tiup-help.output +++ b/tests/expected/tiup/tiup-help.output @@ -33,6 +33,7 @@ Available Components: Flags: -B, --binary [:version] Print binary path of a specific version of a component [:version] and the latest version installed will be selected if no version specified + --binpath string Specify the binary path of component instance -h, --help help for tiup --rm Remove the data directory when the component instance finishes its run --skip-version-check Skip the strict version check, by default a version must be a valid SemVer string diff --git a/tests/expected/tiup/tiup.output b/tests/expected/tiup/tiup.output index 51042bc86c..591a31d182 100644 --- a/tests/expected/tiup/tiup.output +++ b/tests/expected/tiup/tiup.output @@ -33,6 +33,7 @@ Available Components: Flags: -B, --binary [:version] Print binary path of a specific version of a component [:version] and the latest version installed will be selected if no version specified + --binpath string Specify the binary path of component instance -h, --help help for tiup --rm Remove the data directory when the component instance finishes its run --skip-version-check Skip the strict version check, by default a version must be a valid SemVer string From 12f3e5ee03ae71109c21669dc38113d48f54941e Mon Sep 17 00:00:00 2001 From: fredchenbj Date: Fri, 27 Mar 2020 11:40:27 +0800 Subject: [PATCH 4/5] fix some comments Signed-off-by: fredchenbj --- cmd/root.go | 14 ++------------ components/playground/instance/pd.go | 4 ++-- components/playground/instance/tidb.go | 4 ++-- components/playground/instance/tikv.go | 4 ++-- components/playground/main.go | 13 ++++++++++--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 882ae0a193..31e063125e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,14 +15,12 @@ package cmd import ( "fmt" - "os" - "strings" - "github.com/fatih/color" "github.com/pingcap-incubator/tiup/pkg/meta" "github.com/pingcap-incubator/tiup/pkg/repository" "github.com/pingcap-incubator/tiup/pkg/version" "github.com/spf13/cobra" + "os" ) var rootCmd *cobra.Command @@ -82,15 +80,7 @@ the latest stable version will be downloaded from the repository. componentSpec := args[0] for i, arg := range os.Args { if arg == componentSpec { - var num = 1 - if len(os.Args) > i+1 && strings.HasPrefix(os.Args[i+1], "--binpath=") { - num += 1 - flagLen := len("--binpath=") - if len(os.Args[i+1]) > flagLen { - binPath = os.Args[i+1][flagLen:] - } - } - transparentParams = os.Args[i+num:] + transparentParams = os.Args[i+1:] break } } diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index 35e4084ae9..2d0a5cdfbf 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -59,8 +59,8 @@ func (inst *PDInstance) Start(ctx context.Context, version repository.Version, b } uid := fmt.Sprintf("pd-%d", inst.ID) args := []string{ - "tiup", compVersion("pd", version), - fmt.Sprintf("--binpath=%s", binPath), + "tiup", fmt.Sprintf("--binpath=%s", binPath), + compVersion("pd", version), "--name=" + uid, fmt.Sprintf("--data-dir=%s", filepath.Join(inst.Dir, "data")), fmt.Sprintf("--peer-urls=http://%s:%d", inst.Host, inst.Port), diff --git a/components/playground/instance/tidb.go b/components/playground/instance/tidb.go index 911dbc8622..a122cfa4ed 100644 --- a/components/playground/instance/tidb.go +++ b/components/playground/instance/tidb.go @@ -58,8 +58,8 @@ func (inst *TiDBInstance) Start(ctx context.Context, version repository.Version, endpoints = append(endpoints, fmt.Sprintf("%s:%d", inst.Host, pd.StatusPort)) } args := []string{ - "tiup", compVersion("tidb", version), - fmt.Sprintf("--binpath=%s", binPath), + "tiup", fmt.Sprintf("--binpath=%s", binPath), + compVersion("tidb", version), "-P", strconv.Itoa(inst.Port), "--store=tikv", fmt.Sprintf("--host=%s", inst.Host), diff --git a/components/playground/instance/tikv.go b/components/playground/instance/tikv.go index 31456f9680..0f45aa57dc 100644 --- a/components/playground/instance/tikv.go +++ b/components/playground/instance/tikv.go @@ -69,8 +69,8 @@ func (inst *TiKVInstance) Start(ctx context.Context, version repository.Version, endpoints = append(endpoints, fmt.Sprintf("http://%s:%d", inst.Host, pd.StatusPort)) } inst.cmd = exec.CommandContext(ctx, - "tiup", compVersion("tikv", version), - fmt.Sprintf("--binpath=%s", binPath), + "tiup", fmt.Sprintf("--binpath=%s", binPath), + compVersion("tikv", version), fmt.Sprintf("--addr=%s:%d", inst.Host, inst.Port), fmt.Sprintf("--status-addr=%s:%d", inst.Host, inst.StatusPort), fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), diff --git a/components/playground/main.go b/components/playground/main.go index 65bca37fe5..952cddcd60 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -155,6 +155,13 @@ func hasDashboard(pdAddr string) bool { return false } +func getAbsolutePath(binPath string) string { + if !strings.HasPrefix(binPath, "/") { + binPath = filepath.Join(os.Getenv(localdata.EnvNameWorkDir), binPath) + } + return binPath +} + func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monitor bool, tidbBinPath, tikvBinPath, pdBinPath string) error { if pdNum < 1 || tidbNum < 1 || tikvNum < 1 { return fmt.Errorf("all components count must be great than 0 (tidb=%v, tikv=%v, pd=%v)", @@ -163,13 +170,13 @@ func bootCluster(version string, pdNum, tidbNum, tikvNum int, host string, monit var pathMap = make(map[string]string) if tidbBinPath != "" { - pathMap["tidb"] = tidbBinPath + pathMap["tidb"] = getAbsolutePath(tidbBinPath) } if tikvBinPath != "" { - pathMap["tikv"] = tikvBinPath + pathMap["tikv"] = getAbsolutePath(tikvBinPath) } if pdBinPath != "" { - pathMap["pd"] = pdBinPath + pathMap["pd"] = getAbsolutePath(pdBinPath) } // Initialize the profile From 5dbc958341c2e902934997823f3b482e9e220eeb Mon Sep 17 00:00:00 2001 From: fredchenbj Date: Sun, 29 Mar 2020 09:38:08 +0800 Subject: [PATCH 5/5] fix some comments Signed-off-by: fredchenbj --- components/playground/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/playground/main.go b/components/playground/main.go index 952cddcd60..ac718360ed 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -86,8 +86,7 @@ Examples: $ tiup playground nightly # Start a TiDB nightly version local cluster $ tiup playground v3.0.10 --db 3 --pd 3 --kv 3 # Start a local cluster with 10 nodes $ tiup playground nightly --monitor # Start a local cluster with monitor system - $ tiup playground --db.binpath /xx/tidb-server --pd.binpath /xx/pd-server --kv.binpath /xx/tikv-server - # Start a local cluster with component binary path`, + $ tiup playground --db.binpath /xx/tidb-server # Start a local cluster with component binary path`, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { version := "" @@ -156,7 +155,7 @@ func hasDashboard(pdAddr string) bool { } func getAbsolutePath(binPath string) string { - if !strings.HasPrefix(binPath, "/") { + if !strings.HasPrefix(binPath, "/") && !strings.HasPrefix(binPath, "~") { binPath = filepath.Join(os.Getenv(localdata.EnvNameWorkDir), binPath) } return binPath