Browse Source

fix sql dir

pull/110/head v1.7.1
yedf2 4 years ago
parent
commit
ec5c583830
  1. 4
      app/main.go
  2. 13
      common/config.go
  3. 4
      common/utils.go
  4. 2
      common/utils_test.go
  5. 1
      helper/Dockerfile-release

4
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)

13
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.

4
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) {

2
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"))
}

1
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"]

Loading…
Cancel
Save