/
up.sh
executable file
·105 lines (90 loc) · 3.39 KB
/
up.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
#!/bin/sh
set -e # exit on an error
ERROR(){
/bin/echo -e "\e[101m\e[97m[ERROR]\e[49m\e[39m $@"
}
WARNING(){
/bin/echo -e "\e[101m\e[97m[WARNING]\e[49m\e[39m $@"
}
INFO(){
/bin/echo -e "\e[104m\e[97m[INFO]\e[49m\e[39m $@"
}
exists() {
type $1 > /dev/null 2>&1
}
for f in $@; do
case $f in
'--help' )
HELP=1
;;
'--init-only' )
INIT_ONLY=1
;;
'--dev' )
if [ ! "$JEPSEN_ROOT" ]; then
INFO "MISSING VAR: --dev requires JEPSEN_ROOT to be set"
exit 1
else
INFO "Running docker-compose with dev config"
DEV="-f docker-compose.dev.yml"
fi
;;
'--daemon' )
INFO "Running docker-compose as daemon"
RUN_AS_DAEMON=1
;;
*)
ERROR "unknown option $1"
exit 1
;;
esac
shift
done
if [ "$HELP" ]; then
echo "usage: $0 [OPTION]"
echo " --help Display this message"
echo " --init-only Initializes the secret, but does not call docker-compose"
echo " --daemon Runs docker-compose in the background"
echo " --dev Mounts dir at host's $JEPSEN_ROOT to /jepsen on jepsen-control container, syncing files for development"
exit 0
fi
exists ssh-keygen || { ERROR "Please install ssh-keygen (apt-get install openssh-client)"; exit 1; }
exists perl || { ERROR "Please install perl (apt-get install perl)"; exit 1; }
if [ ! -f ./secret/node.env ]; then
INFO "Generating key pair"
ssh-keygen -t rsa -N "" -f ./secret/id_rsa
INFO "Generating ./secret/control.env"
echo '# generated by jepsen/docker/up.sh, parsed by jepsen/docker/control/bashrc' > ./secret/control.env
echo '# NOTE: \\n is expressed as ↩' >> ./secret/control.env
echo SSH_PRIVATE_KEY="$(cat ./secret/id_rsa | perl -p -e 's/\n/↩/g')" >> ./secret/control.env
echo SSH_PUBLIC_KEY=$(cat ./secret/id_rsa.pub) >> ./secret/control.env
INFO "Generating ./secret/node.env"
echo '# generated by jepsen/docker/up.sh, parsed by the "tutum/debian" docker image entrypoint script' > ./secret/node.env
echo ROOT_PASS=root >> ./secret/node.env
echo AUTHORIZED_KEYS=$(cat ./secret/id_rsa.pub) >> ./secret/node.env
else
INFO "No need to generate key pair"
fi
# Dockerfile does not allow `ADD ..`. So we need to copy that.
INFO "Copying .. to control/jepsen"
(
rm -rf ./control/jepsen
mkdir ./control/jepsen
(cd ..; tar --exclude=./docker --exclude=./.git -cf - .) | tar Cxf ./control/jepsen -
)
if [ "$INIT_ONLY" ]; then
exit 0
fi
exists docker || { ERROR "Please install docker (https://docs.docker.com/engine/installation/)"; exit 1; }
exists docker-compose || { ERROR "Please install docker-compose (https://docs.docker.com/compose/install/)"; exit 1; }
INFO "Running \`docker-compose build\`"
docker-compose build
INFO "Running \`docker-compose up\`"
if [ "$RUN_AS_DAEMON" ]; then
docker-compose -f docker-compose.yml $DEV up -d
INFO "All containers started, run \`docker ps\` to view"
exit 0
else
INFO "Please run \`docker exec -it jepsen-control bash\` in another terminal to proceed"
docker-compose -f docker-compose.yml $DEV up
fi