-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-in-docker
executable file
·126 lines (113 loc) · 4.55 KB
/
test-in-docker
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
#!/usr/bin/env bash
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} -dD -r [repo] -o [osimage] package
This script will test the installation of a locally build package
It is meant to verify that all dependencies can be satisfied at installation time
Requirements:
- Need to be in a directory at the same level as the gitrepo to be built
- Package to be test available in the perfSONAR repo or in the local repo
Arguments understood:
-d don't rebuild Docker images but use locally existing one
-D debug install, will get you into a shell instead of doing the install
-r (optional) repository to be used (local repo will be automatically used as well)
if not repo given, then perfsonar-minor-snapshot will be used)
-o (optional) OS to use to try the install (if empty, then all OS known will be tried)
package to be installed
Some examples:
./test-in-docker perfsonar-toolkit
./test-in-docker -r perfsonar-5.0-snapshot -o debian:buster perfsonar-toolkit
proxy=172.17.0.1:3128 ./test-in-docker -r perfsonar-5.0-snapshot iperf3
EOF
}
# Defaults
declare -a ARCHES=("linux/amd64" "linux/arm64")
# See other valid values in build-in-docker
# The ARCHES used need to have a valid image already built, this script is not building any, only the build-in-docker script is building the images
# TODO: Move the image building part into dedicated script
declare -a OSimages=("debian:bullseye" "debian:bookworm" "ubuntu:focal" "ubuntu:jammy" "ubuntu:noble")
build_docker_images=true
REPO="perfsonar-minor-snapshot"
# Parse CLI args
# Parsing options
while getopts "dDhr:o:" OPT; do
case $OPT in
d) build_docker_images=false ;;
D) debug_build="bash" ;;
r) REPO=$OPTARG ;;
o) OSimages=("$OPTARG") ;;
h)
show_help >&2
exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ -n "$1" ]; then
PKG=$1
else
echo "I need the name of package to test."
exit 1
fi
# Variable used by the Docker setup
export OSimage ARCH REPO useproxy
if [ -n "$proxy" ]; then
# If $proxy is set, then we will use it
useproxy=with
else
useproxy=without
fi
# Initialise
LOGS_PREFIX="logs/binary_build"
mkdir -p ${LOGS_PREFIX%%/*}
rm -f ${LOGS_PREFIX}_*.log
TEST_CONTAINERS=""
for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
TEST_CONTAINERS+=${LARCH/\/}"_test "
done
# These 2 vars need to be set before calling docker compose
OSimage=${OSimages[0]}
ARCH=linux/amd64
docker compose down
if $build_docker_images ; then
# Loop on all OS we want to test
for OSimage in ${OSimages[@]}; do
# Loop on all ARCHES we want to prepare images
for ARCH in ${ARCHES[@]}; do
echo -e "\n\033[1;35m============\033[0;35m\nBuilding OS: $OSimage.$ARCH - pS repo: $REPO\n\033[1m============\033[0m\n"
docker buildx bake --load deb_test
done
done
else
echo -e "\n\033[1;33m -d\033[0;33m : I'm not building Docker images but will use the ones already existing in the local registry.\033[0m\n"
fi
# TODO: deb_test should be running on the main Docker host ARCH and be used to run additional commands, if needed
OUTPUT=""
# Loop on all OSimage and ARCHES to test install the new package
for OSimage in ${OSimages[@]}; do
echo "=========="
echo -e "Starting up containers for \033[1m$OSimage\033[0m"
ARCH=linux/amd64 docker compose up -d deb_test $TEST_CONTAINERS
OUTPUT+="-----\n"
for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
LARCH=${LARCH/\/}
echo -e "\n===== Testing installation of \033[1m$PKG\033[0m on \033[1m$ARCH.$OSimage\033[0m in \033[1m$LARCH-test\033[0m container ====="
[ -n "$debug_build" ] && echo -e "\033[1;33m -D\033[0;33m : We will run a debug shell, i.e. call $debug_build if the install fails.\033[0m\n"
# TODO: can we run all tests in parallel?
docker compose exec ${LARCH}_test /usr/local/bin/ps-install-tester $PKG $debug_build
if [ $? -eq 0 ]; then
OUT="\033[32mInstallation of \033[1m$PKG\033[0;32m for \033[1m$OSimage\033[0;32m on \033[1m$ARCH\033[0;32m went fine.\033[0m"
else
OUT="\033[33mSome problem occured during the installation of \033[1m$PKG\033[0;33m for \033[1m$OSimage\033[0;33m on \033[1m$ARCH\033[0m"
fi
echo -e "\n$OUT"
OUTPUT+=$OUT"\n"
# Should we run autopkgtest instead? Or after installation if test exist?
done
echo -e "\nNow stopping all containers"
docker compose down
done
echo -e "\n\n\033[1mTesting summary:\033[0m"
echo -e $OUTPUT