-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathrun.sh
executable file
·84 lines (73 loc) · 2.26 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
#!/bin/sh
set -e
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
GIT_DIR="$(dirname "${SCRIPT_DIR}")"
os="ubuntu"
interactive=0
skip=0
while getopts ":io:r" opt; do
case "${opt}" in
"i")
interactive=1
skip="$((skip + 1))"
;;
"o")
os="${OPTARG}"
skip="$((skip + 2))"
;;
"r")
rebuild="true"
skip="$((skip + 1))"
;;
":")
echo "${TMPNAME}: -${OPTARG} requires an argument" >&2
exit 1
;;
*) ;;
esac
done
shift "${skip}"
oses="${os}"
fails=""
if [ "${os}" = "all" ]; then
oses=""
for config in "${SCRIPT_DIR}/Dockerfile_"*; do
oses="${oses} ${config##*/Dockerfile_}"
done
fi
for os in ${oses}; do
img_tag="privoxy-blocklist-test:${os}"
dockerfile="${SCRIPT_DIR}/Dockerfile_${os}"
pytest_cache="pytest_cache_${os}"
if ! [ -f "${dockerfile}" ]; then
echo "given OS '${os}' is not supported ('${dockerfile}' missing)"
exit 1
fi
if [ "${rebuild}" = "true" ] || ! docker image ls -q "${img_tag}" | grep -vq '^$' || [ "$(($(date +%s) - $(date -d "$(docker image ls "${img_tag}" --format '{{print .CreatedAt}}' | cut -d' ' -f1,2)" +%s)))" -gt 14400 ]; then
echo "building docker image for ${os}"
cd "${GIT_DIR}"
if docker image ls --format '{{ .Repository }}:{{ .Tag }}' | grep -q "${img_tag}"; then
docker image rm "${img_tag}" > /dev/null || true
fi
if docker volume ls --format '{{ .Name }}' | grep -q "${pytest_cache}"; then
docker volume rm "${pytest_cache}" > /dev/null || true
fi
docker build -t "${img_tag}" -f "${dockerfile}" .
cd -
echo
fi
if [ "${interactive}" -eq 0 ]; then
echo "running tests on ${os}"
if ! docker run --rm -w /app -v "${GIT_DIR}:/app" -v "${pytest_cache}:/pytest_cache" "${img_tag}" "${@:-./tests}"; then
fails="${fails} ${os}"
fi
else
echo "interactive mode on ${os}"
docker run -ti --rm -w /app -v "${GIT_DIR}:/app" -v "${pytest_cache}:/pytest_cache" --entrypoint /bin/bash "${img_tag}"
fi
done
if [ -n "${fails}" ]; then
echo
echo "Failed: ${fails}"
exit 1
fi