This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
forked from gardenlinux/gardenlinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·69 lines (58 loc) · 1.74 KB
/
test
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
#!/usr/bin/env bash
set -eufo pipefail
dir="$(dirname "${BASH_SOURCE[0]}")"
container_image=
container_engine=podman
container_run_opts=(
--security-opt seccomp=unconfined
--security-opt apparmor=unconfined
--security-opt label=disable
--read-only
)
while [ $# -gt 0 ]; do
case "$1" in
--container-image)
container_image="$2"
shift 2
;;
--container-engine)
container_engine="$2"
shift 2
;;
--container-run-opts)
declare -a "container_run_opts=($2)"
shift 2
;;
*)
break
;;
esac
done
if [[ ! -d $dir/.build/ ]]; then
echo "ERROR: .build directory does not exist."
echo "Require $1 to be built before it can be tested."
echo "Run ./build $1 before running ./test $1"
exit 1
fi
cname="$(basename "$(realpath "$dir/.build/$1")" .artifacts)"
if [[ ! -f $(realpath "$dir")/.build/$cname.tar ]]; then
echo "ERROR: Require $1 to be built before it can be tested."
echo "Run ./build $1 before running ./test $1"
exit 1
fi
container_mount_opts=(
-v "$(realpath "$dir")/tests:/gardenlinux/tests"
-v "$(realpath "$dir")/features:/gardenlinux/features:ro"
-v "$(realpath "$dir")/bin:/gardenlinux/bin:ro"
-v "$(realpath "$dir")/.build/$cname.tar:/gardenlinux/input.tar:ro"
-v "$(realpath "$dir")/.build/$cname.release:/gardenlinux/input.release:ro"
)
if [ -z "$container_image" ]; then
base_image="$("$dir/build" --print-container-image)"
image_file="$(mktemp)"
"$container_engine" build --iidfile "$image_file" --build-arg base="$base_image" "$dir/tests"
container_image="$(cat "$image_file")"
rm "$image_file"
fi
"$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" 2>&1 | tee "$dir/.build/$cname.test-log"
echo "$cname.test-log" >> "$dir/.build/$cname.artifacts"