Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
fix: config import bug (arana-db#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii authored Oct 28, 2022
1 parent dacf1a2 commit df8d11c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
26 changes: 4 additions & 22 deletions cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ _____________________________________________
`

const (
_keyBootstrap = "config"
_keyImport = "import"
)
const _keyBootstrap = "config"

func init() {
cmd := &cobra.Command{
Expand All @@ -65,29 +62,17 @@ func init() {
}
cmd.PersistentFlags().
StringP(_keyBootstrap, "c", os.Getenv(constants.EnvBootstrapPath), "bootstrap configuration file path")
cmd.PersistentFlags().
String(_keyImport, "", "import configuration yaml file path")

cmds.Handle(func(root *cobra.Command) {
root.AddCommand(cmd)
})
}

func Run(bootstrapConfigPath string, importPath string) {
func Run(bootstrapConfigPath string) {
// print slogan
fmt.Printf("\033[92m%s\033[0m\n", slogan) // 92m: light green

discovery := boot.NewDiscovery(bootstrapConfigPath)
if err := discovery.Init(context.Background()); err != nil {
log.Fatal("start failed: %v", err)
return
}

if len(importPath) > 0 {
if !boot.RunImport(bootstrapConfigPath, importPath) {
return
}
}

if err := boot.Boot(context.Background(), discovery); err != nil {
log.Fatal("start failed: %v", err)
Expand Down Expand Up @@ -129,10 +114,7 @@ func Run(bootstrapConfigPath string, importPath string) {
func run(cmd *cobra.Command, args []string) {
_ = args

var (
bootstrapConfigPath, _ = cmd.PersistentFlags().GetString(_keyBootstrap)
importPath, _ = cmd.PersistentFlags().GetString(_keyImport)
)
bootstrapConfigPath, _ := cmd.PersistentFlags().GetString(_keyBootstrap)

if len(bootstrapConfigPath) < 1 {
// search bootstrap yaml
Expand All @@ -148,5 +130,5 @@ func run(cmd *cobra.Command, args []string) {
}
}

Run(bootstrapConfigPath, importPath)
Run(bootstrapConfigPath)
}
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ services:
arana:
container_name: arana
image: aranadb/arana:master
entrypoint: [ "arana", "start", "-c", "/etc/arana/bootstrap.yaml", "--import", "/etc/arana/config.yaml" ]
entrypoint: [ "sh", "-c", "arana import -c /etc/arana/bootstrap.yaml -s /etc/arana/config.yaml; arana start -c /etc/arana/bootstrap.yaml" ]
networks:
- local
ports:
Expand Down
2 changes: 1 addition & 1 deletion example/local_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ import (

func main() {
bootstrap := testdata.Path("../conf/bootstrap.local-etcd.yaml")
start.Run(bootstrap, "")
start.Run(bootstrap)
}
2 changes: 1 addition & 1 deletion pkg/boot/discovery_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RunImport(importConfPath, configPath string) bool {
tenant.Metadata = cfg.Metadata

ok := func() bool {
op, err := config.NewCenter(tenant.Name, config.GetStoreOperate())
op, err := config.NewCenter(tenant.Name, config.GetStoreOperate(), config.WithWriter(true))
if err != nil {
log.Errorf("create config_center tenant=%s failed: %+v", tenant.Name, err)
return false
Expand Down
2 changes: 1 addition & 1 deletion test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (ms *MySuite) SetupSuite() {
}
go func() {
_ = os.Setenv(constants.EnvConfigPath, ms.tmpFile)
start.Run(ms.tmpBootFile, "")
start.Run(ms.tmpBootFile)
}()

// waiting for arana server started
Expand Down

0 comments on commit df8d11c

Please sign in to comment.