Browse Source

try to add version

pull/58/head v1.5.4
yedf2 4 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"
)
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()

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

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

3
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/

Loading…
Cancel
Save