-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox
159 lines (152 loc) · 5.25 KB
/
sandbox
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
#!/bin/bash
set -eo pipefail
IFS=$'\n\t'
sed -i 's#GRAFANA_USER_ID=0#'GRAFANA_USER_ID=${UID}'#g' .env
sandbox () {
if [ "$2" == "-nightly" ]; then
source .env-nightlies
echo "Using nightlies...removing old ones."
# If nightly images already exist, containers are stopped, destroyed,
# and rebuilt using newly pulled images
if [ $(docker images | grep nightly | tr -s ' ' | cut -d ' ' -f 3 | wc -l) -gt 0 ]; then
docker-compose down
docker-compose rm -f
docker-compose build --pull
fi
else
source .env-latest
echo "Using latest, stable releases"
fi
# Enter attaches users to a shell in the desired container
enter () {
case $2 in
influxdb)
echo "Entering /bin/bash session in the influxdb container..."
docker-compose exec influxdb /bin/bash
;;
chronograf)
echo "Entering /bin/sh session in the chronograf container..."
docker-compose exec chronograf /bin/sh
;;
kapacitor)
echo "Entering /bin/bash session in the kapacitor container..."
docker-compose exec kapacitor /bin/bash
;;
telegraf)
echo "Entering /bin/bash session in the telegraf container..."
docker-compose exec telegraf /bin/bash
;;
flux)
echo "Entering /bin/bash session in the flux container..."
docker-compose exec flux /bin/sh
;;
grafana)
echo "Entering /bin/bash session in the grafana container..."
docker-compose exec grafana /bin/sh
;;
*)
echo "sandbox enter (influxdb||chronograf||kapacitor||telegraf||flux||grafana)"
;;
esac
}
# Logs streams the logs from the container to the shell
logs () {
case $2 in
influxdb)
echo "Following the logs from the influxdb container..."
docker-compose logs -f influxdb
;;
chronograf)
echo "Following the logs from the chronograf container..."
docker-compose logs -f chronograf
;;
kapacitor)
echo "Following the logs from the kapacitor container..."
docker-compose logs -f kapacitor
;;
telegraf)
echo "Following the logs from the telegraf container..."
docker-compose logs -f telegraf
;;
grafana)
echo "Following the logs from the grafana container..."
docker-compose logs -f grafana
;;
*)
echo "sandbox logs (influxdb||chronograf||kapacitor||telegraf||grafana)"
;;
esac
}
case $1 in
up)
echo "Spinning up Docker Images..."
echo "If this is your first time starting sandbox this might take a minute..."
docker-compose up -d --build
echo "Opening tabs in browser..."
sleep 3
if [ $(uname) == "Darwin" ]; then
open http://localhost:${DOCUMENTATION_PORT}
open http://localhost:${CHRONOGRAF_WEB_UI_PORT}
elif [ $(uname) == "Linux" ]; then
sensible-browser http://localhost:${CHRONOGRAF_WEB_UI_PORT}
sensible-browser http://localhost:${DOCUMENTATION_PORT}
else
echo "no browser detected..."
fi
;;
down)
echo "Stopping sandbox containers..."
docker-compose down
;;
restart)
echo "Stopping all sandbox processes..."
docker-compose down > /dev/null 2>&1
echo "Starting all sandbox processes..."
docker-compose up -d --build > /dev/null 2>&1
echo "Services available!"
;;
delete-data)
echo "deleting all influxdb, kapacitor and chronograf data..."
rm -rf kapacitor/data influxdb/data chronograf/data
;;
docker-clean)
echo "Stopping and removing running sandbox containers..."
docker-compose down
echo "Removing TICK images..."
docker rmi sandbox_documentation influxdb:latest telegraf:latest kapacitor:latest grafana/grafana:latest chronograf:latest chrono_config:latest quay.io/influxdb/influxdb:nightly quay.io/influxdb/chronograf:nightly> /dev/null 2>&1
docker rmi $(docker images -f "dangling=true" -q)
;;
influxdb)
echo "Entering the influx cli..."
docker-compose exec influxdb /usr/bin/influx
;;
rebuild-docs)
echo "Rebuilding documentation container..."
docker build -t sandbox_documentation documentation/ > /dev/null 2>&1
echo "Restarting..."
docker-compose down > /dev/null 2>&1
docker-compose up -d --build > /dev/null 2>&1
;;
enter)
enter $@
;;
logs)
logs $@
;;
*)
cat <<-EOF
sandbox commands:
up (-nightly) -> spin up the sandbox environment (latest or nightlies specified in the companion file)
down -> tear down the sandbox environment (latest or nightlies specified in the companion file)
restart (-nightly) -> restart the sandbox
influxdb -> attach to the influx cli
enter (influxdb||kapacitor||chronograf||telegraf) -> enter the specified container
logs (influxdb||kapacitor||chronograf||telegraf) -> stream logs for the specified container
delete-data -> delete all data created by the TICK Stack
docker-clean -> stop and remove all running docker containers and images
rebuild-docs -> rebuild the documentation image
EOF
;;
esac
}
sandbox $@