-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·155 lines (137 loc) · 4.27 KB
/
install
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
#!/usr/bin/env bash
set -euo pipefail
# generate [N] generates a random alphabetical string of length N (defaults to 20).
generate() {
LC_ALL=C tr -dc 'a-zA-Z' < /dev/urandom | head -c"${1:-20}" || test $? -eq 141 ;
echo "";
}
# die [LINES...] exits with an error message
die() {
echo "Failed to start MatchMiner:"
for LINE in "$@"
do
echo "$LINE"
done
exit 1
}
# wait_for_url [URL] waits for URL to become available
wait_for_url() {
curl --fail \
--location \
--max-time 1 \
--retry 30 \
--retry-delay 1 \
--retry-connrefused \
--silent \
--show-error \
--output /dev/null \
"$1"
}
# Ensure that docker is installed:
if ! which docker >/dev/null
then
die 'docker is not installed'
fi
# Ensure that docker-compose is installed:
if ! which docker-compose >/dev/null
then
die 'docker-compose is not installed'
fi
# Ensure that we can connect to Docker:
ERRS="$(docker info --format '{{range .ServerErrors}}{{.}}{{end}}' 2>&1)"
if ! test -z "$ERRS"
then
die 'cannot connect to docker:' "$ERRS"
fi
# Disable annoying Docker message:
export DOCKER_SCAN_SUGGEST=false
# MATCHMINER_BUILD_PATH, if set, will cause us to rebuild the Docker images
# from repositories in the specified path:
if test -n "${MATCHMINER_BUILD_PATH:-}"
then
pushd "$MATCHMINER_BUILD_PATH" >/dev/null
MATCHMINER_BUILD_PATH="$(pwd)"
popd > /dev/null
else
MATCHMINER_BUILD_PATH=""
fi
# Start setup; cd into the path of this script:
if test -z "${BASH_SOURCE[0]:-}"
then
die 'failed to find script path'
fi
pushd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null
# Take down any existing services:
echo 'Taking down MatchMiner if it is already running...'
docker-compose down --remove-orphans --volumes --timeout 5 --rmi local
# Pull images, create containers, and start:
# (This is basically the same as docker-compose up)
echo 'Pulling latest versions of images...'
# Note: we don't use "docker-compose pull" for this because it won't set the
# platform correctly.
docker pull --platform linux/x86_64 'elasticsearch:6.8.12'
docker pull 'mongo:6.0-focal'
docker pull --platform linux/x86_64 'matchminer/matchminer-api:latest'
docker pull --platform linux/x86_64 'matchminer/matchminer-ui:latest'
if test -n "$MATCHMINER_BUILD_PATH"
then
echo "Performing build from ${MATCHMINER_BUILD_PATH}..."
MATCHMINER_BUILD_PATH="$MATCHMINER_BUILD_PATH" docker-compose build
else
echo "Not rebuilding images..."
fi
echo 'Creating containers...'
docker-compose create --pull never --no-build
echo 'Starting containers...'
docker-compose start
# Wait for MongoDB to start:
echo 'Waiting for MongoDB to start...'
START_WAIT="$SECONDS"
# Note: MongoDB will bind to localhost immediately, but it won't bind to 'mongo' until setup is done
while ! docker-compose exec mongo mongosh --quiet --eval ";" mongodb://mongo:27017 >/dev/null 2>/dev/null
do
sleep 1
if test "$((SECONDS - START_WAIT))" -ge 120
then
echo "MongoDB failed to start; check docker-compose logs to debug"
exit 1
fi
done
echo "Restarting MatchMiner API..."
docker-compose restart matchminer-api
# Wait for MatchMiner to be ready:
echo "Waiting for MatchMiner UI to become ready..."
if ! wait_for_url http://localhost:1952
then
die "Startup failed! Check docker-compose logs to debug..."
fi
echo "Waiting for MatchMiner API to become ready..."
if ! wait_for_url http://localhost:1952/api/info
then
die "Startup failed! Check docker-compose logs to debug..."
fi
echo "Waiting for MatchMiner ElasticSearch to become ready..."
if ! wait_for_url http://localhost:1952/api/es/_nodes/_local
then
die "Startup failed! Check docker-compose logs to debug..."
fi
echo "Resetting elasticsearch..."
curl --netrc-file ./netrc --fail --location --silent --show-error --output /dev/null -X POST http://localhost:1952/api/reset_elasticsearch
# Notify user:
echo "MatchMiner started successfully!"
echo "The UI is now available at: http://localhost:1952"
echo "To manage services, enter the directory '$(pwd)' and run docker-compose."
if test "${MATCHMINER_NO_OPEN_BROWSER:-}" = "1"
then
echo "Not opening browser!"
elif which xdg-open >/dev/null 2>/dev/null
then
echo "Opening browser..."
xdg-open http://localhost:1952
elif test "$(uname -s)" = "Darwin"
then
echo "Opening browser..."
open http://localhost:1952
fi
# Setup complete!
popd >/dev/null