Skip to content

Commit

Permalink
Add Postgres configuration in docker configs (uber#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
enmand authored and longquanzheng committed Dec 9, 2019
1 parent cba849d commit ccdf53d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
27 changes: 25 additions & 2 deletions docker/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ persistence:
{{- else if eq $db "mysql" }}
default:
sql:
driverName: "mysql"
pluginName: "mysql"
databaseName: {{ default .Env.DBNAME "cadence" }}
connectAddr: "{{ default .Env.MYSQL_SEEDS "" }}:{{ default .Env.DB_PORT "3306" }}"
connectProtocol: "tcp"
Expand All @@ -38,7 +38,7 @@ persistence:
{{- end }}
visibility:
sql:
driverName: "mysql"
pluginName: "mysql"
databaseName: {{ default .Env.VISIBILITY_DBNAME "cadence_visibility" }}
connectAddr: "{{ default .Env.MYSQL_SEEDS "" }}:{{ default .Env.DB_PORT "3306" }}"
connectProtocol: "tcp"
Expand All @@ -48,6 +48,29 @@ persistence:
connectAttributes:
tx_isolation: 'READ-COMMITTED'
{{- end }}
{{- else if eq $db "postgres" }}
default:
sql:
pluginName: "postgres"
databaseName: {{ default .Env.DBNAME "cadence" }}
connectAddr: "{{ default .Env.POSTGRES_SEEDS "" }}:{{ default .Env.DB_PORT "5432" }}"
connectProtocol: "tcp"
user: {{ default .Env.POSTGRES_USER "" }}
password: {{ default .Env.POSTGRES_PWD "" }}
maxConns: 20
maxIdleConns: 20
maxConnLifetime: "1h"
visibility:
sql:
pluginName: "postgres"
databaseName: {{ default .Env.VISIBILITY_DBNAME "cadence_visibility" }}
connectAddr: "{{ default .Env.POSTGRES_SEEDS "" }}:{{ default .Env.DB_PORT "5432" }}"
connectProtocol: "tcp"
user: {{ default .Env.POSTGRES_USER "" }}
password: {{ default .Env.POSTGRES_PWD "" }}
maxConns: 20
maxIdleConns: 20
maxConnLifetime: "1h"
{{- end }}
{{- if eq $es "true" }}
es-visibility:
Expand Down
29 changes: 29 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ setup_mysql_schema() {
cadence-sql-tool --ep $MYSQL_SEEDS -u $MYSQL_USER --pw $MYSQL_PWD --db $VISIBILITY_DBNAME update-schema -d $VISIBILITY_SCHEMA_DIR
}

setup_postgres_schema() {
SCHEMA_DIR=$CADENCE_HOME/schema/postgres/cadence/versioned
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT create --db $DBNAME
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT --db $DBNAME setup-schema -v 0.0
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT --db $DBNAME update-schema -d $SCHEMA_DIR
VISIBILITY_SCHEMA_DIR=$CADENCE_HOME/schema/postgres/visibility/versioned
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT create --db $VISIBILITY_DBNAME
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT --db $VISIBILITY_DBNAME setup-schema -v 0.0
cadence-sql-tool --plugin postgres --ep $POSTGRES_SEEDS -u $POSTGRES_USER --pw $POSTGRES_PWD -p $DB_PORT --db $VISIBILITY_DBNAME update-schema -d $VISIBILITY_SCHEMA_DIR
}


setup_es_template() {
SCHEMA_FILE=$CADENCE_HOME/schema/elasticsearch/visibility/index_template.json
server=`echo $ES_SEEDS | awk -F ',' '{print $1}'`
Expand All @@ -51,6 +63,9 @@ setup_schema() {
if [ "$DB" == "mysql" ]; then
echo 'setup mysql schema'
setup_mysql_schema
elif [ "$DB" == "postgres" ]; then
echo 'setup postgres schema'
setup_postgres_schema
else
echo 'setup cassandra schema'
setup_cassandra_schema
Expand Down Expand Up @@ -81,6 +96,18 @@ wait_for_mysql() {
echo 'mysql started'
}

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


wait_for_es() {
server=`echo $ES_SEEDS | awk -F ',' '{print $1}'`
URL="http://$server:$ES_PORT"
Expand All @@ -96,6 +123,8 @@ wait_for_es() {
wait_for_db() {
if [ "$DB" == "mysql" ]; then
wait_for_mysql
elif [ "$DB" == "postgres" ]; then
wait_for_postgres
else
wait_for_cassandra
fi
Expand Down

0 comments on commit ccdf53d

Please sign in to comment.