forked from privacy-scaling-explorations/maci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.sh
executable file
·88 lines (77 loc) · 1.88 KB
/
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
#!/usr/bin/env bash
DOCKER_CONFIG="../docker"
SCRIPT='node /root/maci/server/index.js'
function setup(){
CONTAINER_ID=$(docker container ls | grep maci-node | cut -d' ' -f1)
HOST_IP=$(docker inspect "$CONTAINER_ID" | jq -r .[0].NetworkSettings.Networks[].Gateway)
docker exec $CONTAINER_ID sed -i "s/host.docker.internal/$HOST_IP/g" /root/maci/server/admin.sh
docker exec $CONTAINER_ID sed -i "s/host.docker.internal/$HOST_IP/g" /root/maci/server/admin_v0_10.sh
}
function run_script() {
CONTAINER_ID=$(docker container ls | grep maci-node | cut -d' ' -f1)
docker exec -it $CONTAINER_ID $SCRIPT
}
function kill_script() {
CONTAINER_ID=$(docker container ls | grep maci-node | cut -d' ' -f1)
PID=$(docker exec $CONTAINER_ID pgrep node)
echo "kill process: "$PID
docker exec $CONTAINER_ID kill -9 $PID
}
function stop_docker() {
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
}
function start_docker() {
cd $DOCKER_CONFIG && docker-compose up -d
setup
run_script
}
function login_docker() {
CONTAINER_ID=$(docker container ls | grep maci-node | cut -d' ' -f1)
docker exec -it $CONTAINER_ID bash
}
function print_usage() {
echo "start/stopdocker instances: ./test.sh -[ud] "
echo "run/kill server.js in docker: ./test.sh -[rk]"
echo "log in docker: ./test.sh -[l]"
}
UP=""
DOWN=""
RUN=""
LOGIN=""
KILL=""
while getopts 'udrlkpg' OPT; do
case $OPT in
u)
UP="true";;
d)
DOWN="true";;
r)
RUN="true";;
l)
LOGIN="true";;
k)
KILL="true";;
?)
print_usage
exit -1;;
esac
done
if [ "$DOWN" == "true" ]; then
echo "stop dockers..."
stop_docker
fi
if [ "$UP" == "true" ]; then
echo "start dockers..."
start_docker
fi
if [ "$RUN" == "true" ]; then
echo "running docker script..."
run_script
fi
if [ "$LOGIN" == "true" ]; then
login_docker
fi
if [ "$KILL" == "true" ]; then
kill_script
fi