-
Notifications
You must be signed in to change notification settings - Fork 11
/
run.sh
executable file
·396 lines (368 loc) · 10.6 KB
/
run.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
#########################################################
# Run hello bench for OCI nydus image. #
# Platform :All Linux Based Platform #
# Version :1.0 #
# Date :2022-11-09 #
# Author :Bin Tang #
# Contact :[email protected] #
#########################################################
#########################################################
# No need to modify
#########################################################
CURRENT_ROUND=1
RESULT_FILE=result.txt
RESULT_CSV=result.csv
NYDUSIFY_BIN=$(which nydusify)
NYDUS_IMAGE_BIN=$(which nydus-image)
#########################################################
# Could alert value via arguments
#########################################################
ROUND_NUM=10
RESULT_DIR=data
SOURCE_REGISTRY=docker.io/library
TARGET_REGISTRY=""
SKIP=false
IMAGES_PATH=hello_bench_image_list.txt
#########################################################
# Push OCI image to TARGET_REGISTRY
# Globals:
# TARGET_REGISTRY
# Arguments:
# image
# Returns:
# None
#########################################################
function push_registry() {
image=$1
echo "[INFO] Pushing ${image} to ${TARGET_REGISTRY}/${image}"
sudo docker pull ${image}
sudo docker tag ${SOURCE_REGISTRY}/${image} ${TARGET_REGISTRY}/${image}
sudo docker push ${TARGET_REGISTRY}/${image}
sudo docker rmi -f ${TARGET_REGISTRY}/${image}
sudo docker rmi -f ${image}
}
#########################################################
# Convert OCI image to nydus/stargz image and push to
# TARGET_REGISTRY
# Globals:
# TARGET_REGISTRY
# Arguments:
# image
# Returns:
# None
#########################################################
function convert() {
check_binary
image=$1
sudo nerdctl pull ${TARGET_REGISTRY}/${image}
echo "[INFO] Converting ${TARGET_REGISTRY}/${image} to ${TARGET_REGISTRY}/${image}:nydusv6 ..."
echo "sudo $NYDUSIFY_BIN convert \
--fs-version 6 \
--nydus-image $NYDUS_IMAGE_BIN \
--source ${TARGET_REGISTRY}/${image} \
--target ${TARGET_REGISTRY}/${image}:nydusv6"
sudo $NYDUSIFY_BIN convert \
--fs-version 6 \
--nydus-image $NYDUS_IMAGE_BIN \
--source ${TARGET_REGISTRY}/${image} \
--target ${TARGET_REGISTRY}/${image}:nydusv6
}
#########################################################
# Stop all running containers
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#########################################################
function stop_all_containers {
containers=$(sudo nerdctl ps -q | tr '\n' ' ')
if [[ ${containers} == "" ]]; then
return 0
else
echo "Killing containers ${containers}"
for C in ${containers}; do
sudo nerdctl kill "${C}"
sudo nerdctl stop "${C}"
sudo nerdctl rm "${C}"
done
return 1
fi
}
#########################################################
# Run hello bench for OCI image, nydus image
# Globals:
# TARGET_REGISTRY
# Arguments:
# image
# Returns:
# None
#########################################################
function run() {
image=$1
stop_all_containers
sudo nerdctl ps -a | awk 'NR>1 {print $1}' | xargs sudo nerdctl rm >/dev/null 2>&1
sudo nerdctl container prune -f
sudo nerdctl image prune -f --all
sudo systemctl restart nydus-snapshotter
sleep 1
echo "[INFO] Run hello bench in ${image} ..."
sudo nerdctl --snapshotter overlayfs rmi -f ${TARGET_REGISTRY}/${image} >/dev/null 2>&1
result=$(sudo ./hello.py --engine nerdctl --snapshotter overlayfs --op run \
--registry=${TARGET_REGISTRY} \
--images ${image} |
grep "repo")
echo ${result}
echo ${result} >>${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}
echo "[INFO] Remove image ${TARGET_REGISTRY}/${image} ..."
sudo nerdctl --snapshotter overlayfs rmi -f ${TARGET_REGISTRY}/${image} >/dev/null 2>&1
echo "[INFO] Run hello bench in ${image}:nydusv6 ..."
sudo nerdctl --snapshotter nydus rmi -f ${TARGET_REGISTRY}/${image}:nydusv6 >/dev/null 2>&1
result=$(sudo ./hello.py --engine nerdctl --snapshotter nydus --op run \
--registry=${TARGET_REGISTRY} \
--images ${image}:nydusv6 |
grep "repo")
echo ${result}
echo ${result} >>${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}
echo "[INFO] Remove image ${TARGET_REGISTRY}/${image}:nydusv6 ..."
sudo nerdctl --snapshotter nydus rmi -f ${TARGET_REGISTRY}/${image}:nydusv6 >/dev/null 2>&1
}
#########################################################
# Handle data in $RESULT_DIR to csv and png
# Globals:
# RESULT_DIR
# Arguments:
# None
# Returns:
# None
#########################################################
function handle_data() {
python3_path=$(which python3)
if [ "$(which python3)" == "" ]; then
echo "[ERROR] Can not found python3"
exit
fi
if [ ! -d ${RESULT_DIR} ]; then
echo "[ERROR] Directory ${RESULT_DIR} not exist"
exit
fi
${python3_path} draw.py -d ${RESULT_DIR} -r result
}
#########################################################
# Check required options for this script
# Globals:
# TARGET_REGISTRY
# SOURCE_REGISTRY
# Arguments:
# None
# Returns:
# None
#########################################################
function check_opts() {
if [ "${TARGET_REGISTRY}" == "" ]; then
echo "[ERROR] TARGET_REGISTRY is null"
exit
fi
if [ "${SOURCE_REGISTRY}" == "" ]; then
echo "[ERROR] SOURCE_REGISTRY is null"
exit
fi
}
#########################################################
# Check required binary for this script
# Globals:
# NYDUSIFY_BIN
# NYDUS_IMAGE_BIN
# Arguments:
# None
# Returns:
# None
#########################################################
function check_binary() {
if [ "${NYDUSIFY_BIN}" == "" ]; then
echo "[ERROR] nydusify is not found in \$PATH"
exit
fi
if [ "${NYDUS_IMAGE_BIN}" == "" ]; then
echo "[ERROR] nydus-image is not found in \$PATH"
exit
fi
}
#########################################################
# Usage information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#########################################################
function usage() {
echo "Usage:"
echo -e "run.sh -o OPERATION -s SOURCE_REGISTRY -t TARGET_REGISTRY [other options]
[-o operation] \tavailable options are [ push convert run all draw ]
[-i images] \timages list
[-p images path] \tfile path that contains images list (line by line)
[-s source registry] \tsource registry for pulling image
[-t target registry] \target registry for pushing image
[-r round number] \tnumber of round to run hellobench
[-d result directory] \tdirectory to store raw result data
[-k skip finished test] \tskip images that already finisned (in \$RESULT_DIR/\$RESULT_FILE)"
exit -1
}
function getopts_extra() {
declare i=1
while [[ ${OPTIND} -le $# && ${!OPTIND:0:1} != '-' ]]; do
OPTARG[i]=${!OPTIND}
let i++ OPTIND++
done
}
available_operation="push convert run all draw"
if [ $# -eq 0 ]; then
usage
fi
while getopts o:i:p:s:t:r:d:kh OPT; do
case $OPT in
o)
operation=${OPTARG}
if ! [[ "$available_operation" =~ "$operation" ]]; then
echo "operation ${operation} not support now"
exit
fi
;;
i)
getopts_extra "$@"
images=("${OPTARG[@]}")
;;
p)
IMAGES_PATH=${OPTARG}
;;
s)
SOURCE_REGISTRY=${OPTARG}
;;
t)
TARGET_REGISTRY=${OPTARG}
;;
r)
ROUND_NUM=${OPTARG}
;;
d)
RESULT_DIR=${OPTARG}
;;
k)
SKIP=true
;;
*)
usage
;;
esac
done
shift $((OPTIND - 1))
if [ ${#images[@]} -gt 0 ]; then
IMAGES=()
for image in "${images[@]}"; do
IMAGES+=($image)
done
else
IMAGES=($(cat ${IMAGES_PATH} | tr "\n" " "))
fi
images_length=${#IMAGES[@]}
echo "images:"
for IMAGE in "${IMAGES[@]}"; do
echo "- ${IMAGE}"
done
if [ ${images_length} -eq 0 ] && [ "$IMAGES_PATH" == "" ]; then
echo "both images list and file path are null"
exit
fi
case $operation in
push)
check_opts
for image in "${IMAGES[@]}"; do
push_registry ${image}
done
;;
convert)
check_opts
for image in "${IMAGES[@]}"; do
convert ${image}
done
;;
run)
check_opts
if [ ! "${SKIP}" == "true" ]; then
if [ -d ${RESULT_DIR} ]; then
rm -rf ${RESULT_DIR}
fi
mkdir ${RESULT_DIR}
fi
for i in $(seq 1 ${ROUND_NUM}); do
CURRENT_ROUND=${i}
if [ ! "${SKIP}" == "true" ]; then
echo "" >${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}
fi
for image in "${IMAGES[@]}"; do
if [ "${SKIP}" == "true" ]; then
skip=false
for i in $(cat ${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}); do
if [[ "${i}" =~ "${image}" ]]; then
echo "Skip image ${image}."
skip=true
break
fi
done
if [ "${skip}" == "true" ]; then
continue
fi
fi
run ${image}
done
done
;;
all)
check_opts
if [ ! "${SKIP}" == "true" ]; then
if [ -d ${RESULT_DIR} ]; then
rm -rf ${RESULT_DIR}
fi
mkdir ${RESULT_DIR}
fi
for i in $(seq 1 ${ROUND_NUM}); do
CURRENT_ROUND=${i}
if [ ! "${SKIP}" == "true" ]; then
echo "" >${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}
fi
for image in "${IMAGES[@]}"; do
if [ "${SKIP}" == "true" ]; then
skip=false
for i in $(cat ${RESULT_DIR}/${RESULT_FILE}.${CURRENT_ROUND}); do
if [[ "${i}" =~ "${image}" ]]; then
echo "Skip image ${image}."
skip=true
break
fi
done
if [ "${skip}" == "true" ]; then
continue
fi
fi
if [ ${CURRENT_ROUND} -eq 1 ]; then
push_registry ${image}
convert ${image}
fi
run ${image}
done
done
handle_data
;;
draw)
handle_data
;;
*)
echo "get invalid operation: ${operation}"
usage
exit
;;
esac