-
Notifications
You must be signed in to change notification settings - Fork 11
/
get-wecube.sh
executable file
·257 lines (206 loc) · 8.55 KB
/
get-wecube.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
255
256
257
#!/bin/bash
SECONDS=0
SCRIPT_DIR=$(realpath $(dirname "$0"))
INSTALLER_LOG_DIR="./installer-logs"
mkdir -p $INSTALLER_LOG_DIR
set -e
trap 'catch $? $LINENO' EXIT
catch() {
[ "$1" == '0' ] && exit 0
echo -e "\n\e[0;31mError occurred during installation at line $2.\e[0m\n"
pushd $SCRIPT_DIR >/dev/null
LOG_COLLECT_DIR=$(realpath "$INSTALLER_LOG_DIR")
echo -e "\n\e[0;33mCollecting WeCube logs into \"$LOG_COLLECT_DIR\"...\e[0m"
cp -R $SCRIPT_DIR/out.log $WECUBE_HOME/logs/* $LOG_COLLECT_DIR/
cp -R $WECUBE_HOME/wecmdb/log/* $LOG_COLLECT_DIR/wecmdb/
cp -R $WECUBE_HOME/monitor/logs/* $LOG_COLLECT_DIR/monitor/
LOG_FILE_ARCHIVE="wecube-logs.tar.gz"
tar czvf $LOG_FILE_ARCHIVE $INSTALLER_LOG_DIR
echo "WeCube installation logs saved to file ${LOG_FILE_ARCHIVE}"
popd >/dev/null
exit 1
}
echo -e "\nPlease specify the configuration parameters for WeCube installation.\n"
#### Configuration Section ####
INSTALL_TARGET_HOST_DEFAULT='127.0.0.1'
WECUBE_RELEASE_VERSION_DEFAULT='latest'
WECUBE_SETTINGS_DEFAULT='standard'
WECUBE_HOME_DEFAULT='/data/wecube'
WECUBE_USER_DEFAULT='root'
INITIAL_PASSWORD_DEFAULT='Wecube@123456'
USE_MIRROR_IN_MAINLAND_CHINA_DEFAULT='true'
#### End of Configuration Section ####
read -p "- Host [$INSTALL_TARGET_HOST_DEFAULT]: " INSTALL_TARGET_HOST
INSTALL_TARGET_HOST=${INSTALL_TARGET_HOST:-$INSTALL_TARGET_HOST_DEFAULT}
read -p "- WeCube release version (latest, v2.7.0, ...) [$WECUBE_RELEASE_VERSION_DEFAULT]: " WECUBE_RELEASE_VERSION
WECUBE_RELEASE_VERSION=${WECUBE_RELEASE_VERSION:-$WECUBE_RELEASE_VERSION_DEFAULT}
read -p "- WeCube settings (standard, bootcamp, empty, init) [$WECUBE_SETTINGS_DEFAULT]: " WECUBE_SETTINGS
WECUBE_SETTINGS=${WECUBE_SETTINGS:-$WECUBE_SETTINGS_DEFAULT}
read -p "- WeCube installation directory [$WECUBE_HOME_DEFAULT]: " WECUBE_HOME
WECUBE_HOME=${WECUBE_HOME:-$WECUBE_HOME_DEFAULT}
read -p "- User to run WeCube [$WECUBE_USER_DEFAULT]: " WECUBE_USER
WECUBE_USER=${WECUBE_USER:-$WECUBE_USER_DEFAULT}
read -s -p "- User password (As initial password for MySQL root) [$INITIAL_PASSWORD_DEFAULT]: " INITIAL_PASSWORD_1 && echo ""
[ -n "$INITIAL_PASSWORD_1" ] && read -s -p "Please re-enter the password to confirm: " INITIAL_PASSWORD_2 && echo ""
[ -n "$INITIAL_PASSWORD_1" ] && [ "$INITIAL_PASSWORD_1" != "$INITIAL_PASSWORD_2" ] && echo 'Inputs do not match!' && exit 1
INITIAL_PASSWORD=${INITIAL_PASSWORD_1:-$INITIAL_PASSWORD_DEFAULT}
read -p "- Should use mirror sites in Mainland China [$USE_MIRROR_IN_MAINLAND_CHINA_DEFAULT]: " USE_MIRROR_IN_MAINLAND_CHINA
USE_MIRROR_IN_MAINLAND_CHINA=${USE_MIRROR_IN_MAINLAND_CHINA:-$USE_MIRROR_IN_MAINLAND_CHINA_DEFAULT}
echo -e "\nPlease review the following configuration:\n"
cat <<-EOF | tee "$INSTALLER_LOG_DIR/input-params.log"
- INSTALL_TARGET_HOST = ${INSTALL_TARGET_HOST}
- WECUBE_RELEASE_VERSION = ${WECUBE_RELEASE_VERSION}
- WECUBE_SETTINGS = ${WECUBE_SETTINGS}
- WECUBE_HOME = ${WECUBE_HOME}
- WECUBE_USER = ${WECUBE_USER}
- INITIAL_PASSWORD = (*hidden*)
- USE_MIRROR_IN_MAINLAND_CHINA = ${USE_MIRROR_IN_MAINLAND_CHINA}
EOF
echo ""
read -p "Continue? [y/Y] " -n 1 -r && echo ""
[[ ! $REPLY =~ ^[Yy]$ ]] && echo "Installation aborted." && exit 1
sudo mkdir -p $WECUBE_HOME
sudo chown -R $USER:$USER $WECUBE_HOME
INSTALLER_URL="https://github.com/WeBankPartners/delivery-by-terraform/archive/master.zip"
INSTALLER_PKG="$WECUBE_HOME/wecube-installer.zip"
INSTALLER_DIR="$WECUBE_HOME/installer"
INSTALLER_SOURCE_CODE_DIR="$WECUBE_HOME/delivery-by-terraform-master/installer"
if [ "$USE_MIRROR_IN_MAINLAND_CHINA" == "true" ]; then
echo 'Using Gitee as mirror for WeCube code repository in Mainland China.'
INSTALLER_URL="https://gitee.com/WeBankPartners/delivery-by-terraform/repository/archive/master.zip"
INSTALLER_SOURCE_CODE_DIR="$WECUBE_HOME/delivery-by-terraform-master/installer"
fi
echo -e "\nFetching WeCube installer from \"$INSTALLER_URL\"..."
RETRIES=30
while [ $RETRIES -gt 0 ]; do
if $(curl --connect-timeout 30 --speed-time 30 --speed-limit 1000 -fL $INSTALLER_URL -o $INSTALLER_PKG); then
break
else
RETRIES=$((RETRIES - 1))
PAUSE=$(( ( RANDOM % 5 ) + 1 ))
echo "Retry in $PAUSE seconds, $RETRIES times remaining..."
sleep "$PAUSE"
fi
done
[ $RETRIES -eq 0 ] && echo 'Failed to fetch installer package! Installation aborted.' && exit 1
# install yum packages
yum install epel-release -y
yum install unzip jq -y
unzip -o -q $INSTALLER_PKG -d $WECUBE_HOME
cp -R $INSTALLER_SOURCE_CODE_DIR $WECUBE_HOME
[ -f $WECUBE_RELEASE_VERSION ] && \
cp $WECUBE_RELEASE_VERSION "$INSTALLER_DIR/wecube-platform/" && \
cp $WECUBE_RELEASE_VERSION "$INSTALLER_DIR/wecube-system-settings/"
echo -e "\nRunning WeCube installer scripts...\n"
pushd $INSTALLER_DIR >/dev/null
read -d '' BASE_ENV <<-EOF || true
DATE_TIME='$(date --rfc-3339=seconds)'
HOST_PRIVATE_IP='${INSTALL_TARGET_HOST}'
WECUBE_RELEASE_VERSION='${WECUBE_RELEASE_VERSION}'
WECUBE_SETTINGS='${WECUBE_SETTINGS}'
WECUBE_HOME='${WECUBE_HOME}'
WECUBE_USER='${WECUBE_USER}'
INITIAL_PASSWORD='${INITIAL_PASSWORD}'
USE_MIRROR_IN_MAINLAND_CHINA='${USE_MIRROR_IN_MAINLAND_CHINA}'
EOF
INSTALLATION_PARAMS_ENV_FILE="$INSTALLER_DIR/installation-params.env"
(umask 066 && cat <<-EOF >"$INSTALLATION_PARAMS_ENV_FILE"
${BASE_ENV}
EOF
)
./invoke-installer.sh "$INSTALLATION_PARAMS_ENV_FILE" params-validator
PROVISIONING_ENV_FILE="$INSTALLER_DIR/provisioning.env"
(umask 066 && cat <<-EOF >"$PROVISIONING_ENV_FILE"
${BASE_ENV}
DOCKER_PORT=2375
S3_PORT=9000
S3_ACCESS_KEY=access_key
S3_SECRET_KEY=secret_key
MYSQL_PORT=3307
MYSQL_USERNAME=root
MYSQL_PASSWORD='${INITIAL_PASSWORD}'
EOF
)
./invoke-installer.sh "$PROVISIONING_ENV_FILE" wecube-user docker mysql-docker minio-docker open-monitor-agent
WECUBE_DB_ENV_FILE="$INSTALLER_DIR/db-deployment-wecube-db-standalone.env"
(umask 066 && cat <<-EOF >"$WECUBE_DB_ENV_FILE"
${BASE_ENV}
DB_HOST='${INSTALL_TARGET_HOST}'
DB_PORT=3307
DB_NAME=wecube
DB_USERNAME=root
DB_PASSWORD='${INITIAL_PASSWORD}'
WECUBE_RELEASE_VERSION='${WECUBE_RELEASE_VERSION}'
EOF
)
./invoke-installer.sh "$WECUBE_DB_ENV_FILE" db-connectivity
AUTH_SERVER_DB_ENV_FILE="$INSTALLER_DIR/db-deployment-auth-server-db-standalone.env"
(umask 066 && cat <<-EOF >"$AUTH_SERVER_DB_ENV_FILE"
${BASE_ENV}
DB_HOST='${INSTALL_TARGET_HOST}'
DB_PORT=3307
DB_NAME=auth_server
DB_USERNAME=root
DB_PASSWORD='${INITIAL_PASSWORD}'
EOF
)
./invoke-installer.sh "$AUTH_SERVER_DB_ENV_FILE" db-connectivity
WECUBE_PLATFORM_ENV_FILE="$INSTALLER_DIR/app-deployment-wecube-platform-standalone.env"
(umask 066 && cat <<-EOF >"$WECUBE_PLATFORM_ENV_FILE"
${BASE_ENV}
STATIC_RESOURCE_HOSTS='${INSTALL_TARGET_HOST}'
S3_HOST='${INSTALL_TARGET_HOST}'
CORE_DB_HOST='${INSTALL_TARGET_HOST}'
CORE_DB_PORT=3307
CORE_DB_NAME=wecube
CORE_DB_USERNAME=root
CORE_DB_PASSWORD='${INITIAL_PASSWORD}'
AUTH_SERVER_DB_HOST='${INSTALL_TARGET_HOST}'
AUTH_SERVER_DB_PORT=3307
AUTH_SERVER_DB_NAME=auth_server
AUTH_SERVER_DB_USERNAME=root
AUTH_SERVER_DB_PASSWORD='${INITIAL_PASSWORD}'
EOF
)
./invoke-installer.sh "$WECUBE_PLATFORM_ENV_FILE" wecube-platform
WECUBE_PLUGIN_HOSTING_ENV_FILE="$INSTALLER_DIR/app-deployment-wecube-plugin-hosting-standalone.env"
(umask 066 && cat <<-EOF >"$WECUBE_PLUGIN_HOSTING_ENV_FILE"
${BASE_ENV}
CORE_HOST='${INSTALL_TARGET_HOST}'
EOF
)
./invoke-installer.sh "$WECUBE_PLUGIN_HOSTING_ENV_FILE" wecube-plugin-hosting
WECUBE_SYSTEM_SETTINGS_ENV_FILE="$INSTALLER_DIR/app-deployment-wecube-system-settings-standalone.env"
(umask 066 && cat <<-EOF >"$WECUBE_SYSTEM_SETTINGS_ENV_FILE"
${BASE_ENV}
S3_ACCESS_KEY=access_key
S3_SECRET_KEY=secret_key
AGENT_S3_BUCKET_NAME=wecube-agent
ARTIFACTS_S3_BUCKET_NAME=wecube-artifacts
CORE_HOST='${INSTALL_TARGET_HOST}'
S3_HOST='${INSTALL_TARGET_HOST}'
PLUGIN_HOST='${INSTALL_TARGET_HOST}'
PORTAL_ENTRYPOINT='${INSTALL_TARGET_HOST}'
GATEWAY_ENTRYPOINT='${INSTALL_TARGET_HOST}'
CORE_DB_HOST='${INSTALL_TARGET_HOST}'
CORE_DB_PORT=3307
CORE_DB_NAME=wecube
CORE_DB_USERNAME=root
CORE_DB_PASSWORD='${INITIAL_PASSWORD}'
AUTH_SERVER_DB_HOST='${INSTALL_TARGET_HOST}'
AUTH_SERVER_DB_PORT=3307
AUTH_SERVER_DB_NAME=auth_server
AUTH_SERVER_DB_USERNAME=root
AUTH_SERVER_DB_PASSWORD='${INITIAL_PASSWORD}'
PLUGIN_DB_HOST='${INSTALL_TARGET_HOST}'
PLUGIN_DB_PORT=3307
PLUGIN_DB_NAME=mysql
PLUGIN_DB_USERNAME=root
PLUGIN_DB_PASSWORD='${INITIAL_PASSWORD}'
EOF
)
./invoke-installer.sh "$WECUBE_SYSTEM_SETTINGS_ENV_FILE" wecube-system-settings
popd >/dev/null
ELAPSED_TIME="$((${SECONDS}/60))m$((${SECONDS}%60))s"
echo -e "\n\n\e[0;32mWeCube installation completed in ${ELAPSED_TIME}.\e[0m"
echo -e "\n\e[0;32mPlease visit WeCube at http://${INSTALL_TARGET_HOST}:19090\e[0m\n"