forked from cubefs/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_docker.sh
executable file
·212 lines (185 loc) · 4.12 KB
/
run_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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#! /bin/bash
set -e
RootPath=$(cd $(dirname $0)/..; pwd)
GOPATH=/go
export DiskPath="$RootPath/docker/docker_data"
MIN_DNDISK_AVAIL_SIZE_GB=10
help() {
cat <<EOF
Usage: ./run_docker.sh [ -h | --help ] [ -d | --disk </disk/path> ] [ -l | --ltptest ]
-h, --help show help info
-d, --disk </disk/path> set CubeFS DataNode local disk path
-b, --build build CubeFS server and client
-s, --server start CubeFS servers docker image
-c, --client start CubeFS client docker image
-m, --monitor start monitor web ui
-l, --ltptest run ltp test
-r, --run run servers, client and monitor
-f, --format run gofmt to format source code
--clean cleanup old docker image
EOF
exit 0
}
compose="docker-compose --env-file ${RootPath}/docker/run_docker.env -f ${RootPath}/docker/docker-compose.yml"
clean() {
${compose} down
}
prepare() {
${compose} run prepare
}
# unit test
run_unit_test() {
${compose} run unit_test
}
# go format
run_format() {
prepare
${compose} run format
}
run_bsgofumpt() {
prepare
${compose} run bs_gofumpt
}
run_bsgolint() {
prepare
${compose} run bs_golint
}
# build
build() {
prepare
${compose} run build
}
# build
build_s3() {
prepare
${compose} run build bash -c "/bin/bash /cfs/script/build.sh -s3"
}
# start server
start_servers() {
isDiskAvailable $DiskPath
mkdir -p ${DiskPath}/disk/{1..4}
${compose} up -d servers
}
start_client() {
${compose} run client bash -c "/cfs/script/start_client.sh ; /bin/bash"
}
start_monitor() {
${compose} up -d monitor
}
start_s3test() {
${compose} run client
}
start_ltptest() {
${compose} run client bash -c "/cfs/script/start.sh -ltp"
}
run_s3test() {
build_s3
start_servers
start_s3test
clean
}
run_ltptest() {
build
start_servers
start_ltptest
clean
}
run() {
build
start_monitor
start_servers
start_client
}
cmd="help"
ARGS=( "$@" )
for opt in ${ARGS[*]} ; do
case "$opt" in
-h|--help)
help
;;
-b|--build)
cmd=build
;;
-t|--test)
cmd=run_test
;;
-l|--ltptest)
cmd=run_ltptest
;;
-n|--s3test)
cmd=run_s3test
;;
-r|--run)
cmd=run
;;
-s|--server)
cmd=run_servers
;;
-c|--client)
cmd=run_client
;;
-m|--monitor)
cmd=run_monitor
;;
-f|--format)
cmd=run_format
;;
--bsgofumpt)
cmd=run_bsgofumpt
;;
--bsgolint)
cmd=run_bsgolint
;;
-clean|--clean)
cmd=clean
;;
*)
;;
esac
done
function isDiskAvailable() {
Disk=${1:-"need diskpath"}
[[ -d $Disk ]] || mkdir -p $Disk
if [[ ! -d $Disk ]] ; then
echo "error: $DiskPath must be exist and at least 10GB free size"
exit 1
fi
avail_kb=$(df -k $Disk | tail -1 | awk '{print $4}')
avail_GB=$(( $avail_kb / 1000 / 1000 ))
if (( $avail_GB < $MIN_DNDISK_AVAIL_SIZE_GB )) ; then
echo "$Disk: avaible size $avail_GB GB < Min Disk avaible size $MIN_DNDISK_AVAIL_SIZE_GB GB" ;
exit 1
fi
}
for opt in ${ARGS[*]} ; do
case "-$1" in
--d|---disk)
shift
export DiskPath=${1:?"need disk dir path"}
isDiskAvailable $DiskPath
shift
;;
-)
break
;;
*)
shift
;;
esac
done
case "-$cmd" in
-help) help ;;
-run) run ;;
-build) build ;;
-run_servers) start_servers ;;
-run_client) start_client ;;
-run_monitor) start_monitor ;;
-run_ltptest) run_ltptest ;;
-run_test) run_unit_test ;;
-run_format) run_format ;;
-run_s3test) run_s3test ;;
-run_bsgofumpt) run_bsgofumpt ;;
-run_bsgolint) run_bsgolint ;;
-clean) clean ;;
*) help ;;
esac