-
Notifications
You must be signed in to change notification settings - Fork 0
/
phenomenal.sh
executable file
·222 lines (185 loc) · 5.67 KB
/
phenomenal.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
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
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status
set -e
scriptname="${BASH_SOURCE##*/}"
function usage
{
cat <<TEXT_END
Usage:
$scriptname -h
$scriptname <command> <provider> [-c file] [options]
Options:
-h/--help Display help
-c/--config Use specified configuration file. If no configuration
file is specified, use default "config.<provider>.sh"
--skip-deployment Skips the deployment step (terraform)
--skip-provisioning Skips the provisioning step (ansible/helm)
Commands:
deploy Setup the cloud research environment
destroy Destroy the cloud research environment
state Status of the cloud research environment
list List network and flavor-names for the cloud provider
Providers:
aws
gcp
ostack
azure
kvm
byoc
Examples:
$scriptname deploy ostack
$scriptname destroy ostack
$scriptname state gcp
$scriptname deploy gcp --config-file ~/my-configs/my-cloud-conf
TEXT_END
}
# docker --version | grep "Docker version" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Docker is not installed - exiting" >&2
exit 1
fi
case "$1" in
deploy|destroy|state|list)
cmd="$1"
;;
-h|--help)
usage
exit
;;
"")
echo "No <command> specified" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
*)
printf '"%s" is not a valid command\n' "$1" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
esac
case "$2" in
aws|gcp|ostack|kvm|byoc|azure)
provider="$2"
;;
"")
echo "No <provider> specified" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
*)
printf '"%s" is not a valid provider\n' "$2" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
esac
config_file="config.$provider.sh"
case "$3" in
-c|--config*)
printf 'Using configuration file "%s"\n' "$4"
config_file="$4"
;;
"")
printf 'Using default configuration file "%s"\n' "$config_file"
;;
--skip-deployment)
export TF_skip_deployment=true;
;;
--skip-provisioning)
export TF_skip_provisioning=true;
;;
*)
printf '"%s" is not a valid argument\n' "$3" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
esac
if [[ ! -f "$config_file" ]]; then
printf 'Configuration file "%s" does not exist\n' "$config_file" >&2
exit 1
fi
case "$5" in
"")
;;
--skip-deployment)
export TF_skip_deployment=true;
;;
--skip-provisioning)
export TF_skip_provisioning=true;
;;
*)
printf '"%s" is not a valid argument\n' "$3" >&2
printf 'See "%s --help"\n' "$scriptname" >&2
exit 1
;;
esac
source "$config_file"
if [ -n "$TF_VAR_gce_credentials_file" ]; then
GOOGLE_CREDENTIALS=$(cat "$TF_VAR_gce_credentials_file")
fi
if [ -n "$OS_CREDENTIALS_FILE" ]; then
# Import credentials file if variables not set aleady
if [[ -z "$OS_USERNAME" ]] || [[ -z "$OS_PASSWORD" ]] || [[ -z "$OS_AUTH_URL" ]]; then
source "$OS_CREDENTIALS_FILE"
fi
fi
# Make sure KubeNow config dir exists
mkdir -p "$HOME/.kubenow"
# set environment variables used by scripts in cloud-deploy/
DEPLOYMENTS_DIR="deployments"
DEPLOYMENT_REFERENCE="id-phnmnl-${config_file%.sh}"
DEPLOYMENT_DIR_HOST="$PWD/$DEPLOYMENTS_DIR/$DEPLOYMENT_REFERENCE"
printf 'Using deployment directory "%s"\n' "$DEPLOYMENT_DIR_HOST"
# make sure KubeNow subrepo is updated but ignore errors
git submodule update > /dev/null 2>&1 || true
# Get all user GID
LOCAL_GROUP_IDS="$(id -G)"
# Specify extra kvm/libvirt args
if [[ $provider == "kvm" ]]; then
LIBVIRT_EXTRA_OPTS="-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock --net=host --privileged=true"
fi
# execute scripts via docker container with all dependencies
docker run --rm -it \
-v "$PWD":/cloud-deploy \
-v "$HOME/.kubenow":/.kubenow \
$LIBVIRT_EXTRA_OPTS \
-e "LOCAL_USER_ID=$UID" \
-e "LOCAL_GROUP_IDS=$LOCAL_GROUP_IDS" \
-e "LOCAL_DEPLOYMENT=True" \
-e "PORTAL_APP_REPO_FOLDER=/cloud-deploy" \
-e "PORTAL_DEPLOYMENTS_ROOT=/cloud-deploy/$DEPLOYMENTS_DIR" \
-e "PORTAL_DEPLOYMENT_REFERENCE=$DEPLOYMENT_REFERENCE" \
-e "GOOGLE_CREDENTIALS=$GOOGLE_CREDENTIALS" \
-e "SLACK_ERR_REPORT_TOKEN=$SLACK_ERR_REPORT_TOKEN" \
-e "TERRAFORM_OPT=$TERRAFORM_OPT" \
-e "ANSIBLE_OPT=$ANSIBLE_OPT" \
--env-file <(env | grep OS_) \
--env-file <(env | grep TF_) \
--env-file <(env | grep GOOGLE_) \
--env-file <(env | grep AWS_) \
--env-file <(env | grep ARM_) \
--env-file <(env | grep KUBENOW_) \
andersla/provisioners:20180215-1900 \
"cd /cloud-deploy && /cloud-deploy/cloud_portal/$provider/$cmd.sh"
if [[ $cmd == "deploy" || $cmd == "state" ]]; then
# display inventoty
echo "Inventory:"
cat "$DEPLOYMENT_DIR_HOST/inventory"
echo "---"
echo ""
# get domain from inventory
domain="$(awk -F'=' '/domain/ { print $2 }' $DEPLOYMENT_DIR_HOST/inventory)"
## finally display url:s
jupyter_url="http://notebook.$domain"
luigi_url="http://luigi.$domain"
galaxy_url="http://galaxy.$domain"
dashboard_url="http://dashboard.$domain"
echo 'Services should be reachable at following url:'
printf 'Galaxy: "%s"\n' "$galaxy_url"
printf 'Jupyter: "%s"\n' "$jupyter_url"
printf 'Luigi: "%s"\n' "$luigi_url"
printf 'Kube-dashboard: "%s"\n' "$dashboard_url"
echo
echo 'And if you want to ssh into master:'
echo "ssh-add $DEPLOYMENT_DIR_HOST/vre.key"
echo "ssh ubuntu@master.$domain"
fi