diff --git a/app/main.go b/app/main.go index 1fa99bd..8f3f949 100644 --- a/app/main.go +++ b/app/main.go @@ -13,12 +13,15 @@ import ( "github.com/yedf/dtm/examples" ) +var Version, Commit, Date string + var usage = `dtm is a lightweight distributed transaction manager. usage: dtm [command] Available commands: + version print dtm version dtmsvr run dtm as a server dev create all needed table and run dtm as a server bench start bench server @@ -35,6 +38,10 @@ func main() { } return } + if os.Args[1] == "version" { + fmt.Printf("version: %s commit: %s built at: %s\n", Version, Commit, Date) + return + } dtmcli.SetCurrentDBType(common.DtmConfig.DB["driver"]) if os.Args[1] != "dtmsvr" { // 实际线上运行,只启动dtmsvr,不准备table相关的数据 common.WaitDBUp() diff --git a/common/types.go b/common/types.go index 4be83a3..d07c27d 100644 --- a/common/types.go +++ b/common/types.go @@ -140,7 +140,7 @@ func getIntEnv(key string, defaultV string) int64 { } func init() { - if len(os.Args) == 1 { + if len(os.Args) == 1 || os.Args[1] == "version" { return } DtmConfig.TransCronInterval = getIntEnv("TRANS_CRON_INTERVAL", "3") @@ -167,7 +167,7 @@ func init() { } } if len(cont) != 0 { - dtmimp.Logf("cont is: \n%s", string(cont)) + dtmimp.Logf("config is: \n%s", string(cont)) err := yaml.Unmarshal(cont, &DtmConfig) dtmimp.FatalIfError(err) } diff --git a/helper/.goreleaser.yml b/helper/.goreleaser.yml index 4e96e44..39ca3ad 100644 --- a/helper/.goreleaser.yml +++ b/helper/.goreleaser.yml @@ -11,3 +11,5 @@ builds: id: 'dtm' dir: . main: ./app/main.go + ldflags: + - -s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.Date={{.Date}} diff --git a/helper/Dockerfile-release b/helper/Dockerfile-release index 6a0db95..db911a7 100644 --- a/helper/Dockerfile-release +++ b/helper/Dockerfile-release @@ -3,8 +3,7 @@ WORKDIR /app/dtm # RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct EXPOSE 8080 COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" app/main.go -RUN apk add upx && upx main +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" app/main.go && apk add upx && upx main FROM alpine:3.14 as runner COPY --from=builder /app/dtm/main /app/dtm/