Skip to content

Commit

Permalink
Server and CLI use version from release and versionChecking constant …
Browse files Browse the repository at this point in the history
…and commit revision (#4308)
  • Loading branch information
longquanzheng authored Jul 31, 2021
1 parent cd9a33a commit 28e0489
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 42 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN go build -mod=readonly -o /go/bin/tcheck github.com/uber/tcheck
# Build Cadence binaries
FROM golang:1.13.6-alpine AS builder

ARG RELEASE_VERSION

RUN apk add --update --no-cache ca-certificates make git curl mercurial bzr unzip

WORKDIR /cadence
Expand All @@ -28,6 +30,8 @@ RUN go mod download
COPY . .
RUN rm -fr .bin .build

ENV CADENCE_RELEASE_VERSION=$RELEASE_VERSION

# bypass codegen, use committed files. must be run separately, before building things.
RUN make .fake-codegen
RUN CGO_ENABLED=0 make copyright cadence-cassandra-tool cadence-sql-tool cadence cadence-server
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ BINS += cadence
TOOLS += cadence
cadence: $(BUILD)/lint
@echo "compiling cadence with OS: $(GOOS), ARCH: $(GOARCH)"
@go build -o $@ cmd/tools/cli/main.go
@go build -ldflags '$(GO_BUILD_LDFLAGS)' -o $@ cmd/tools/cli/main.go

BINS += cadence-server
cadence-server: $(BUILD)/lint
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Other clients are developed by community:

* Use [Cadence command-line tool](https://cadenceworkflow.io/docs/cli/) to perform various tasks on Cadence server cluster
* Use brew to install CLI: `brew install cadence-workflow`
* Use docker image for CLI: `docker run --rm ubercadence/cli:master `. Be sure to update your image when you want to try new features: `docker pull ubercadence/cli:master `
* Use docker image for CLI: `docker run --rm ubercadence/cli:<releaseVersion>` or `docker run --rm ubercadence/cli:master ` . Be sure to update your image when you want to try new features: `docker pull ubercadence/cli:master `
* Build the CLI image, see [instructions](docker/README.md#diy-building-an-image-for-any-tag-or-branch)
* Check out the repo and run `make cadence` to build all tools. See [CONTRIBUTING](CONTRIBUTING.md) for prerequisite of make command.


Expand Down
13 changes: 11 additions & 2 deletions cmd/server/cadence/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package cadence

import (
"fmt"
"log"
"os"
"os/signal"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/urfave/cli"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/tools/cassandra"
"github.com/uber/cadence/tools/sql"
Expand Down Expand Up @@ -158,12 +160,19 @@ func constructPathIfNeed(dir string, file string) string {
}

// BuildCLI is the main entry point for the cadence server
func BuildCLI(version string, revision string) *cli.App {
func BuildCLI(releaseVersion string, gitRevision string) *cli.App {
version := fmt.Sprintf(" Release version: %v \n"+
" Build commit: %v\n"+
" Max Support CLI feature version: %v \n"+
" Max Support GoSDK feature version: %v \n"+
" Max Support JavaSDK feature version: %v \n"+
" Note: Feature version is for compatibility checking between server and clients if enabled feature checking. Server is always backward compatible to older CLI versions, but not accepting newer than it can support.",
releaseVersion, gitRevision, client.SupportedCLIVersion, client.SupportedGoSDKVersion, client.SupportedJavaSDKVersion)

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

app.Flags = []cli.Flag{
cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ import (

// main entry point for the cadence server
func main() {
app := cadence.BuildCLI(metrics.Version, metrics.Revision)
app := cadence.BuildCLI(metrics.ReleaseVersion, metrics.Revision)
app.Run(os.Args)
}
21 changes: 10 additions & 11 deletions common/authorization/oauthAutorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ import (
type (
oauthSuite struct {
suite.Suite
logger *log.MockLogger
cfg config.OAuthAuthorizer
att Attributes
token string
controller *gomock.Controller
domainCache *cache.MockDomainCache
ctx context.Context
domainEntry *cache.DomainCacheEntry
logger *log.MockLogger
cfg config.OAuthAuthorizer
att Attributes
token string
controller *gomock.Controller
domainCache *cache.MockDomainCache
ctx context.Context
domainEntry *cache.DomainCacheEntry
}
)

Expand Down Expand Up @@ -88,12 +88,11 @@ func (s *oauthSuite) SetupTest() {

s.domainEntry = cache.NewGlobalDomainCacheEntryForTest(
&persistence.DomainInfo{
ID: "test-domain-id",
ID: "test-domain-id",
Name: "test-domain",
Data: map[string]string{
common.DomainDataKeyForReadGroups: "c",
},

},
&persistence.DomainConfig{Retention: 1},
&persistence.DomainReplicationConfig{
Expand Down Expand Up @@ -227,4 +226,4 @@ func (s *oauthSuite) TestIncorrectPermission() {
}))
result, _ := authorizer.Authorize(s.ctx, &s.att)
s.Equal(result.Decision, DecisionDeny)
}
}
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ const StickyTaskConditionFailedErrorMsg = "StickyTaskConditionFailedError"
const MemoKeyForOperator = "operator"

// ReservedTaskListPrefix is the required naming prefix for any task list partition other than partition 0
const ReservedTaskListPrefix = "/__cadence_sys/"
const ReservedTaskListPrefix = "/__cadence_sys/"
8 changes: 4 additions & 4 deletions common/metrics/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ var (
// Revision is the VCS revision associated with this build. Overridden using ldflags
// at compile time. Example:
// $ go build -ldflags "-X github.com/uber/cadence/common/metrics.Revision=abcdef" ...
// Adapted from: https://www.atatus.com/blog/golang-auto-build-versioning/
// see go-build-ldflags.sh for GIT_REVISION
Revision = "unknown"

// Branch is the VCS branch associated with this build.
Branch = "unknown"

// Version is the version associated with this build.
Version = "unknown"
// ReleaseVersion is the version associated with this build.
ReleaseVersion = "unknown"

// BuildDate is the date this build was created.
BuildDate = "unknown"
Expand Down Expand Up @@ -102,7 +102,7 @@ func NewRuntimeMetricsReporter(
revisionTag: Revision,
branchTag: Branch,
buildDateTag: BuildDate,
buildVersionTag: Version,
buildVersionTag: ReleaseVersion,
goVersionTag: goVersion,
},
)
Expand Down
22 changes: 14 additions & 8 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,24 @@ cd docker
docker-compose up
```

DIY: Building an image for any branch and restarting
DIY: Building an image for any tag or branch
-----------------------------------------
Replace **YOUR_TAG** and **YOUR_CHECKOUT_BRANCH** in the below command to build:
Replace **YOUR_TAG** and **YOUR_CHECKOUT_BRANCH_OR_TAG** in the below command to build:
You can checkout a [release tag](https://github.com/uber/cadence/tags) (e.g. v0.21.3) or any branch you are interested.

```
cd $GOPATH/src/github.com/uber/cadence
git checkout YOUR_CHECKOUT_BRANCH
docker build . -t ubercadence/server:YOUR_TAG
git checkout YOUR_CHECKOUT_BRANCH_OR_TAG
docker build . -t ubercadence/<imageName>:YOUR_TAG
```
Or for auto-setup images:

You can specify `--build-arg TARGET=<target>` to build different binaries.
There are three targets supported:
* server. Default target if not specified. This will build a regular server binary.
* auto-setup. The image will setup all the DB/ElasticSearch schema during startup.
* cli. This image is for [CLI](https://cadenceworkflow.io/docs/cli/).

For example of auto-setup images:
```
cd $GOPATH/src/github.com/uber/cadence
git checkout YOUR_CHECKOUT_BRANCH
Expand All @@ -88,9 +97,6 @@ docker-compose down
docker-compose up
```

Note that with `TARGET=auto-setup`, the images will setup all the DB/ElasticSearch schema during startup.
By default, the image will not setup schema if you leave TARGET empty.

Using docker image for production
=========================
In a typical production setting, dependencies (cassandra / statsd server) are
Expand Down
15 changes: 8 additions & 7 deletions scripts/go-build-ldflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ if [ "$MODE" != "LDFLAG" ] && [ "$MODE" != "ECHO" ]; then
exit 1
fi

export GIT_REVISION=$(git rev-parse --short HEAD)
# $(git rev-parse --short HEAD) \"$(git log -1 --format=%cI-%h)\"
export GIT_REVISION=$(git log -1 --format=%cI-%h) # use commit date time and hash: e.g. 2021-07-27 19:36:53 -0700-40c5f1896, doc: https://git-scm.com/docs/pretty-formats
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
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)
if [ -z ${CADENCE_RELEASE_VERSION} ]; then
# If not set CADENCE_RELEASE_VERSION, then use the most recent tag.
export RELEASE_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}
# If passing a CADENCE_RELEASE_VERSION explicitly, then use it
export RELEASE_VERSION=${CADENCE_RELEASE_VERSION}
fi


if [ "$MODE" = "LDFLAG" ]; then
LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \
-X ${BASE_PACKAGE}.Branch=${GIT_BRANCH} \
-X ${BASE_PACKAGE}.Version=${GIT_VERSION} \
-X ${BASE_PACKAGE}.ReleaseVersion=${RELEASE_VERSION} \
-X ${BASE_PACKAGE}.BuildDate=${BUILD_DATE} \
-X ${BASE_PACKAGE}.BuildTimeUnix=${BUILD_TS_UNIX}"

Expand Down
17 changes: 11 additions & 6 deletions tools/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
package cli

import (
"fmt"

"github.com/urfave/cli"
)

const (
// Version is the controlled version string. It should be updated every time
// before we release a new version.
Version = "0.19.0"
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/metrics"
)

// SetFactory is used to set the ClientFactory global
Expand All @@ -37,10 +36,16 @@ func SetFactory(factory ClientFactory) {

// NewCliApp instantiates a new instance of the CLI application.
func NewCliApp() *cli.App {
version := fmt.Sprintf("CLI feature version: %v \n"+
" Release version: %v\n"+
" Build commit: %v\n"+
" Note: CLI feature version is for compatibility checking between server and CLI if enabled feature checking. Server is always backward compatible to older CLI versions, but not accepting newer than it can support.",
client.SupportedCLIVersion, metrics.ReleaseVersion, metrics.Revision)

app := cli.NewApp()
app.Name = "cadence"
app.Usage = "A command-line tool for cadence users"
app.Version = Version
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: FlagAddressWithAlias,
Expand Down

0 comments on commit 28e0489

Please sign in to comment.