-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo.sh
executable file
·174 lines (142 loc) · 4.14 KB
/
demo.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
#!/bin/sh
OS=`uname`
HOSTNAME=`hostname`
# Check if everything we need is there.
if [ $OS != "Linux" ] && [ $OS != "Darwin" ]; then
echo "Error: Only Linux or MacOS are supported."
exit 1;
fi
if ! type "docker" > /dev/null; then
echo "Error: You need to have docker installed."
exit 1;
fi
if ! type "docker-compose" > /dev/null; then
echo "Error: You need to have docker-compose installed."
exit 1;
fi
if ! type "java" > /dev/null; then
echo "Error: You need to have java installed."
exit 1;
fi
if ! type "curl" > /dev/null; then
echo "Error: You need to have curl installed."
exit 1;
fi
if [ "$OS" = "Darwin" ]; then
NATIVE_DOCKER_CMD=`docker ps`
NATIVE_DOCKER=`echo $?`
if [ $NATIVE_DOCKER -ne 0 ]; then
echo "Check if docker-machine is running."
if ! type "docker-machine" > /dev/null; then
echo "Error: You need to have docker-machine installed."
exit 1;
fi
DEFAULT_DOCKER_MACHINE=`docker-machine ls | grep default | grep Running | wc -l`
if [ $DEFAULT_DOCKER_MACHINE -eq 1 ]; then
HOSTNAME=`docker-machine ip default`
else
echo "Error: a docker-machine with the name 'default' must be running."
exit 1;
fi
else
echo "=================================================="
echo "You seem like to run docker mac beta. \n PLEASE MAKE SURE YOU HAVE ENABLED THE "
echo "\n\n EXPERIMENTAL VPN COMPATIBILITY MODE in the settings. \n\n\n"
echo "\n Press >ENTER< to continue \n"
echo "=================================================="
read
fi
fi
# Start cloning the repositories.
repos="pivio-web pivio-server pivio-client pivio-demo-data"
for repo in ${repos}
do
echo $repo
if [ -d "$repo" ]
then
cd $repo
git pull
cd ..
else
git clone https://github.com/pivio/$repo.git
fi
cd $repo
if [ -e "build.gradle" ]; then
./gradlew build --no-daemon
fi
cd ..
done
# Create the docker-compose file.
rm -r docker-compose.yml > /dev/null
cat <<EOF > docker-compose.yml
services:
pivio-web:
build: pivio-web/
ports:
- "8080:8080"
links:
- pivio-server
volumes:
- $PWD/pivio-conf/:/pivio-conf
environment:
- PIVIO_SERVER=http://pivio-server:9123
- PIVIO_SERVER_JS=http://$HOSTNAME:9123
- PIVIO_VIEW=http://$HOSTNAME:8080
devices:
- "/dev/urandom:/dev/random"
pivio-server:
build: pivio-server/
ports:
- "9123:9123"
links:
- elasticsearch
devices:
- "/dev/urandom:/dev/random"
elasticsearch:
image: elasticsearch:2.4.6
command: ["/bin/sh", "-c", "if ! plugin list | grep -q delete-by-query; then plugin install delete-by-query; fi && gosu elasticsearch elasticsearch"]
devices:
- "/dev/urandom:/dev/random"
EOF
rm -rf pivio-conf
mkdir -p pivio-conf
cat <<EOF > pivio-conf/server_config.yaml
api: http://pivio-server:9123/
js_api: http://$HOSTNAME:9123/
mainurl: http://$HOSTNAME:8080/
pages:
- description: Overview
url: /app/overview
id: tabOverview
- description: Query
url: /app/query
id: tabQuery
- description: Feed
url: /app/feed
id: tabFeed
EOF
docker-compose up -d --build
echo "Waiting for the servers to come up (on $HOSTNAME). This can take a while because of not enough entropy on your machine."
# This can take a while because of missing enough entropy. I you know how
# to speed this up. Let me know. Thanks.
until $(curl --output /dev/null -X GET --silent --head --fail http://$HOSTNAME:9123/document); do
printf '.'
sleep 5
done
echo "Uploading demo data."
java -jar pivio-client/build/libs/pivio.jar -yamldir $PWD/pivio-demo-data/ -serviceurl http://$HOSTNAME:9123/document
if [ $? -eq 0 ]; then
echo "Waiting for enough entropy for the webserver to be available."
until $(curl --output /dev/null -X GET --silent --head --fail http://$HOSTNAME:8080/); do
printf '.'
sleep 5
done
echo "Open your webbrowser and point it to $HOSTNAME:8080";
if [ "$OS" = "Darwin" ]; then
open "http://$HOSTNAME:8080"
fi
else
echo "Error: Oops, something went wrong. I'm sorry. Please file a bug report."
exit 1;
fi
echo "You can stop the demo with 'docker-compose stop'."