-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupgrade-schema.sh
executable file
·40 lines (32 loc) · 1.01 KB
/
upgrade-schema.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
40
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
cf api "$CF_API_URL"
(set +x; cf auth "$CF_USERNAME" "$CF_PASSWORD")
cf target -o "$CF_ORGANIZATION" -s "$CF_SPACE"
# dummy app so we can run a task.
cf push \
-f src/manifests/upgrade-schema.yml \
-p src \
-i 1 \
--var DB_NAME="$DB_NAME" \
--var REDIS_NAME="$REDIS_NAME" \
--var APP_NAME="$APP_NAME" \
--var FLASK_ENV="$FLASK_ENV" \
--var DATABASE_ENCRYPTION_KEY="$DATABASE_ENCRYPTION_KEY" \
--no-route \
--health-check-type=process \
-c "sleep 3600" \
"$APP_NAME"
# This is just to put logs in the concourse output.
(cf logs "$APP_NAME" | grep "TASK/db-upgrade") &
cmd="FLASK_APP='broker.app:create_app()' flask db upgrade"
id=$(cf run-task "$APP_NAME" --command "$cmd" --name="db-upgrade" | grep "task id:" | awk '{print $3}')
status=RUNNING
while [[ "$status" == 'RUNNING' ]]; do
sleep 5
status=$(cf tasks "$APP_NAME" | grep "^$id " | awk '{print $3}')
done
cf delete -r -f "$APP_NAME"
[[ "$status" == 'SUCCEEDED' ]] && exit 0
exit 1