From ec5c583830977af803bdaba5bc76ea08658cd275 Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Mon, 20 Dec 2021 19:48:07 +0800 Subject: [PATCH] fix sql dir --- app/main.go | 4 +++- common/config.go | 13 ++++++++----- common/utils.go | 4 ++-- common/utils_test.go | 2 +- helper/Dockerfile-release | 1 - 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/main.go b/app/main.go index fb97b4b..8a63fdf 100644 --- a/app/main.go +++ b/app/main.go @@ -52,7 +52,9 @@ func main() { } dtmimp.Logf("starting dtm....") common.MustLoadConfig() - dtmcli.SetCurrentDBType(common.Config.ExamplesDB.Driver) + if common.Config.ExamplesDB.Driver != "" { + dtmcli.SetCurrentDBType(common.Config.ExamplesDB.Driver) + } if os.Args[1] != "dtmsvr" { // 实际线上运行,只启动dtmsvr,不准备table相关的数据 storage.WaitStoreUp() dtmsvr.PopulateDB(true) diff --git a/common/config.go b/common/config.go index 4a7f180..cd6de2d 100644 --- a/common/config.go +++ b/common/config.go @@ -1,6 +1,7 @@ package common import ( + "encoding/json" "errors" "io/ioutil" "path/filepath" @@ -12,9 +13,9 @@ import ( const ( DtmMetricsPort = 8889 - Mysql = "mysql" - Redis = "redis" - BoltDb = "boltdb" + Mysql = "mysql" + Redis = "redis" + BoltDb = "boltdb" ) // MicroService config type for micro service @@ -80,11 +81,13 @@ func MustLoadConfig() { } } if len(cont) != 0 { - dtmimp.Logf("config is: \n%s", string(cont)) err := yaml.UnmarshalStrict(cont, &Config) dtmimp.FatalIfError(err) } - err := checkConfig() + scont, err := json.MarshalIndent(&Config, "", " ") + dtmimp.FatalIfError(err) + dtmimp.Logf("config is: \n%s", scont) + err = checkConfig() dtmimp.LogIfFatalf(err != nil, `config error: '%v'. check you env, and conf.yml/conf.sample.yml in current and parent path: %s. please visit http://d.dtm.pub to see the config document. diff --git a/common/utils.go b/common/utils.go index 2992625..9465a6c 100644 --- a/common/utils.go +++ b/common/utils.go @@ -83,9 +83,9 @@ func MustGetwd() string { func GetSqlDir() string { wd := MustGetwd() if filepath.Base(wd) == "test" { - wd = filepath.Dir(wd) + "/sqls" + wd = filepath.Dir(wd) } - return wd + return wd + "/sqls" } func RecoverPanic(err *error) { diff --git a/common/utils_test.go b/common/utils_test.go index 228ee8f..303a8ab 100644 --- a/common/utils_test.go +++ b/common/utils_test.go @@ -43,7 +43,7 @@ func TestFuncs(t *testing.T) { assert.NotEqual(t, "", wd) dir1 := GetSqlDir() - assert.Equal(t, true, strings.HasSuffix(dir1, "common")) + assert.Equal(t, true, strings.HasSuffix(dir1, "/sqls")) } diff --git a/helper/Dockerfile-release b/helper/Dockerfile-release index 7d83ed6..b922185 100644 --- a/helper/Dockerfile-release +++ b/helper/Dockerfile-release @@ -10,7 +10,6 @@ RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" ap FROM --platform=$TARGETPLATFORM alpine:3.14 COPY --from=builder /app/dtm/main /app/dtm/ -COPY --from=builder /app/dtm/sqls/*.sql /app/dtm/sqls/ ENV IS_DOCKER=1 WORKDIR /app/dtm CMD ["/app/dtm/main", "dtmsvr"]