Skip to content

Commit

Permalink
First pass at dockerFile for cadence server (cadence-workflow#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkat1109 authored May 26, 2017
1 parent 250f52f commit b1f7b8b
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cover_ci: cover_profile
goveralls -coverprofile=$(BUILD)/cover.out -service=travis-ci || echo -e "\x1b[31mCoveralls failed\x1b[m"; \

lint: vendor/glide.updated
@echo $(ALL_SRC)
@echo Running linter
@lintFail=0; for file in $(ALL_SRC); do \
golint "$$file"; \
if [ $$? -eq 1 ]; then lintFail=1; fi; \
Expand Down
3 changes: 3 additions & 0 deletions common/service/config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (c *Metrics) newM3Scope() tally.Scope {
// a default reporting interval of a second
func (c *Metrics) newStatsdScope() tally.Scope {
config := c.Statsd
if len(config.HostPort) == 0 {
return tally.NoopScope
}
statter, err := statsd.NewBufferedClient(config.HostPort, config.Prefix, config.FlushInterval, config.FlushBytes)
if err != nil {
log.Fatalf("error creating statsd client, err=%v", err)
Expand Down
68 changes: 68 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (c) 2017 Uber Technologies, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

FROM debian:jessie

# get golang 1.8.1
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
gcc \
libc6-dev \
make \
pkg-config \
libev4 libev-dev \
gettext-base \
wget \
python-pip \
git-all \
&& rm -rf /var/lib/apt/lists/*

RUN pip install cqlsh

ENV GOLANG_VERSION 1.8.2
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 5477d6c9a4f96fa120847fafa88319d7b56b5d5068e41c3587eebe248b939be7

RUN set -eux; \
wget -O golang.tar.gz "$GOLANG_DOWNLOAD_URL" \
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

# get and compile cadence-server
ENV CADENCE_HOME $GOPATH/src/github.com/uber/cadence

RUN go get -u github.com/Masterminds/glide
RUN go get -u github.com/golang/lint/golint
RUN git clone --depth=50 https://github.com/uber/cadence.git $CADENCE_HOME
RUN cd $CADENCE_HOME; make bins_nothrift

EXPOSE 7933 7934 7935

COPY ./start.sh $CADENCE_HOME/start.sh
COPY ./config_template.yaml $CADENCE_HOME/config/docker_template.yaml
RUN chmod a+x $CADENCE_HOME/start.sh

WORKDIR $CADENCE_HOME
CMD ./start.sh $CADENCE_HOME
54 changes: 54 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Quickstart
==========

Following steps will bring up the docker container running cadence server
along with all its dependencies (cassandra, statsd, graphite). Exposes cadence
frontend on port 7933 and grafana metrics frontend on port 8080.

```
cd $GOPATH/src/github.com/uber/cadence/docker
docker-compose up
```

View metrics at localhost:8080/dashboard

Building and running the image
==============================

Build
-----
```
cd $GOPATH/src/github.com/uber/cadence/docker
docker-compose build
```

Run with defaults
-----------------
```
docker-compose run cadence
```

Run with all the config options
-------------------------------
```
docker-compose run -e CASSANDRA_CONSISTENCY=Quorum \ -- Default cassandra consistency level
-e BIND_ON_LOCALHOST=false \ -- Don't use localhost ip address for cadence services
-e RINGPOP_SEEDS=10.0.0.1 \ -- Use this as the gossip bootstrap hosts for ringpop
-e NUM_HISTORY_SHARDS=1024 \ -- Number of history shards
-e SERVICES=history,matching \ -- Spinup only the provided services
cadence
```

Running cadence without dependencies
====================================
If you prefer to spin up your cassandra / statsd server, use the following
to just bring up cadence server
```
cd $GOPATH/src/github.com/uber/cadence/docker
docker build -t uber/cadence:master .
docker run uber/cadence
-e CASSANDRA_CONSISTENCY=Quorum \
-e CASSANDRA_SEEDS=127.0.0.1 \ -- Cassandra server seed list
-e RINGPOP_SEEDS=10.0.0.1 \ -- Use this as the gossip bootstrap hosts for ringpop
-e NUM_HISTORY_SHARDS=1024 \ -- Number of history shards
```
39 changes: 39 additions & 0 deletions docker/config_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cassandra:
hosts: "${CASSANDRA_SEEDS}"
keyspace: "${KEYSPACE}"
consistency: "${CASSANDRA_CONSISTENCY}"
numHistoryShards: ${NUM_HISTORY_SHARDS}

ringpop:
name: cadence
bootstrapMode: hosts
bootstrapHosts: ["${RINGPOP_SEEDS}"]
maxJoinDuration: 30s

services:
frontend:
tchannel:
port: 7933
bindOnLocalHost: ${BIND_ON_LOCALHOST}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence"

matching:
tchannel:
port: 7935
bindOnLocalHost: ${BIND_ON_LOCALHOST}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence"

history:
tchannel:
port: 7934
bindOnLocalHost: ${BIND_ON_LOCALHOST}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence"
26 changes: 26 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
cassandra:
image: cassandra:3.9
ports:
- "9042:9042"
statsd:
image: hopsoft/graphite-statsd
ports:
- "8080:80"
- "2003:2003"
- "8125:8125"
- "8126:8126"
cadence:
build: .
image: uber/cadence:master
ports:
- "7933:7933"
- "7934:7934"
- "7935:7935"
environment:
- "CASSANDRA_SEEDS=cassandra"
- "STATSD_ENDPOINT=statsd:8125"
depends_on:
- cassandra
- statsd
85 changes: 85 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash -x

# Copyright (c) 2017 Uber Technologies, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

setup_schema() {
SCHEMA_FILE=$CADENCE_HOME/schema/cadence/schema.cql
$CADENCE_HOME/cadence-cassandra-tool --ep $CASSANDRA_SEEDS create -k $KEYSPACE --rf $RF
$CADENCE_HOME/cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $KEYSPACE setup-schema -d -f $SCHEMA_FILE
}

wait_for_cassandra() {
server=`echo $CASSANDRA_SEEDS | awk -F ',' '{print $1}'`
until cqlsh --cqlversion=3.4.2 $server < /dev/null; do
echo 'waiting for cassandra to start up'
sleep 1
done
echo 'cassandra started'
}

init_env() {

export HOST_IP="127.0.0.1" # default to localhost binding

if [ "$BIND_ON_LOCALHOST" == false ]; then
export HOST_IP=`hostname --ip-address`
else
export BIND_ON_LOCALHOST=true
fi

if [ -z "$KEYSPACE" ]; then
export KEYSPACE="cadence"
fi

if [ -z "$CASSANDRA_SEEDS" ]; then
export CASSANDRA_SEEDS=$HOST_IP
fi

if [ -z "$CASSANDRA_CONSISTENCY" ]; then
export CASSANDRA_CONSISTENCY="One"
fi

if [ -z "$RINGPOP_SEEDS" ]; then
export RINGPOP_SEEDS=$HOST_IP:7933,$HOST_IP:7934,$HOST_IP:7935
fi

if [ -z "$NUM_HISTORY_SHARDS" ]; then
export NUM_HISTORY_SHARDS=4
fi
}

CADENCE_HOME=$1

if [ -z "$RF" ]; then
RF=1
fi

if [ -z "$SERVICES" ]; then
SERVICES="history,matching,frontend"
fi

init_env
wait_for_cassandra
setup_schema

# fix up config
envsubst < config/docker_template.yaml > config/docker.yaml
./cadence --root $CADENCE_HOME --env docker start --services=$SERVICES
4 changes: 2 additions & 2 deletions schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ How
Q: How do I update existing schema ?
* Add your changes to schema.cql
* Create a new schema version directory under ./schema/keyspace/versioned/vx.x
** Add a manifest.json
** Add your changes in a cql file
* Add a manifest.json
* Add your changes in a cql file
* Update the unit test within ./tools/cassandra/updateTask_test.go `TestDryrun` with your version x.x
* Once you are done with these use the ./cadence-cassandra-tool to update the schema

Expand Down
12 changes: 12 additions & 0 deletions tools/cassandra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ type (
DisableVersioning bool // do not use schema versioning
}

// CreateKeyspaceConfig holds the config
// params needed to create a cassandra
// keyspace
CreateKeyspaceConfig struct {
BaseConfig
ReplicationFactor int
}

// ConfigError is an error type that
// represents a problem with the config
ConfigError struct {
Expand All @@ -70,6 +78,8 @@ const (
cliOptTargetVersion = "version"
cliOptDryrun = "dryrun"
cliOptSchemaDir = "schema-dir"
cliOptReplicationFactor = "replication-factor"
cliOptQuiet = "quiet"

cliFlagEndpoint = cliOptEndpoint + ", ep"
cliFlagKeyspace = cliOptKeyspace + ", k"
Expand All @@ -80,6 +90,8 @@ const (
cliFlagTargetVersion = cliOptTargetVersion + ", v"
cliFlagDryrun = cliOptDryrun + ", y"
cliFlagSchemaDir = cliOptSchemaDir + ", d"
cliFlagReplicationFactor = cliOptReplicationFactor + ", rf"
cliFlagQuiet = cliOptQuiet + ", q"
)

var rmspaceRegex = regexp.MustCompile("\\s+")
Expand Down
Loading

0 comments on commit b1f7b8b

Please sign in to comment.