forked from influxdata/influxdata-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle-test.sh
executable file
·103 lines (86 loc) · 2.49 KB
/
circle-test.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
#!/bin/bash
set -ex
dir=.
if [ $# -gt 0 ]; then
dir=("$@")
fi
log_msg() {
echo "[$(date "+%Y/%m/%d %H:%M:%S %z")] $@"
}
docker_build() {
if [ ! -z "$BUILD_NUMBER" ]; then
# Build on Jenkins without using the cache.
docker build --no-cache --force-rm "$@"
elif [ ! -z "$CIRCLE_BUILD_NUM" ]; then
# CircleCI cannot build docker images with --rm=true correctly.
docker build --no-cache --rm=false "$@"
else
# Local building should use the cache for speedy development.
docker build --no-cache --rm=true "$@"
fi
}
log_msg "Verifying docker daemon connectivity"
docker version
failed_builds=()
tags=()
# Gather directories with a Dockerfile and sanitize the path to remove leading
# a leading ./ and multiple slashes into a single slash.
dockerfiles=$(find "$dir" -name Dockerfile -print0 | xargs -0 -I{} dirname {} | grep -v dockerlib | sed 's@^./@@' | sed 's@//*@/@g')
for path in $dockerfiles; do
# Generate a tag by replacing the first slash with a colon and all remaining slashes with a dash.
tag=$(echo $path | sed 's@/@:@' | sed 's@/@-@g')
log_msg "Building docker image $tag (from $path)"
if ! docker_build -t "$tag" "$path"; then
failed_builds+=("$tag")
else
if [ ! -z "$BUILD_NUMBER" ]; then
# Remove the image if we are running on Jenkins.
docker rmi "$tag"
fi
tags+=("$tag")
fi
done
if [ ${#failed_builds[@]} -eq 0 ]; then
log_msg "All builds succeeded."
else
log_msg "Failed to build the following images:"
for tag in ${failed_builds[@]}; do
echo " $tag"
done
exit ${#failed_builds[@]}
fi
# Image tests:
assert_equals() {
local actual=$1
local expected=$2
local test_name=$3
if [ "$actual" != "$expected" ]; then
msg="$test_name: '$actual' is not equal to '$expected'"
failed_tests+=("$msg")
fi
}
assert_contains() {
local actual="$1"
local expected_substring="$2"
local test_name="$3"
if [[ "$actual" != *"$expected_substring"* ]]; then
msg="$test_name: '$actual' does not contain '$expected_substring'"
failed_tests+=("$msg")
fi
}
failed_tests=()
# Iterate over every circle-test.sh script in any subdirectory
#circle_tests=$(find "$dir" -mindepth 2 -name circle-test.sh -print0)
#for path in $circle_tests; do
# log_msg "Executing $path"
# . $path
#done
if [ ${#failed_tests[@]} -eq 0 ]; then
log_msg "All tests succeeded."
else
log_msg "The following tests failed:"
for ((i = 0; i < ${#failed_tests[@]}; i++)); do
echo " ${failed_tests[$i]}"
done
exit ${#failed_tests[@]}
fi