forked from ghermeto/openjs-world-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-docker.sh
executable file
·96 lines (83 loc) · 2.83 KB
/
setup-docker.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
#!/bin/sh
#cleanup stuff
echo "cleaning up any previous setup..."
docker stop prom || echo "prometheus container not found"
docker stop graf || echo "grafana container not found"
docker stop pgdb || echo "postgres container not found"
docker rm prom || echo "prometheus container not found"
docker rm graf || echo "grafana container not found"
docker rm pgdb || echo "postgres container not found"
docker network rm openjsworld || echo "network openjsworld not found"
echo "cleaning up any previous setup... done!"
#setting up the shared bridge netwrok
echo "setting up docker bridge network..."
docker network create -d bridge openjsworld
echo "setting up docker bridge network... done!"
#setup prometheus
echo "setting up prometheus container..."
docker pull prom/prometheus
docker run -d \
-p 9091:9090 \
-v "${PWD}/config/prometheus.yml:/etc/prometheus/prometheus.yml" \
--network="openjsworld" \
--name="prom" \
prom/prometheus
echo "setting up prometheus container... done!"
#setup grafana
echo "setting up grafana container..."
docker pull grafana/grafana
docker run -d \
-p 3001:3000 \
--network="openjsworld" \
--name="graf" \
grafana/grafana
echo "setting up grafana container... done!"
echo "waiting for grafana service..."
until curl http://localhost:3001/api/health; do
>&2 echo "grafana is unavailable - sleeping"
sleep 1
done
echo "waiting for grafana service... done!"
#configure grafana
echo "configuring grafana..."
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"name": "prometheus_data", "type": "prometheus", "url": "http://prom:9090", "access": "proxy"}' \
--user admin:admin \
http://localhost:3001/api/datasources
curl -X POST \
-H 'Content-Type: application/json' \
-d @config/grafana-dashboard.json \
--user admin:admin \
http://localhost:3001/api/dashboards/db
echo "configuring grafana... done!"
#setup postgres db
echo "setting up postgres container..."
docker pull postgres
docker run -d \
-p 5433:5432 \
--network="openjsworld" \
--name="pgdb" \
-v "${PWD}/config/db.sql:/usr/local/etc/db.sql" \
-e POSTGRES_PASSWORD=supersecret \
-e POSTGRES_DB=openjs \
postgres
echo "setting up postgres container... done!"
echo "waiting for postgres service..."
until docker run \
--network="openjsworld" \
-e PGPASSWORD=supersecret \
-v "${PWD}/config/db.sql:/usr/local/etc/db.sql" \
postgres psql -h pgdb -U postgres -d openjs -c '\q'; do
>&2 echo "postgres is unavailable - sleeping"
sleep 1
done
echo "waiting for postgres service... done!"
echo "creating postgres database..."
#configure postgres
docker run --rm \
--network="openjsworld" \
-e PGPASSWORD=supersecret \
-v "${PWD}/config/db.sql:/usr/local/etc/db.sql" \
postgres psql -h pgdb -U postgres -d openjs -f /usr/local/etc/db.sql
echo "creating postgres database... done!"