This repository has been archived by the owner on Nov 15, 2019. It is now read-only.
forked from BD2KGenomics/dcc-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_bootstrap
415 lines (343 loc) · 16.9 KB
/
install_bootstrap
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/env bash
# Created by Solomon Shorser
# Hacked by Denis Yuen
# Hacked by Brian O'Connor <[email protected]>
# TODO:
# * we need a mechanism to shutdown since this script launches services in daemon mode
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
cat <<MSG
UCSC CLOUD COMMONS INSTALLATION BOOTSTRAPPER
-----------------------------------------------------------------------------
This tool will setup a single host which has all of the infrastructure we
use to run the UCSC Cloud Commons reference implemenation used by the
UCSC Genomics Institute. See https://github.com/DataBiosphere/cgp-deployment
This system requires the following:
* Docker support in your Linux distribution (Ubuntu 16.04 is officially supported).
Note: by default the ethernet device is assumed to be eth0 and this is used to
find the IP address of the host. In some instances on AWS the default ethernet
device is ens3 for example. You can override the eth0 by setting the
ETH_DEV env variable before running this script.
For more information see:
* the main GitHub page: https://github.com/DataBiosphere/cgp-deployment
* the UCSC Genomics Institute - Analysis Core: http://ucsc-cgl.org
MSG
# Check if a repository exists at a given directory and if not, clone it
function check_for_repo {
if [ ! -d "$2" ]; then
git clone "$1" "$2"
cd "$2"
git checkout feature/commons
cd ..
fi
}
function generate_password {
tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1
}
# Ask the user a question and save the answer.
# They MUST give an answer, they cannot leave their answer blank. In the future, that could be parameterized...
# $1 - the question string
# $2 - the previous value
# $3 - the name of the value
# $4 - reference to the user's answer.
function ask_question()
{
question_str=$1
prev_val=$2
val_name=$3
answer=''
while [[ -z ${answer// /} ]] ; do
if [[ -n $prev_val ]] ; then
read -ep "${question_str} Previous value: "$'\n' -i "$prev_val" answer
else
read -ep "$question_str"$'\n' answer
fi
if [[ -z ${answer// /} ]] ; then
echo "$val_name name cannot be blank."
fi
done
# Set the user's value in the reference. See here: http://stackoverflow.com/a/14852461/192801 to get an idea of how this works.
eval "${!4}=\"$answer\""
}
# RUN BASIC INSTALLERS
# FYI: The weird "^^" is to make the user input into uppercase so that if they enter "y" the installer will still run.
install_commons_launcher=''
while [[ "${install_commons_launcher^^}" != 'Y' && "${install_commons_launcher^^}" != 'N' ]] ; do
echo "DO YOU WISH TO CONTINUE [Y/N]:"
read install_commons_launcher
if [ "${install_commons_launcher^^}" = 'Y' ] ; then
user_install_docker=''
set +e
DOCKER_PATH="$(which docker)"
set -e
if [ -z "$DOCKER_PATH" ] ; then
user_install_docker='Y'
else
while [[ "${user_install_docker^^}" != 'Y' && "${user_install_docker^^}" != 'N' ]] ; do
echo "It looks like docker may already be installed. Would you like to run this step anyway, which may attempt to upgrade docker? [Y/N]"
read user_install_docker
done
fi
echo "Installing various apt packages"
# need to install regardless
set +e
sudo apt-get -y update
sudo apt-get install wget curl ruby-mustache=1.0.2-1 jq git --yes &> install_wget_curl.log
install_wget_result=$?
set -e
if [ $install_wget_result -ne 0 ] ; then
echo "It looks like there may have been a problem installing or updated wget and curl:"
cat install_wget_curl.log
exit 1
fi
if [ "${user_install_docker^^}" = 'Y' ] ; then
# Remove eXecute permission from /etc/grub.d/30_os-prober because sometimes the docker installer will hang when this hangs. This has happened in OpenStack
# and could happen elsewhere.
if [ -f /etc/grub.d/30_os-prober ] ; then
sudo chmod a-x /etc/grub.d/30_os-prober
fi
echo "Installing docker..."
set +e
curl -sSL https://get.docker.com/ | sh &> install_docker.log
install_docker_result=$?
set -e
if [ $install_docker_result -ne 0 ] ; then
echo "It looks like there may have been a problem installing docker:"
cat install_wget_curl.log
exit 1
fi
set +e
sudo wget https://github.com/docker/compose/releases/download/1.8.1/run.sh -O /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose &> install_compose.log
install_compose_result=$?
set -e
if [ $install_compose_result -ne 0 ] ; then
echo "It looks like there may have been a problem installing docker compose:"
cat install_compose.log
exit 1
fi
echo "Done installing docker!"
DOCKER_PATH="$(which docker)"
else
echo "Skipping docker installation..."
fi
if [ -z "$DOCKER_PATH" ] ; then
echo "You need to install docker before pulling docker images. Please ensure that docker is properly installed and then re-run this script with the command \"bash install_bootstrap\""
exit 1
fi
elif [ "${install_commons_launcher^^}" = 'N' ] ; then
echo "You are exiting the installer now, but you can always run it again when you are ready."
exit 0
fi
done
# CORE COMMONS: initial steps
if [[ $(sudo docker network ls | grep core_public | wc -l) = "0" ]]; then
echo "creating core_public docker network"
sudo docker network create core_public
else
echo "core_public docker network already exists"
fi
#add the command to
#start the UCSC Computational Genomics Platform (CGP) container that sets up the
#Nginx config template with the uuids for each of the containers in the CGP
#at boot time
echo "Attempting to add docker start core-config-gen to rc.local"
sudo ./put_core_start_cmd_in_rc.sh
# CORE COMMON: bring up the primary nginx gateway server
run_common=''
while [[ "${run_common^^}" != 'Y' && "${run_common^^}" != 'N' ]] ; do
read -ep $'Are you ready to launch the public-facing gateway nginx server? [Y/N]\n' run_common
done
if [[ "${run_common^^}" = 'Y' ]]; then
if [[ $(sudo docker ps | grep 'core-' | wc -l) = "0" ]]; then
echo "starting core primary nginx gateway and common containers"
cd common
sudo docker-compose.yml up -d
cd ..
else
echo "core common containers already running."
fi
echo 'you can stop the core common containers with `cd $(pwd)/common && docker-compose down`'
else
echo "the core won't be publicly accessible until the gateway is started"
fi
# RUN THE BOARDWALK INSTALLER
run_boardwalk=''
while [[ "${run_boardwalk^^}" != 'Y' && "${run_boardwalk^^}" != 'N' ]] ; do
echo "Would you like to run the boardwalk installer now? [Y/N]"
read run_boardwalk
if [ "${run_boardwalk^^}" = 'Y' ] ; then
dcc_dashboard_protocol=https
dcc_dashboard_port=8080
if [ -f boardwalk_launcher_config/boardwalk.config ] ; then
source <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" boardwalk_launcher_config/boardwalk.config)
fi
echo "Do you want to run boardwalk in dev mode or prod? [dev/prod]"
boardwalk_mode=-1
while [[ "${boardwalk_mode}" = "-1" ]]; do
read boardwalk_mode
if [[ "${boardwalk_mode^^}" =~ ^(D|DEV|DEVELOP|DEVELOPMENT)$ ]]; then
boardwalk_mode=dev
elif [[ "${boardwalk_mode^^}" =~ ^(P|PROD|PRODUCTION)$ ]]; then
boardwalk_mode=prod
else
echo "bad input: ${boardwalk_mode}" >&2
boardwalk_mode=-1
fi
done
# base_url=''
# if [ ! -z $BASE_URL ] ; then
# read -ep $'What is the name of the base URL? Previous value: \n' -i "$BASE_URL" base_url
# else
# read -ep $'What is the name of the base URL? \n' base_url
# fi
# email_address=''
# read -ep $'What is the email address for notification? Previous value: \n' -i "$EMAIL_ADDRESS" email_address
# else
# read -ep $'What is the email address for notification? \n' email_address
# fi
############################
# Authorization/whitelist #
############################
echo "Do you want to install with an authorization whitelist? [Y/N]"
require_auth=''
while [[ "${require_auth^^}" != 'Y' && "${require_auth^^}" != 'N' ]] ; do
read require_auth
if [ "${require_auth^^}" = 'Y' ] ; then
email_whitelist_name='email_whitelist_name'
ask_question "What is the name of the AWS Secret that contains the whitelist? (e.g. commons/dev/whitelist)" "$EMAIL_WHITELIST_NAME" "email whitelist name" $email_whitelist_name
project_name='project_name'
ask_question "What is the name of the project for this instance (e.g. Stage, Commons, AnVIL, etc.)? This name will be used for error messages." "$PROJECT_NAME" "project name" $project_name
contact_email='contact_email'
ask_question "What is a contact email in case there are problems authorizing?" "$CONTACT_EMAIL" "contact email" $contact_email
elif [ "${require_auth^^}" = 'N' ] ; then
# we need to reset these because otherwise the old value from the last run which was cached
# in boardwalk.config will overwrite. This would be bad because a value for email_whitelist_name
# indicates whether or not there is authentication.
email_whitelist_name=''
project_name=''
contact_email=''
fi
done
dcc_dashboard_host='dcc_dashboard_host'
ask_question "What is the hostname of dcc-dashboard? (This is likely the domain name resolving to your virtual machine.)" "$DCC_DASHBOARD_HOST" "DCC Dashboard Host" $dcc_dashboard_host
############################
# AWS questions #
############################
aws_default_region='aws_default_region'
ask_question "What AWS region does AWS Secrets Manager reside in?" "$AWS_DEFAULT_REGION" "AWS region" $aws_default_region
aws_access_key_id='aws_access_key_id'
ask_question "What is your AWS Access Key ID?" "$AWS_ACCESS_KEY_ID" "AWS Key name" $aws_access_key_id
aws_secret_access_key='aws_secret_access_key'
ask_question "What is your AWS Secret Access Key?" "$AWS_SECRET_ACCESS_KEY" "AWS Secret Key name" $aws_secret_access_key
#############################
# Elasticsearch questions #
#############################
es_port='443'
es_protocol='https'
es_domain='es_domain'
ask_question "What is the domain of the elasticsearch instance?" "$ES_DOMAIN" "Elasticsearch domain" $es_domain
#############################
# Google Cloud Services #
#############################
google_client_id='google_client_id'
ask_question "What is your Google Client ID?" "$GOOGLE_CLIENT_ID" "Google Client ID" $google_client_id
google_client_secret='google_client_secret'
ask_question "What is your Google Client Secret?" "$GOOGLE_CLIENT_SECRET" "Google Client Secret" $google_client_secret
google_site_verification_code='google_site_verification_code'
ask_question "What is your Google site verification code, something like tk74JOp1VBqdRQVTirM8WKpa1VIYW_vwxfoJo53inH8?" "$GOOGLE_SITE_VERIFICATION_CODE" "Google Site Verification Code" $google_site_verification_code
#####################################
# Generating presigned URLs in AWS #
#####################################
azul_s3_bucket='azul_s3_bucket'
ask_question "What is the name of the AWS S3 bucket to store BDBags?" "$AZUL_S3_BUCKET" "Azul S3 Bucket" $azul_s3_bucket
azul_s3_aws_region='azul_s3_aws_region'
ask_question "What is the AWS region of that AWS S3 bucket?" "$AZUL_S3_AWS_REGION" "Azul_S3_Aws_Region" $azul_s3_aws_region
# The default expiration time of the presigned URL is set to 1 h.
azul_presigned_url_expiration=3600
# dcc_dashboard_port='dcc_dashboard_port'
# ask_question "What is your DCC Dashboard Port?" "$DCC_DASHBOARD_PORT" "DCC Dashboard Port" $dcc_dashboard_port
# dcc_dashboard_protocol='dcc_dashboard_protocol'
# ask_question "What is your DCC Dashboard Protocol (http/https)?" "$DCC_DASHBOARD_PROTOCOL" "DCC Dashboard Protocol" $dcc_dashboard_protocol
# dcc_dashboard_service='dcc_dashboard_service'
# ask_question "Where is your DCC Dashboard Service domain?" "$DCC_DASHBOARD_SERVICE" "DCC Dashboard Service" $dcc_dashboard_service
dcc_dashboard_service=$dcc_dashboard_host
# dcc_invoicing_service='dcc_invoicing_service'
# ask_question "What is your DCC Invocing Service domain?" "$DCC_INVOICING_SERVICE" "DCC Invoicing Service" $dcc_invoicing_service
dcc_invoicing_service=$dcc_dashboard_host
dos_dss_service='dos_dss_service'
ask_question "What is the domain of the dos-dss server?" "$DOS_DSS_SERVICE" "DOS DSS Service" $dos_dss_service
# to be used to encrypt the refresh token that is stored in the session
refresh_token_encrypt_key="$(generate_password)"
user_group=$(stat -c '%u:%g' $HOME)
#Setting up the database vars for login
login_user='login-user'
login_db='login-db'
echo "generating monitor postgresql (postgres) password"
login_password="$(generate_password)"
echo "generating SECRET_KEY for login"
secret_key="$(generate_password)"
echo "generating LOG_IN_TOKEN for boardwalk check session"
login_token="$(generate_password)"
#TODO: The script should snoop the .env file and check if it has a password assigned already and use that. Otherwise, generate a random password.
core_client_version='1.1.2'
# Now write a config for this file.
[[ -f boardwalk_launcher_config/boardwalk.config ]] || mkdir -p boardwalk_launcher_config
cat > boardwalk_launcher_config/boardwalk.config <<CONFIG
{
"AZUL_S3_BUCKET":"${azul_s3_bucket}",
"AZUL_S3_AWS_REGION":"${azul_s3_aws_region}",
"AZUL_PRESIGNED_URL_EXPIRATION":"${azul_presigned_url_expiration}",
"AWS_DEFAULT_REGION":"${aws_default_region}",
"AWS_ACCESS_KEY_ID":"${aws_access_key_id}",
"AWS_SECRET_ACCESS_KEY":"${aws_secret_access_key}",
"DATABASE_URL":"${database_url}",
"PROJECT_NAME":"${project_name}",
"CONTACT_EMAIL":"${contact_email}",
"EMAIL_WHITELIST_NAME":"${email_whitelist_name}",
"REFRESH_TOKEN_ENCRYPT_KEY":"${refresh_token_encrypt_key}",
"DCC_DASHBOARD_HOST":"${dcc_dashboard_host}",
"DCC_DASHBOARD_PROTOCOL":"${dcc_dashboard_protocol}",
"DCC_DASHBOARD_SERVICE":"${dcc_dashboard_service}",
"DCC_INVOICING_SERVICE":"${dcc_invoicing_service}",
"DCC_CORE_CLIENT_VERSION":"${core_client_version}",
"DOS_DSS_SERVICE":"${dos_dss_service}",
"ES_DOMAIN":"${es_domain}",
"ES_PORT":"${es_port}",
"ES_PROTOCOL":"${es_protocol}",
"GOOGLE_CLIENT_ID":"${google_client_id}",
"GOOGLE_CLIENT_SECRET":"${google_client_secret}",
"GOOGLE_SITE_VERIFICATION_CODE":"${google_site_verification_code}",
"LOGIN_POSTGRES_USER":"${login_user}",
"LOGIN_POSTGRES_DB":"${login_db}",
"LOGIN_POSTGRES_PASSWORD":"${login_password}",
"LOG_IN_TOKEN":"${login_token}",
"SECRET_KEY":"${secret_key}",
"SERVER_NAME":"${dcc_dashboard_host}",
"USER_GROUP":"${user_group}"
}
CONFIG
# template out stuff
mustache boardwalk_launcher_config/boardwalk.config boardwalk/conf/boardwalk.config.template > boardwalk/.env
cd boardwalk
# If in dev mode, check for dev repos and clone if not present
if [ "${boardwalk_mode}" = "dev" ]; then
check_for_repo https://github.com/DataBiosphere/cgp-dashboard.git dcc-dashboard
check_for_repo https://github.com/DataBiosphere/azul.git azul
check_for_repo https://github.com/DataBiosphere/cgp-boardwalk.git boardwalk
fi
# Bringing stuff down in case there are some cached containers
echo "Bringing down any existing Boardwalk containers and volumes"
sudo docker-compose -f ${boardwalk_mode}.yml down -v
echo "Creating Boardwalk associated containers"
sudo docker-compose -f ${boardwalk_mode}.yml up -d
cd ..
elif [ "${run_boardwalk^^}" = 'N' ] ; then
echo "You can run this script at another time to run the boardwalk installer"
fi
done
# FINISHED INSTALLER
echo "Done with installation, exiting now."
set +e