Skip to content

Commit

Permalink
Expose server version tag to be set during build time
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Apr 7, 2021
1 parent f50a0fe commit 3a1e1bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/server/cadence/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ func constructPathIfNeed(dir string, file string) string {
}

// BuildCLI is the main entry point for the cadence server
func BuildCLI() *cli.App {
func BuildCLI(version string, revision string) *cli.App {

app := cli.NewApp()
app.Name = "cadence"
app.Usage = "Cadence server"
app.Version = "0.0.1"
app.Version = version + "-" + revision

app.Flags = []cli.Flag{
cli.StringFlag{
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
"os"

"github.com/uber/cadence/cmd/server/cadence"
"github.com/uber/cadence/common/metrics"
_ "github.com/uber/cadence/common/persistence/sql/sqlplugin/mysql" // needed to load mysql plugin
_ "github.com/uber/cadence/common/persistence/sql/sqlplugin/postgres" // needed to load postgres plugin
)

// main entry point for the cadence server
func main() {
app := cadence.BuildCLI()
app := cadence.BuildCLI(metrics.Version, metrics.Revision)
app.Run(os.Args)
}
9 changes: 8 additions & 1 deletion scripts/go-build-ldflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ fi

export GIT_REVISION=$(git rev-parse --short HEAD)
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
export GIT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo unknown)
export BUILD_DATE=$(date '+%F-%T') # outputs something in this format 2017-08-21-18:58:45
export BUILD_TS_UNIX=$(date '+%s') # second since epoch
export BASE_PACKAGE=github.com/uber/cadence/common/metrics
if [ -z ${SERVER_VERSION} ]; then
# If not set SERVER_VERSION, then use the most recent tag.
export GIT_VERSION=$(git describe --tags --abbrev=0 --dirty 2>/dev/null || echo unknown)
else
# If passing a version explicitly, then use it
export GIT_VERSION=${SERVER_VERSION}
fi


if [ "$MODE" = "LDFLAG" ]; then
LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \
Expand Down

0 comments on commit 3a1e1bc

Please sign in to comment.