-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall_bootstrap
More file actions
372 lines (324 loc) · 17.5 KB
/
Copy pathinstall_bootstrap
File metadata and controls
372 lines (324 loc) · 17.5 KB
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
#! /bin/bash
set -e
PANCANCER_LAUNCHER_VERSION=3.2.2
PANCANCER_CLI_VERSION=0.1.2
WORKFLOW_LISTING_URL=https://raw.githubusercontent.com/ICGC-TCGA-PanCancer/cli/${PANCANCER_CLI_VERSION}/config/workflowlist.json
cat <<MSG
PANCANCER COMMAND LINE INTERFACE - INSTALLATION
-----------------------------------------------
This tool will setup a "launcher" host which has all of the tools we used to align and variant call
the PanCancer donors. This launcher host can then launch one or more worker VMs with our Docker
workflows installed on them for processing one or more genomes specified by the user.
This system requires the following:
* Docker support in your Linux distribution (Ub1untu 14.04 is officially supported by the Pancancer Launcher).
* AWS credentials, if you are using Amazon EC2.
* A GNOS key (or keys) which are used to both download Docker images for our workflows, dependencies, as well as data from from GNOS servers used in the project.
Please ensure that these files are in ~/.gnos
* Alternatively (or in addition to) the GNOS keys, a token for downloading workflows, dependencies, as well as donor data files from S3.
MSG
# 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\""
}
user_pancancer_version=latest
#FYI: The weird "^^" is to make the user input into uppercase so that if they enter "y" the installer will still run.
install_pancancer_launcher=''
while [[ "${install_pancancer_launcher^^}" != 'Y' && "${install_pancancer_launcher^^}" != 'N' ]] ; do
echo "DO YOU WISH TO CONTINUE [Y/N]:"
read install_pancancer_launcher
if [ "${install_pancancer_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
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
sudo apt-get install wget curl --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
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
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
else
echo "Pulling pancancer_launcher image..."
set +e
sudo docker pull pancancer/pancancer_launcher:"${user_pancancer_version}" &> pull_image.log
pull_result=$?
set -e
if [ $pull_result -ne 0 ] ; then
echo "It looks like there might have been an error when pulling the docker image. The pancancer_launcher cannot be run until this is resolved. Error is:"
cat pull_image.log
exit 1
fi
echo "Done pulling pancancer_launcher!"
fi
elif [ "${install_pancancer_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
run_pancancer_launcher=''
while [[ "${run_pancancer_launcher^^}" != 'Y' && "${run_pancancer_launcher^^}" != 'N' ]] ; do
echo "Would you like to run the pancancer_launcher now? [Y/N]"
read run_pancancer_launcher
# If the user would like to run pancancer_launcher, then we have to get some config settings from them OR read them from an existing file
if [ "${run_pancancer_launcher^^}" = 'Y' ] ; then
#Read the config file if it exists and then show previous values...
if [ -f ~/.pancancer/pancancer.config ] ; then
source ~/.pancancer/pancancer.config
fi
user_cloud_env=''
while [[ -z "${user_cloud_env// /}" ]] ; do
if [ ! -z $CLOUD_ENV ] ; then
read -ep $'What cloud environment are you working in? Allowed values are "AWS", "OpenStack", "Azure". Previous value: \n' -i "$CLOUD_ENV" user_cloud_env
else
read -ep $'What cloud environment are you working in? Allowed values are "AWS", "OpenStack", "Azure". \n' user_cloud_env
fi
if [[ -z "${user_cloud_env// /}" || ( ${user_cloud_env} != 'AWS' && ${user_cloud_env} != 'OpenStack' && ${user_cloud_env} != 'Azure' ) ]] ; then
echo 'Cloud environment must be one of: "AWS", "OpenStack", "Azure".'
user_cloud_env=''
fi
done
user_pem_path=''
while [[ ! -f $user_pem_path || ! -e $user_pem_path || -z "${user_pem_path// /}" ]] ; do
if [ ! -z $PEM_PATH ] ; then
read -ep $'What is the path to the pem key file you will use to authenticate in this environment? Previous value: \n' -i "$PEM_PATH" user_pem_path
user_pem_path="${user_pem_path/#\~/$HOME}"
else
read -ep $'What is the path to the pem key file you will use to authenticate in this environment?\n' user_pem_path
user_pem_path="${user_pem_path/#\~/$HOME}"
fi
if [[ ! -f $user_pem_path || ! -e $user_pem_path ]] ; then
echo "The path you pass for the key file must be valid. Please ensure that \"$user_pem_path\" is a valid path."
fi
done
user_key_name='user_key_name'
ask_question "What is the name of this key?" "$KEY_NAME" "Key name" $user_key_name
if [ $user_cloud_env == 'AWS' ] ; then
############################
# AWS questions
############################
if [ -f ~/.aws/config ] ; then
AWS_KEY=$(grep aws_access_key_id ~/.aws/config | sed 's/\(.*=\)//g')
AWS_SECRET_KEY=$(grep aws_secret_access_key ~/.aws/config | sed 's/\(.*=\)//g')
fi
user_aws_key='user_aws_key'
ask_question "What is your AWS Key?" "$AWS_KEY" "AWS Key name" $user_aws_key
user_aws_secret_key='user_aws_secret_key'
ask_question "What is your AWS Secret Key?" "$AWS_SECRET_KEY" "AWS Secret Key name" $user_aws_secret_key
user_sec_grp='user_sec_grp'
ask_question "What is your Security Group?" "$SECURITY_GROUP" "Security Group" $user_sec_grp
# Write the AWS config file, so that it will be available when the start_launcher_container script runs.
# TODO: Parameterize "region" and "output", maybe...
[[ -d ~/.aws ]] || mkdir ~/.aws
cat >~/.aws/config <<AWS_CONFIG
[default]
aws_access_key_id=${user_aws_key}
aws_secret_access_key=${user_aws_secret_key}
region=us-east-1
output=json
AWS_CONFIG
elif [ $user_cloud_env == 'Azure' ] ; then
############################
# AZURE QUESTIONS
############################
user_azure_subscription_id='user_azure_subscription_id'
ask_question "What is your Azure subscription?" "$AZURE_SUBSCRIPTION" "Azure subscription" $user_azure_subscription_id
user_azure_storage_account_name='user_azure_storage_account_name'
ask_question "What is your Azure storage account name?" "$AZURE_STORAGE_ACCOUNT" "Azure storage account name" $user_azure_storage_account_name
user_azure_storage_account_key='user_azure_storage_account_key'
ask_question "What is your Azure storage account key?" "$AZURE_STORAGE_ACCOUNT_KEY" "Azure storage account key" $user_azure_storage_account_key
user_azure_AD_user='user_azure_AD_user'
ask_question "What is your Azure Active Directory user name?" "$AZURE_AD_USER" "Azure Active Directory user name" $user_azure_AD_user
user_azure_AD_passwd='user_azure_AD_passwd'
ask_question "What is your Azure Active Directory password?" "$AZURE_AD_PASSWD" "Azure Active Directory user name" $user_azure_AD_passwd
user_azure_AD_tenant='user_azure_AD_tenant'
ask_question "What is your Azure Active Directory tenant?" "$AZURE_AD_TENANT" "Azure Active Directory tenant" $user_azure_AD_tenant
user_azure_AD_client='user_azure_AD_client'
ask_question "What is your Azure Active Directory client?" "$AZURE_AD_CLIENT" "Azure Active Directory client" $user_azure_AD_client
user_azure_virtual_network='user_azure_virtual_network'
ask_question "What is the name of the Virtual Network for this fleet?" "$AZURE_VIRTUAL_NETWORK" "Azure Virtual Network Name" $user_azure_virtual_network
user_azure_location='user_azure_location'
ask_question "What Location do you want to use for this fleet?" "$AZURE_LOCATION" "Location" $user_azure_location
# TODO: Get public and private Azure IP addresses, or ask the user to provide them since it seems rather difficult to get them from the Azure API directly.
elif [ $user_cloud_env == 'OpenStack' ] ; then
############################
# OpenStack questions
############################
user_os_username='user_os_username'
ask_question "What is your OpenStack username (formatted as <tenant>:<username>)?" "$OS_USERNAME" "OpenStack username" $user_os_username
user_os_password='user_os_password'
ask_question "What is your OpenStack password?" "$OS_PASSWORD" "OpenStack password" $user_os_password
user_os_endpoint='user_os_endpoint'
ask_question "What is your OpenStack endpoint?" "$OS_ENDPOINT" "OpenStack endpoint" $user_os_endpoint
user_os_region='user_os_region'
ask_question "What is your OpenStack region?" "$OS_REGION" "OpenStack region" $user_os_region
user_sec_grp='user_sec_grp'
ask_question "What is your Security Group?" "$SECURITY_GROUP" "Security Group" $user_sec_grp
user_os_network_id='user_os_network_id'
ask_question "What is your OpenStack network ID?" "$OS_NETWORK_ID" "Network ID" $user_os_network_id
user_os_zone=''
if [ ! -z $OS_ZONE ] ; then
read -ep $'What is your OpenStack zone? Previous value: \n' -i $OS_REGION user_os_zone
else
read -ep $'What is your OpenStack zone?\n' user_os_zone
fi
else
# Just in case some other value somehow gets in to $user_cloud_env
echo "Unrecognized cloud environment: $user_cloud_env, exiting..."
exit 1
fi
# echo "What version of the pancancer_launcher do you wish to run (default will be \"latest\")?"
# read user_pancancer_version
# They already pulled "latest", earlier in this script, so just stick with that. Future versions could ask this question, if necessary...
user_pancancer_version="latest"
user_fleet_name=''
if [ $user_cloud_env == 'Azure' ] ; then
# In Azure, the fleet name also gets used for the storage account name which may only contain lowercase letters, numbers, and dashes.
if [ ! -z "$FLEET_NAME" ] ; then
read -ep $'What would you like to name your fleet? Azure fleet names may only contain lowercase letter, numbers, and dashes. If you do not specify a name, a name will be generated randomly for you. Previous value: \n' -i "$FLEET_NAME" user_fleet_name
else
read -ep $'What would you like to name your fleet? Azure fleet names may only contain lowercase letter, numbers, and dashes. If you do not specify a name, a name will be generated randomly for you.\n' user_fleet_name
fi
user_fleet_name=${user_fleet_name,,}
user_fleet_name=${user_fleet_name//[^[:alnum:]]/}
# If the user didn't specify a fleet name we need to do it HERE because the start_launcher_container.sh script may generate fleet names
# that are not Azure-friendly.
if [ -z $user_fleet_name ] ; then
user_fleet_name=$(cat /dev/urandom | tr -dc 'a-z0-9-' | fold -w 10 | head -n 1)
fi
echo "Your Azure fleet name: $user_fleet_name"
else
if [ ! -z "$FLEET_NAME" ] ; then
read -ep $'What would you like to name your fleet? If you do not specify a name, a name will be generated randomly for you. Previous value: \n' -i "$FLEET_NAME" user_fleet_name
else
read -ep $'What would you like to name your fleet? If you do not specify a name, a name will be generated randomly for you.\n' user_fleet_name
fi
fi
# Build a flag for fleet names to get passed to the next script...
FLEET_NAME_STR=''
if [ ! -z "$user_fleet_name" ] ; then
# remove quotes from the fleet names, could have come from quoted previous fleet name in config
user_fleet_name=${user_fleet_name//\"/}
# replace space with underscore so we can pass to the next script without having to surround in quotes because that
# causes problems for other systems.
user_fleet_name=${user_fleet_name// /_}
FLEET_NAME_STR=" -f $user_fleet_name "
fi
user_fleet_size='user_fleet_size'
# Loop until the user gives a valid integer.
while [[ -n ${user_fleet_size//[0-9]/} ]] ; do
user_fleet_size='user_fleet_size'
ask_question "What is the maximum number of worker VMs you want to run in your fleet?" "$FLEET_SIZE" "Maximum fleet size" $user_fleet_size
if [[ -n ${user_fleet_size//[0-9]/} ]] ; then
echo "Only positive integers are allowed."
fi
done
workflow_listing_url='workflow_listing_url'
ask_question "What is the URL that lists available workflows?" $WORKFLOW_LISTING_URL "Workflow listing URL" $workflow_listing_url
# now wget the start_launcher_container script and call it with the values from above:
#$(wget -q -O start_launcher_container.sh https://github.com/ICGC-TCGA-PanCancer/pancancer_launcher/releases/download/$PANCANCER_LAUNCHER_VERSION/start_launcher_container.sh)
starter_script_url="https://github.com/ICGC-TCGA-PanCancer/pancancer_launcher/releases/download/$PANCANCER_LAUNCHER_VERSION/start_launcher_container.sh"
set +e
wget -O start_launcher_container.sh $starter_script_url 2>get_start_launcher_container.err
get_starter_script_result=$?
set -e
if [ $get_starter_script_result -ne 0 ] ; then
echo "There seems to have been a problem downloading the startup script from: $starter_script_url"
echo "Error is:"
cat ./get_start_launcher_container.err
fi
chmod u+x start_launcher_container.sh
CMD_STR="bash start_launcher_container.sh -p $user_pem_path -i $user_pancancer_version -e ${user_cloud_env^^} $FLEET_NAME_STR"
# Now write a config for this file.
[[ -d ~/.pancancer ]] || mkdir ~/.pancancer
# Note: You can't have ANY blank lines in .pancancer/pancancer.config because the python library that will eventually process it does not like blank lines and will fail.
cat >~/.pancancer/pancancer.config <<CONFIG
PEM_PATH="${user_pem_path}"
KEY_NAME="${user_key_name}"
FLEET_NAME="${user_fleet_name}"
FLEET_SIZE="${user_fleet_size}"
WORKFLOW_LISTING_URL="${workflow_listing_url}"
CLOUD_ENV="${user_cloud_env}"
SECURITY_GROUP="${user_sec_grp}"
AZURE_SUBSCRIPTION="${user_azure_subscription_id}"
AZURE_STORAGE_ACCOUNT="${user_azure_storage_account_name}"
AZURE_STORAGE_ACCOUNT_KEY="${user_azure_storage_account_key}"
AZURE_AD_USER="${user_azure_AD_user}"
AZURE_AD_PASSWD="${user_azure_AD_passwd}"
AZURE_AD_TENANT="${user_azure_AD_tenant}"
AZURE_AD_CLIENT="${user_azure_AD_client}"
AZURE_VIRTUAL_NETWORK="${user_azure_virtual_network}"
AZURE_LOCATION="${user_azure_location}"
OS_USERNAME="${user_os_username}"
OS_PASSWORD="${user_os_password}"
OS_ENDPOINT="${user_os_endpoint}"
OS_NETWORK_ID="${user_os_network_id}"
OS_REGION="${user_os_region}"
OS_ZONE="${user_os_zone}"
CONFIG
[[ -d "/home/$USER/pancancer_launcher_config" ]] || mkdir "/home/$USER/pancancer_launcher_config"
cp ~/.pancancer/pancancer.config /home/$USER/pancancer_launcher_config/pancancer.config
echo $CMD_STR > start_launcher_container.cmd
$(echo -e $CMD_STR)
elif [ "${run_pancancer_launcher^^}" = 'N' ] ; then
echo "You can run this script at another time to run the pancancer launcher"
exit 0
fi
done
echo "Exiting now."
set +e