forked from jet-admin/jet-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_jet.sh
executable file
·242 lines (205 loc) · 5.52 KB
/
install_jet.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
#!/bin/sh
set -e
# Jet Bridge
# https://github.com/jet-admin/jet-bridge
#
# This script is meant for quick & easy install via:
#
# sh <(curl -s https://app.jetadmin.io/install_jet.sh)
PROJECT=$1
TOKEN=$2
ENVIRONMENT=$3
if [ "$(uname)" = "Darwin" ]; then
MAC=1
else
MAC=0
fi
WIN=0
case $(uname -s) in CYGWIN*)
WIN=1
esac
if [ $WIN -eq 1 ] || [ $MAC -eq 1 ]; then
NET="bridge"
else
NET="host"
fi
check_arguments() {
if [ -z $PROJECT ]; then
echo
echo "ERROR:"
echo " Pass project as an argument"
echo
exit 1
fi
if [ -z $TOKEN ]; then
echo
echo "ERROR:"
echo " Pass token as an argument"
echo
exit 1
fi
}
remove_container() {
docker rm --force ${CONTAINER_NAME} >/dev/null 2>&1 || true
}
check_is_docker_installed() {
# Check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo
echo "ERROR:"
echo " Docker is not found on your system"
echo " Install Docker by running the following command:"
echo
echo " sh <(curl -s https://get.docker.com)"
echo
echo " or follow official documentation"
echo
echo " https://docs.docker.com/install/"
echo
exit 1
fi
}
check_is_docker_running() {
# Check if docker is running
docker info >/dev/null 2>&1 && { docker_state=1; } || { docker_state=0; }
if [ $docker_state != 1 ]; then
echo
echo "ERROR:"
echo " Docker does not seem to be running or you don't have permissions"
echo
if [ "$(id -u)" -ne 0 ]; then
echo " [!] Try running this script with sudo:"
echo
echo " curl -s https://app.jetadmin.io/install_jet.sh -o install_jet.sh"
echo " sudo sh install_jet.sh ${PROJECT} ${TOKEN} ${ENVIRONMENT}"
echo
fi
exit 1
fi
}
fetch_latest_jet_bridge() {
echo
echo " Fetching latest Jet Bridge image..."
echo
docker pull jetadmin/jetbridge:latest
}
prepare_container() {
echo
echo " Installing Jet Bridge as a Docker container..."
echo
read -p "Enter Docker container name or leave default [jet_bridge]: " CONTAINER_NAME
CONTAINER_NAME=${CONTAINER_NAME:-jet_bridge}
}
create_config() {
DATABASE_HOST=''
POSSIBLE_HOST=''
if [ $WIN -eq 1 ] || [ $MAC -eq 1 ]; then
remove_container
POSSIBLE_HOST=$(docker run \
--name=${CONTAINER_NAME} \
-it \
-v ${PWD}:/jet \
--entrypoint=/network-entrypoint.sh \
--net=host \
jetadmin/jetbridge:latest)
fi
if [ $POSSIBLE_HOST ]; then
DATABASE_HOST=" -e DATABASE_HOST=${POSSIBLE_HOST}"
fi
remove_container
docker run \
--name=${CONTAINER_NAME} \
-it \
-v ${PWD}:/jet \
-e PROJECT=${PROJECT} \
-e TOKEN=${TOKEN} \
-e ENVIRONMENT=${ENVIRONMENT} \
-e ENVIRONMENT_TYPE=docker \
${DATABASE_HOST} \
-e POSSIBLE_HOST=${POSSIBLE_HOST} \
-e ARGS=config \
--net=${NET} \
jetadmin/jetbridge:latest
}
run_instance() {
PORT=$(awk -F "=" '/^PORT=/ {print $2}' jet.conf)
SSL_CERT=$(awk -F "=" '/^SSL_CERT=/ {print $2}' jet.conf)
SSL_KEY=$(awk -F "=" '/^SSL_KEY=/ {print $2}' jet.conf)
CONFIG_FILE="${PWD}/jet.conf"
RUN_TIMEOUT=$(awk -F "=" '/^RUN_TIMEOUT=/ {print $2}' jet.conf)
RUN_TIMEOUT="${RUN_TIMEOUT:-10}"
echo
echo " Starting Jet Bridge..."
remove_container
docker run \
-p ${PORT}:${PORT} \
--name=${CONTAINER_NAME} \
-v ${PWD}:/jet \
--net=${NET} \
--restart=always \
-d \
jetadmin/jetbridge:latest \
1> /dev/null
if [ -n "$SSL_CERT" ] || [ -n "$SSL_KEY" ]; then
BASE_URL="https://localhost:${PORT}/api/"
else
BASE_URL="http://localhost:${PORT}/api/"
fi
REGISTER_URL="${BASE_URL}register/"
printf ' '
i=0
DELAY=1
TIMEOUT=10
i_last=$((TIMEOUT / DELAY))
until $(curl --output /dev/null --silent --fail ${BASE_URL}); do
printf '.'
sleep $DELAY
i=$((i+1))
if [ $i -ge $i_last ]; then
echo
echo
echo "ERROR:"
echo " Jet Bridge failed to start after timeout (${TIMEOUT}):"
echo
docker logs ${CONTAINER_NAME}
exit 1
fi
done
if command -v python >/dev/null 2>&1; then
python -mwebbrowser ${REGISTER_URL}
fi
echo
echo " To stop:"
echo " docker stop ${CONTAINER_NAME}"
echo
echo " To start:"
echo " docker start ${CONTAINER_NAME}"
echo
echo " To view logs:"
echo " docker logs -f ${CONTAINER_NAME}"
echo
echo " To view token:"
echo " docker exec -it ${CONTAINER_NAME} jet_bridge token"
echo
echo " Success! Jet Bridge is now running and will start automatically on system reboot"
echo
echo " Port: ${PORT}"
echo " Docker Container: ${CONTAINER_NAME}"
echo " Config File: ${CONFIG_FILE}"
echo
echo " Project: ${PROJECT}"
echo " Token: ${TOKEN}"
if [ -n "$ENVIRONMENT" ]; then
echo " Environment: ${ENVIRONMENT}"
fi
echo
echo " Open ${REGISTER_URL} to finish installation"
echo
}
check_arguments
check_is_docker_installed
check_is_docker_running
fetch_latest_jet_bridge
prepare_container
create_config
run_instance