-
Notifications
You must be signed in to change notification settings - Fork 19
/
sync-jupyter-db.sh
executable file
·39 lines (30 loc) · 1.2 KB
/
sync-jupyter-db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Run this locally or on CI/CD to set jupyter VCAP variables on Cloud Foundry.
#
# Note: this is only part of setting up a new instance of Jupyter.
# See maintenance_or_infrequent_tasks.md for more details.
if ! command -v jq &> /dev/null; then
>&2 echo 'Please install jq to continue (https://github.com/jqlang/jq)'
exit 127
fi
. env-helpers.sh crt-portal-django
function get_db_config() {
cf_get_multiline_env VCAP_SERVICES \
| jq '.["aws-rds"][0]["credentials"]'
}
function cf_set_env() {
cf set-env "crt-portal-jupyter" "$1" "$2" 1>/dev/null
}
portal_services="$(get_db_config)"
db_name="$(echo "$portal_services" | jq -r '.["db_name"]')"
db_host="$(echo "$portal_services" | jq -r '.["host"]')"
db_port="$(echo "$portal_services" | jq -r '.["port"]')"
db_user="$(cf_get_env POSTGRES_ANALYTICS_USER)"
db_password="$(cf_get_env POSTGRES_ANALYTICS_PASSWORD)"
# Format needed for Python connections:
cf_set_env DATABASE_URL "postgresql://$db_user:$db_password@$db_host:$db_port/$db_name"
# Format needed for R connections:
cf_set_env DATABASE_HOSTNAME "$db_host"
cf_set_env DATABASE_PORT "$db_port"
cf_set_env DATABASE_USER "$db_user"
cf_set_env DATABASE_PASSWORD "$db_password"
cf restart crt-portal-jupyter