helm: Convert the SSO server to be served over SSL.
[arvados-k8s.git] / arvados / config / api-server / 90-init-db.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -e
7 prepare_database() {
8   RAILSPKG_DATABASE_LOAD_TASK="$1"
9   DB_MIGRATE_STATUS=$($COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true)
10   if echo "$DB_MIGRATE_STATUS" | grep -qF 'Schema migrations table does not exist yet.'; then
11       # The database exists, but the migrations table doesn't.
12       bundle exec rake "$RAILSPKG_DATABASE_LOAD_TASK" db:seed
13   elif echo "$DB_MIGRATE_STATUS" | grep -q '^database: '; then
14       bundle exec rake db:migrate
15   elif echo "$DB_MIGRATE_STATUS" | grep -q 'database .* does not exist'; then
16       bundle exec rake db:setup
17   else
18     echo "Warning: Database is not ready to set up." >&2
19     exit 1
20   fi
21
22   if [[ -f "/create-workbench-api-client.rb" ]]; then
23     # This is the API server
24     cd /var/www/arvados-api/current
25     bundle exec script/create_superuser_token.rb {{ .Values.superUserSecret }}
26     cd script
27     bundle exec get_anonymous_user_token.rb -t {{ .Values.anonymousUserSecret }} || true
28     bundle exec rails runner /create-workbench-api-client.rb
29   fi
30
31 }
32
33 prepare_database "db:structure:load"
34