This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 574
/
quickstart.sh
executable file
·254 lines (215 loc) · 6.79 KB
/
quickstart.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
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
#!/bin/bash -e
echo '
### ######## ####### ########
## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
## ## ## ## ## ## ########
######### ## ## ## ## ##
## ## ## ## ## ## ##
## ## ######## ####### ##
'
echo '
*****************************************************
* EVALUATION MODE *
*****************************************************
* Quickstart is designed to get you up and running *
* with the DevOps Platform as quickly as possible. *
* As such it is not a "production" ready deployment *
* and therefore we brand it as "evaluation mode". *
* In using quickstart you are acknowledging this, *
* along with the lack of proper security, backups, *
* patching, and other operational considerations. *
*****************************************************
'
usage(){
cat <<END_USAGE
Usage:
./quickstart.sh
-t local
[-m <MACHINE_NAME>]
[-u <INITIAL_ADMIN_USER>]
[-p <INITIAL_ADMIN_PASSWORD>]
./quickstart.sh
-t aws
-m <MACHINE_NAME>
-c <AWS_VPC_ID>
-r <AWS_DEFAULT_REGION>
[-z <AVAILABILITY_ZONE_LETTER>]
[-a <AWS_ACCESS_KEY>]
[-s <AWS_SECRET_ACCESS_KEY>]
[-u <INITIAL_ADMIN_USER>]
[-p <INITIAL_ADMIN_PASSWORD>]
END_USAGE
}
provision_local() {
if [ -z ${MACHINE_NAME} ]; then
MACHINE_NAME=adop
fi
# Allow script to continue if error returned by docker-machine command
set +e
# Create Docker machine if one doesn't already exist with the same name
docker-machine ip ${MACHINE_NAME} > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Docker machine '$MACHINE_NAME' already exists"
else
# To run adop stack locally atleast 6144 MB is required.
docker-machine create --driver virtualbox --virtualbox-memory 6144 ${MACHINE_NAME}
fi
# Reenable errexit
set -e
}
# Function to create AWS-specific environment variables file
source_aws() {
AWS_FILE='./conf/provider/env.provider.aws.sh'
if [ -f ${AWS_FILE} ]; then
echo "Your AWS parameters file already exists, deleting it..."
rm -f ${AWS_FILE}
fi
echo "Creating a new AWS variables file..."
cp ./conf/provider/examples/env.provider.aws.sh.example ${AWS_FILE}
# AWS-specific environment variables
if [ -z ${AWS_VPC_ID} ]; then
usage
exit 1
else
sed -i'' -e "s/###AWS_VPC_ID###/$AWS_VPC_ID/g" ${AWS_FILE}
fi
if [ -z ${AWS_KEYPAIR} ]; then
sed -i'' -e "s/###AWS_KEYPAIR###/$MACHINE_NAME/g" ${AWS_FILE}
else
sed -i'' -e "s/###AWS_KEYPAIR###/$AWS_KEYPAIR/g" ${AWS_FILE}
fi
if [ -z ${AWS_INSTANCE_TYPE} ]; then
sed -i'' -e "s/###AWS_INSTANCE_TYPE###/t2.large/g" ${AWS_FILE}
else
sed -i'' -e "s/###AWS_INSTANCE_TYPE###/$AWS_INSTANCE_TYPE/g" ${AWS_FILE}
fi
if [ -z ${AWS_SUBNET_ID} ]; then
sed -i'' -e "s/###AWS_SUBNET_ID###/default/g" ${AWS_FILE}
else
sed -i'' -e "s/###AWS_SUBNET_ID###/$AWS_SUBNET_ID/g" ${AWS_FILE}
fi
sed -i'' -e "s/###AWS_DEFAULT_REGION###/$AWS_DEFAULT_REGION/g" ${AWS_FILE}
}
provision_aws() {
if [ -z ${MACHINE_NAME} ] | \
[ -z ${AWS_VPC_ID} ] | \
[ -z ${AWS_DEFAULT_REGION} ]; then
echo "ERROR: Mandatory parameters missing!"
usage
exit 1
fi
if [ -z ${VPC_AVAIL_ZONE} ]; then
echo "No availability zone specified - using default [a]."
export VPC_AVAIL_ZONE=a
elif [[ ! ${VPC_AVAIL_ZONE} =~ ^[a-e]{1,1}$ ]]; then
echo "Availability zone can only be a single lower case char, 'a' to 'e'. Exiting..."
exit 1
fi
if [ -z ${AWS_ACCESS_KEY_ID} ];
then
echo "WARN: AWS_ACCESS_KEY_ID not set (externally or with -a), delegating to Docker Machine"
fi
if [ -z ${AWS_SECRET_ACCESS_KEY} ];
then
echo "WARN: AWS_SECRET_ACCESS_KEY not set (externally or with -s), delegating to Docker Machine"
fi
if [ -z ${AWS_DOCKER_MACHINE_SIZE} ]; then
export AWS_DOCKER_MACHINE_SIZE="m4.xlarge"
fi
# Create a file with AWS parameters
source_aws
# Allow script to continue if error returned by docker-machine command
set +e
# Create Docker machine if one doesn't already exist with the same name
docker-machine ip ${MACHINE_NAME} > /dev/null 2>&1
rc=$?
# Reenable errexit
set -e
if [ ${rc} -eq 0 ]; then
echo "Docker machine '$MACHINE_NAME' already exists"
else
MACHINE_CREATE_CMD="docker-machine create \
--driver amazonec2 \
--amazonec2-vpc-id ${AWS_VPC_ID} \
--amazonec2-zone $VPC_AVAIL_ZONE \
--amazonec2-instance-type ${AWS_DOCKER_MACHINE_SIZE} \
--amazonec2-root-size ${AWS_ROOT_SIZE:-32}"
if [ -n "${AWS_ACCESS_KEY_ID}" ] && [ -n "${AWS_SECRET_ACCESS_KEY}" ] && [ -n "${AWS_DEFAULT_REGION}" ]; then
MACHINE_CREATE_CMD="${MACHINE_CREATE_CMD} \
--amazonec2-access-key ${AWS_ACCESS_KEY_ID} \
--amazonec2-secret-key ${AWS_SECRET_ACCESS_KEY} \
--amazonec2-region ${AWS_DEFAULT_REGION}"
fi
MACHINE_CREATE_CMD="${MACHINE_CREATE_CMD} ${MACHINE_NAME}"
${MACHINE_CREATE_CMD}
fi
}
while getopts "t:m:a:s:c:z:r:u:p:h" opt; do
case ${opt} in
t)
export MACHINE_TYPE=${OPTARG}
;;
m)
export MACHINE_NAME=${OPTARG}
;;
a)
export AWS_ACCESS_KEY_ID=${OPTARG}
;;
s)
export AWS_SECRET_ACCESS_KEY=${OPTARG}
;;
c)
export AWS_VPC_ID=${OPTARG}
;;
z)
export VPC_AVAIL_ZONE=${OPTARG}
;;
r)
export AWS_DEFAULT_REGION=${OPTARG}
;;
u)
export INITIAL_ADMIN_USER=${OPTARG}
;;
p)
export INITIAL_ADMIN_PASSWORD_PLAIN=${OPTARG}
;;
h)
usage
exit
;;
*)
echo "Invalid parameter(s) or option(s)."
usage
exit 1
;;
esac
done
if [ -z ${MACHINE_TYPE} ]; then
echo "Please specify a machine type to create during quickstart"
usage
exit 1
fi
CLI_COMPOSE_OPTS=""
# Switch based on the machine type
case ${MACHINE_TYPE} in
"local")
provision_local
;;
"aws")
provision_aws
CLI_COMPOSE_OPTS="-f etc/aws/default.yml"
;;
*)
echo "Invalid parameter(s) or option(s)."
usage
exit 1
;;
esac
# Use the ADOP CLI
eval $(docker-machine env ${MACHINE_NAME})
./adop compose -m "${MACHINE_NAME}" ${CLI_COMPOSE_OPTS} init
# Generate and export Self-Signed SSL certificate for Docker Registry, applicable only for AWS type
if [ ${MACHINE_TYPE} == "aws" ]; then
./adop certbot gen-export-certs "registry.$(docker-machine ip ${MACHINE_NAME}).nip.io" registry
fi