-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev
executable file
·67 lines (56 loc) · 1.77 KB
/
dev
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
#!/bin/bash
set -e
export CHARM_HOST=localhost
if ! which charm >/dev/null 2>&1; then
echo "charm CLI not found, install it first"
exit 1
fi
if [ "$1" = "refresh" ]; then
echo "🚀 Refreshing docker containers..."
docker-compose up -d
exit
fi
error() {
echo
echo "☣️ Ruh roh! something catastrophically bad happened, aborting launch mission."
echo
exit 1
}
trap "error" EXIT
echo "🚀 Booting the Charmed Ring cluster..."
mkdir -p tmp
## empty so go mod tidy doesn't complain about file permissions
touch tmp/go.mod
docker-compose up -d >> tmp/dev.log 2>&1
## Wait for charm servers
echo "⏳ Waiting for Charm servers to start..."
while ! nc -q 1 localhost 4002 </dev/null; do sleep 10; done
while ! nc -q 1 localhost 5002 </dev/null; do sleep 10; done
while ! nc -q 1 localhost 6002 </dev/null; do sleep 10; done
echo "👤 Creating the first user..."
charm name test
docker run -v $PWD/tmp/cluster/charm1:/charm1 \
-v $PWD/tmp/cluster/charm2:/charm2 \
-v $PWD/tmp/cluster/charm3:/charm3 \
-i alpine /bin/sh -s >> /tmp/dev.log <<SCRIPT
set -e
apk update && apk upgrade && apk add --no-cache sqlite
sqlite3 /charm1/db/charm_sqlite.db ".backup /tmp/dump.sqlite"
sqlite3 /charm2/db/charm_sqlite.db ".restore /tmp/dump.sqlite"
sqlite3 /charm3/db/charm_sqlite.db ".restore /tmp/dump.sqlite"
cp -r /charm1/.ssh/* /charm2/.ssh/
cp -r /charm1/.ssh/* /charm3/.ssh/
SCRIPT
docker-compose restart charm2 charm3 >> tmp/dev.log 2>&1
trap - EXIT
echo "💍 Charmed Ring cluster ready!"
echo
echo "Don't forget to export the required environment variable"
echo "to use the Charmed Ring cluster:"
echo " export CHARM_HOST=localhost"
echo
echo "To monitor cluster logs:"
echo " docker-compose logs -f"
echo
echo "To clean up:"
echo " script/clean-cluster"