-
Notifications
You must be signed in to change notification settings - Fork 0
/
local-trial
executable file
·252 lines (210 loc) · 7.78 KB
/
local-trial
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
#!/usr/bin/env bash
# NB: local trial script has to be self-contained
# See https://sipb.mit.edu/doc/safe-shell/
set -euf -o pipefail
if [[ "$OSTYPE" == "linux-gnu" ]]; then
export MAYBE_SUDO="sudo"
else
export MAYBE_SUDO=""
fi
if [ -t 1 ]; then
export NORMAL="$(tput sgr0)"
export RED="$(tput setaf 1)"
export GREEN="$(tput setaf 2)"
export MAGENTA="$(tput setaf 5)"
export CYAN="$(tput setaf 6)"
export WHITE="$(tput setaf 7)"
export BOLD="$(tput bold)"
else
export NORMAL=""
export RED=""
export GREEN=""
export MAGENTA=""
export CYAN=""
export WHITE=""
export BOLD=""
fi
error_exit() {
echo "${RED}${BOLD}ERROR${NORMAL}${BOLD}: $1${NORMAL}"
shift
while [ "$#" -gt "0" ]; do
echo " - $1"
shift
done
exit 1
}
log_step() {
echo ''
echo "${GREEN}${BOLD}INFO${NORMAL}${BOLD}: $1${NORMAL}"
shift
while [ "$#" -gt "0" ]; do
echo " - $1"
shift
done
}
log_warn() {
echo ''
echo "${GREEN}${BOLD}INFO${NORMAL}${BOLD}: $1${NORMAL}"
shift
while [ "$#" -gt "0" ]; do
echo " - $1"
shift
done
}
export DISTRO=$( (lsb_release -ds || cat /etc/*release || uname -om) 2>/dev/null | head -n1)
command_present() {
type "$1" >/dev/null 2>&1
}
retool_containers_present() {
# NB: awk is to remove whitespace from `wc`
RETOOL_IMAGES="$($MAYBE_SUDO docker image ls | grep 'retool-onpremise' | wc -l | awk '{print $1}')"
test "$RETOOL_IMAGES" -gt '0'
}
retool_trial_running() {
# NB: awk is to remove whitespace from `wc`
CONTAINERS="$($MAYBE_SUDO docker-compose ps -q | wc -l | awk '{print $1}')"
test "$CONTAINERS" -gt '0'
}
# NB: trim trailing slash on $TMPDIR as different OS's do it differently
INSTALL_DIRECTORY="$HOME/retool"
DOCKER_CONTEXT="$INSTALL_DIRECTORY/retool-onpremise"
cd "$HOME"
if [ ! -d "$DOCKER_CONTEXT" ]; then
if [ -d "$INSTALL_DIRECTORY" ]; then
log_step 'found a partial install, cleaning it up...'
rm -rf "$INSTALL_DIRECTORY"
fi
log_step 'setting up install location...' "$INSTALL_DIRECTORY"
mkdir retool && cd retool
if ! command_present unzip; then
log_warn '`unzip` not found!'
log_warn 'Attempting to git clone instead'
if command_present git; then
log_step 'cloning...'
git clone https://github.com/tryretool/retool-onpremise.git
elif command_present yum; then
log_warn 'You did not have git so installing'
sudo yum install git
git clone https://github.com/tryretool/retool-onpremise.git
else
error_exit "Please install git or unzip before continuing"
fi
else
log_step 'downloading...'
curl -L -XGET -o master.zip https://github.com/tryretool/retool-onpremise/archive/master.zip
log_step 'unpacking...'
unzip master.zip
mv retool-onpremise-master retool-onpremise
fi
# NB: this is to make onprem containers to all get named the same.
cd retool-onpremise
DOCKER_CONTEXT="$(pwd)"
log_step 'setting environment variables'
cp ./docker.env.trial docker.env
if ! command_present docker; then
# shellcheck disable=2016
log_warn '`docker` not found! Attempting to install. This may take a few minutes.'
./get-docker.sh
if ! command_present docker; then
if [[ "$OSTYPE" == "darwin"* ]]; then
error_exit "please install \`docker\` manually" \
"Instructions can be found at ${WHITE}${BOLD}https://docs.docker.com/${NORMAL}" \
"${BOLD}Remember${NORMAL} to start the \`Docker\` app from the UI."
else
error_exit "please install \`docker\` manually" \
"Instructions can be found at ${WHITE}${BOLD}https://docs.docker.com/${NORMAL}" \
"${BOLD}Remember${NORMAL} to start the \`docker\` daemon/service."
fi
fi
else
# shellcheck disable=2016
log_step '`docker` found!'
fi
if ! command_present docker-compose; then
# shellcheck disable=2016
log_warn '`docker-compose` not found! Attempting to install'
./get-docker-compose.sh
if ! command_present docker-compose; then
if [[ "$OSTYPE" == "darwin"* ]]; then
error_exit "please install \`docker-compose\` manually" \
"Usually, \`docker\` and \`docker-compose\` are bundled together, consider uninstalling your existing docker implementation" \
"Instructions can be found at ${WHITE}${BOLD}https://docs.docker.com/${NORMAL}" \
"${BOLD}Remember${NORMAL} to start the \`Docker\` app and wait for it to be ${GREEN}${BOLD}READY${NORMAL}."
else
error_exit "please install \`docker-compose\` manually" \
"Usually, \`docker\` and \`docker-compose\` are bundled together, consider uninstalling your existing docker implementation" \
"Instructions can be found at ${WHITE}${BOLD}https://docs.docker.com/${NORMAL}" \
"${BOLD}Remember${NORMAL} to start the \`docker\` daemon/service and wait for it to be ${GREEN}${BOLD}READY${NORMAL}."
fi
fi
else
# shellcheck disable=2016
log_step '`docker-compose` found!'
fi
if [[ $DISTRO == *"CentOS"* ]]; then
echo 'Starting docker service and making compose accessible by root user'
if [ ! -f /usr/bin/docker-compose ]; then
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
sudo systemctl enable docker.service
sudo systemctl start docker.service
fi
if retool_containers_present; then
log_step 'noticed you have tried Retool before, cleaning up...'
$MAYBE_SUDO docker-compose rm -fsv
fi
else
cd "$DOCKER_CONTEXT" || error_exit "Couldn't \`cd\` into '$DOCKER_CONTEXT'" \
"if you are having repeat issues, you can \`rm -rf $INSTALL_DIRECTORY\`" \
"if you're still having issues, you can stop all docker containers using the \`docker\` command"
fi
if (! $MAYBE_SUDO docker stats --no-stream) && [ "$OSTYPE" == "linux-gnu" ] && [ "$DISTRO" != "*centos*" ]; then
sudo docker service start
fi
if retool_trial_running; then
log_step 'stopping Retool for update...'
$MAYBE_SUDO docker-compose down
fi
if [ ! -f ./docker-compose-ssl.yml ]; then
mv docker-compose.yml docker-compose-ssl.yml
fi
if [ -f ./docker-compose-local-trial.yml ]; then
mv docker-compose-local-trial.yml docker-compose.yml
fi
log_step 'updating Retool!'
$MAYBE_SUDO docker-compose pull
log_step "running Retool! ${WHITE}${BOLD}This can take up to 5 minutes${NORMAL}"
$MAYBE_SUDO docker-compose up -d
echo ""
echo " -- ${GREEN}${BOLD}!! RETOOL IS BOOTING !!${NORMAL} --"
# NB: the API doesn't start up the first time, this is why the below is complex
WAITED=0
api_running() {
API_DOCKER_CONTAINER="$($MAYBE_SUDO docker ps | grep 'retool-onpremise_api')"
test -n "$API_DOCKER_CONTAINER"
}
printf "%s%s%s%s" "Waiting for Retool to start up... " "${RED}${BOLD}" "<Pressing Ctrl-C may prevent proper start-up>" "$NORMAL"
while [ $WAITED -lt 20 ] && api_running; do
WAITED=$((WAITED + 1))
sleep 1
done
if ! api_running; then
$MAYBE_SUDO docker-compose up -d > /dev/null 2>&1
WAITED=0
while [ $WAITED -lt 10 ] && ! api_running; do
WAITED=$((WAITED + 1))
sleep 1
done
fi
# NB: empty stuff to fully wipe out previous line completely
printf "\r%s%s%s%s%s%s%s%s" "$MAGENTA" 'Check out your ' "$BOLD" 'BROWSER' "${NORMAL}${MAGENTA}" ' for some awesomeness!!!' "$NORMAL" ' '
echo
echo ""
echo " ${CYAN}Navigate to${NORMAL}: ${WHITE}${BOLD}http://localhost:3000/auth/signup${NORMAL} or ${WHITE}${BOLD}[publically_accessible_ip]:3000/auth/signup${NORMAL}"
echo " ${CYAN}To STOP Retool, run${NORMAL}: ${WHITE}${BOLD}${DOCKER_CONTEXT}/stop-local-trial${NORMAL}"
echo " ${CYAN}To RESTART Retool, run${NORMAL}: ${WHITE}${BOLD}${DOCKER_CONTEXT}/local-trial${NORMAL}"
echo ""
echo "Retool was installed in ~/retool. It will run in the background until you manually stop it. If Retool stops you can restart it without losing your data. "
if command_present open; then
open 'http://localhost:3000/auth/signup'
fi