Browse Source

try to add version

pull/58/head v1.5.4
yedf2 5 years ago
parent
commit
e52d303d99
  1. 7
      app/main.go
  2. 4
      common/types.go
  3. 2
      helper/.goreleaser.yml
  4. 3
      helper/Dockerfile-release

7
app/main.go

@ -13,12 +13,15 @@ import (
"github.com/yedf/dtm/examples" "github.com/yedf/dtm/examples"
) )
var Version, Commit, Date string
var usage = `dtm is a lightweight distributed transaction manager. var usage = `dtm is a lightweight distributed transaction manager.
usage: usage:
dtm [command] dtm [command]
Available commands: Available commands:
version print dtm version
dtmsvr run dtm as a server dtmsvr run dtm as a server
dev create all needed table and run dtm as a server dev create all needed table and run dtm as a server
bench start bench server bench start bench server
@ -35,6 +38,10 @@ func main() {
} }
return 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"]) dtmcli.SetCurrentDBType(common.DtmConfig.DB["driver"])
if os.Args[1] != "dtmsvr" { // 实际线上运行,只启动dtmsvr,不准备table相关的数据 if os.Args[1] != "dtmsvr" { // 实际线上运行,只启动dtmsvr,不准备table相关的数据
common.WaitDBUp() common.WaitDBUp()

4
common/types.go

@ -140,7 +140,7 @@ func getIntEnv(key string, defaultV string) int64 {
} }
func init() { func init() {
if len(os.Args) == 1 { if len(os.Args) == 1 || os.Args[1] == "version" {
return return
} }
DtmConfig.TransCronInterval = getIntEnv("TRANS_CRON_INTERVAL", "3") DtmConfig.TransCronInterval = getIntEnv("TRANS_CRON_INTERVAL", "3")
@ -167,7 +167,7 @@ func init() {
} }
} }
if len(cont) != 0 { 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) err := yaml.Unmarshal(cont, &DtmConfig)
dtmimp.FatalIfError(err) dtmimp.FatalIfError(err)
} }

2
helper/.goreleaser.yml

@ -11,3 +11,5 @@ builds:
id: 'dtm' id: 'dtm'
dir: . dir: .
main: ./app/main.go main: ./app/main.go
ldflags:
- -s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.Date={{.Date}}

3
helper/Dockerfile-release

@ -3,8 +3,7 @@ WORKDIR /app/dtm
# RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct # RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
EXPOSE 8080 EXPOSE 8080
COPY . . COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" app/main.go RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" app/main.go && apk add upx && upx main
RUN apk add upx && upx main
FROM alpine:3.14 as runner FROM alpine:3.14 as runner
COPY --from=builder /app/dtm/main /app/dtm/ COPY --from=builder /app/dtm/main /app/dtm/

Loading…
Cancel
Save