diff --git a/tdrs-backend/plg/deploy.sh b/tdrs-backend/plg/deploy.sh index a93704c3f..c3264f5ed 100755 --- a/tdrs-backend/plg/deploy.sh +++ b/tdrs-backend/plg/deploy.sh @@ -9,7 +9,7 @@ help() { echo "a Deploy the entire PLG stack." echo "p Deploy a postgres exporter. Requires -u and -d" echo "u Requires -p. The database URI the exporter should connect with." - echo "d Requires -p. The Cloud Foundry service name of the RDS instance." + echo "d The Cloud Foundry service name of the RDS instance. Should be included with all deployments." echo } @@ -39,9 +39,12 @@ deploy_grafana() { APP_NAME="grafana" DATASOURCES="datasources.yml" cp datasources.template.yml $DATASOURCES + MANIFEST=manifest.tmp.yml + cp manifest.yml $MANIFEST yq eval -i ".datasources[0].url = \"http://prometheus.apps.internal:8080\"" $DATASOURCES yq eval -i ".datasources[1].url = \"http://loki.apps.internal:8080\"" $DATASOURCES + yq eval -i ".applications[0].services[0] = \"$1\"" $MANIFEST cf push --no-route -f manifest.yml -t 180 --strategy rolling # cf map-route $APP_NAME apps.internal --hostname $APP_NAME @@ -52,6 +55,7 @@ deploy_grafana() { cf add-network-policy $APP_NAME prometheus --protocol tcp --port 8080 cf add-network-policy $APP_NAME loki --protocol tcp --port 8080 rm $DATASOURCES + rm $MANIFEST popd } @@ -69,6 +73,14 @@ deploy_loki() { popd } +err_help_exit() { + echo $1 + echo + help + popd + exit +} + while getopts ":hap:u:d:" option; do case $option in h) # display Help @@ -81,7 +93,7 @@ while getopts ":hap:u:d:" option; do DEPLOY="pg-exporter";; u) # Bind a Postgres exporter to $DB_URI DB_URI=$OPTARG;; - d) # Bind a Postgres exporter to $DB_SERVICE_NAME + d) # Bind a Postgres exporter or Grafana to $DB_SERVICE_NAME DB_SERVICE_NAME=$OPTARG;; \?) # Invalid option echo "Error: Invalid option" @@ -95,18 +107,17 @@ if [ "$#" -eq 0 ]; then fi pushd "$(dirname "$0")" +if [ "$DB_URI" == "" ] || [ "$DB_SERVICE_NAME" == "" ]; then + err_help_exit "Error: you must include a database service name." +fi if [ "$DEPLOY" == "plg" ]; then deploy_prometheus deploy_loki deploy_grafana fi if [ "$DEPLOY" == "pg-exporter" ]; then - if [ "$DB_URI" == "" ] || [ "$DB_SERVICE_NAME" == "" ]; then - echo "Error: you must also pass -u and -d when deploying a postgres exporter." - echo - help - popd - exit + if [ "$DB_URI" == "" ]; then + err_help_exit "Error: you must provide a database uri when deploying a postgres exporter." fi deploy_pg_exporter $ENV $DB_URI $DB_SERVICE_NAME fi diff --git a/tdrs-backend/plg/grafana/manifest.yml b/tdrs-backend/plg/grafana/manifest.yml index 199a8b053..94b8fab33 100644 --- a/tdrs-backend/plg/grafana/manifest.yml +++ b/tdrs-backend/plg/grafana/manifest.yml @@ -32,3 +32,5 @@ applications: cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING" buildpacks: - https://github.com/cloudfoundry/binary-buildpack + services: + - {{ rds_service }}