Skip to content

Commit

Permalink
Added docker support for mysql (uber#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgohite authored and venkat1109 committed Mar 12, 2019
1 parent d181c67 commit 4257916
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 40 deletions.
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
tcpdump \
netcat \
python-pip \
mysql-client \
&& rm -rf /var/lib/apt/lists/*

RUN pip install cqlsh
Expand All @@ -54,7 +55,8 @@ ENV CADENCE_HOME /cadence
EXPOSE 7933 7934 7935 7939

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

COPY --from=builder /go/src/github.com/uber/cadence/cadence-cassandra-tool /cadence
Expand Down
12 changes: 12 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ docker-compose down
docker-compose up
```

Running cadence service with MySQL
-----------------------------------------

Run cadence with MySQL instead of cassandra, use following commads:

```
docker-compose -f docker-compose-mysql.yml up
docker-compose -f docker-compose-mysql.yml down
```

Please note that SQL support is still in active developement and it is not production ready yet.

Quickstart for production
=========================
In a typical production setting, dependencies (cassandra / statsd server) are
Expand Down
100 changes: 100 additions & 0 deletions docker/config_template_mysql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
log:
stdout: true
level: "${LOG_LEVEL}"

persistence:
defaultStore: mysql-default
visibilityStore: mysql-visibility
numHistoryShards: ${NUM_HISTORY_SHARDS}
datastores:
mysql-default:
sql:
driverName: "mysql"
databaseName: "${DBNAME}"
connectAddr: "${MYSQL_SEEDS}:3306"
connectProtocol: "tcp"
user: "${MYSQL_USER}"
password: "${MYSQL_PWD}"
mysql-visibility:
sql:
driverName: "mysql"
databaseName: "${VISIBILITY_DBNAME}"
connectAddr: "${MYSQL_SEEDS}:3306"
connectProtocol: "tcp"
user: "${MYSQL_USER}"
password: "${MYSQL_PWD}"

ringpop:
name: cadence
bootstrapMode: hosts
bootstrapHosts: ${RINGPOP_SEEDS_JSON_ARRAY}
maxJoinDuration: 30s

services:
frontend:
rpc:
port: 7933
bindOnIP: ${BIND_ON_IP}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence-frontend"

matching:
rpc:
port: 7935
bindOnIP: ${BIND_ON_IP}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence-matching"

history:
rpc:
port: 7934
bindOnIP: ${BIND_ON_IP}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence-history"

worker:
rpc:
port: 7939
bindOnIP: ${BIND_ON_IP}
metrics:
statsd:
hostPort: "${STATSD_ENDPOINT}"
prefix: "cadence-worker"

clustersInfo:
enableGlobalDomain: false
failoverVersionIncrement: 10
masterClusterName: "active"
currentClusterName: "active"
clusterInitialFailoverVersion:
active: 0
clusterAddress:
active:
rpcName: "cadence-frontend"
rpcAddress: "127.0.0.1:7933"

dcRedirectionPolicy:
policy: "noop"
toDC: ""

archival:
status: enabled
blobstore:
storeDirectory: "/tmp/blobstore/"
defaultBucket:
name: "cadence-development"
owner: "cadence"
retentionDays: 10
customBuckets:
- name: "custom-bucket-1"
owner: "custom-owner-1"
retentionDays: 10
- name: "custom-bucket-2"
owner: "custom-owner-2"
retentionDays: 5
39 changes: 39 additions & 0 deletions docker/docker-compose-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3'
services:
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
- "MYSQL_ROOT_PASSWORD=root"
statsd:
image: hopsoft/graphite-statsd
ports:
- "8080:80"
- "2003:2003"
- "8125:8125"
- "8126:8126"
cadence:
image: ubercadence/server:0.5.4
ports:
- "7933:7933"
- "7934:7934"
- "7935:7935"
- "7939:7939"
environment:
- "DB=mysql"
- "MYSQL_USER=root"
- "MYSQL_PWD=root"
- "MYSQL_SEEDS=mysql"
- "STATSD_ENDPOINT=statsd:8125"
depends_on:
- mysql
- statsd
cadence-web:
image: ubercadence/web:3.1.2
environment:
- "CADENCE_TCHANNEL_PEERS=cadence:7933"
ports:
- "8088:8088"
depends_on:
- cadence
96 changes: 57 additions & 39 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

setup_schema() {
CADENCE_HOME=$1
DB="${DB:-cassandra}"
CFG_TEMPLATE=docker_template_$DB.yaml
SERVICES="${SERVICES:-history,matching,frontend,worker}"
RF=${RF:-1}
export LOG_LEVEL="${LOG_LEVEL:-info}"
export NUM_HISTORY_SHARDS=${NUM_HISTORY_SHARDS:-4}

# cassandra env
export KEYSPACE="${KEYSPACE:-cadence}"
export VISIBILITY_KEYSPACE="${VISIBILITY_KEYSPACE:-cadence_visibility}"
export CASSANDRA_CONSISTENCY="${CASSANDRA_CONSISTENCY:-One}"

#mysql env
export DBNAME="${DBNAME:-cadence}"
export VISIBILITY_DBNAME="${VISIBILITY_DBNAME:-cadence_visibility}"
export DB_PORT=${DB_PORT:-3306}


setup_cassandra_schema() {
SCHEMA_DIR=$CADENCE_HOME/schema/cassandra/cadence/versioned
$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 -v 0.0
Expand All @@ -31,6 +50,21 @@ setup_schema() {
$CADENCE_HOME/cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $VISIBILITY_KEYSPACE update-schema -d $VISIBILITY_SCHEMA_DIR
}

setup_mysql_schema() {
mysql -h $MYSQL_SEEDS -u$MYSQL_USER -p$MYSQL_PWD < $CADENCE_HOME/schema/mysql/v57/cadence/database.sql
mysql -h $MYSQL_SEEDS -u$MYSQL_USER -p$MYSQL_PWD $DBNAME < $CADENCE_HOME/schema/mysql/v57/cadence/schema.sql
mysql -h $MYSQL_SEEDS -u$MYSQL_USER -p$MYSQL_PWD < $CADENCE_HOME/schema/mysql/v57/visibility/database.sql
mysql -h $MYSQL_SEEDS -u$MYSQL_USER -p$MYSQL_PWD $VISIBILITY_DBNAME < $CADENCE_HOME/schema/mysql/v57/visibility/schema.sql
}

setup_schema() {
if [ "$DB" == "mysql" ]; then
setup_mysql_schema
else
setup_cassandra_schema
fi
}

wait_for_cassandra() {
server=`echo $CASSANDRA_SEEDS | awk -F ',' '{print $1}'`
until cqlsh --cqlversion=3.4.4 $server < /dev/null; do
Expand All @@ -40,6 +74,26 @@ wait_for_cassandra() {
echo 'cassandra started'
}

wait_for_mysql() {
server=`echo $MYSQL_SEEDS | awk -F ',' '{print $1}'`
nc -z $server $DB_PORT < /dev/null
until [ $? -eq 0 ]; do
echo 'waiting for mysql to start up'
sleep 1
nc -z $server $DB_PORT < /dev/null
done
echo 'mysql started'
}

wait_for_db() {
if [ "$DB" == "mysql" ]; then
wait_for_mysql
else
wait_for_cassandra
fi
}


json_array() {
echo -n '['
while [ $# -gt 0 ]; do
Expand All @@ -52,7 +106,6 @@ json_array() {
}

init_env() {

export HOST_IP=`hostname --ip-address`

if [ "$BIND_ON_LOCALHOST" == true ] || [ "$BIND_ON_IP" == "127.0.0.1" ]; then
Expand All @@ -69,55 +122,20 @@ init_env() {
// this env variable is deprecated
export BIND_ON_LOCALHOST=false

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

if [ -z "$VISIBILITY_KEYSPACE" ]; then
export VISIBILITY_KEYSPACE="cadence_visibility"
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_JSON_ARRAY="[\"$HOST_IP:7933\",\"$HOST_IP:7934\",\"$HOST_IP:7935\",\"$HOST_IP:7939\"]"
else
array=(${RINGPOP_SEEDS//,/ })
export RINGPOP_SEEDS_JSON_ARRAY=$(json_array "${array[@]}")
fi

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

if [ -z "$LOG_LEVEL" ]; then
export LOG_LEVEL="info"
fi
}

CADENCE_HOME=$1

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

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

init_env
wait_for_cassandra

wait_for_db
if [ "$SKIP_SCHEMA_SETUP" != true ]; then
setup_schema
fi

# fix up config
envsubst < config/docker_template.yaml > config/docker.yaml
envsubst < config/$CFG_TEMPLATE > config/docker.yaml
./cadence-server --root $CADENCE_HOME --env docker start --services=$SERVICES

0 comments on commit 4257916

Please sign in to comment.