Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Postgres configuration in docker configs #2894

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be SQL_* to match the env vars in the SQL tool?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. We use POSTGRES_SEEDS in https://github.com/uber/cadence/blob/master/environment/env.go#L62

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