-
-
Notifications
You must be signed in to change notification settings - Fork 586
/
test_containers.sh
executable file
·56 lines (43 loc) · 1.85 KB
/
test_containers.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
#!/bin/bash
# Runs "make test" in each container directory
set -o errexit
set -o pipefail
set -o nounset
echo "--- buildkite building ${BUILDKITE_JOB_ID:-} at $(date) on $(hostname) for OS=$(go env GOOS) in $PWD with golang=$(go version) docker=$(docker version --format '{{.Server.Version}}') and docker-compose $(docker-compose version --short)"
function cleanup {
set +x
echo "--- Cleanup docker"
echo "Warning: deleting all docker containers and deleting images that match this build."
if [ "$(docker ps -aq | wc -l)" -gt 0 ] ; then
docker rm -f $(docker ps -aq) >/dev/null || true
fi
docker system prune --volumes --force
# Make sure we don't have any existing containers on the testbot that might
# result in this container not being built from scratch.
VERSION=$(make version | sed 's/^VERSION://')
IMAGES=$(docker images | awk "/$VERSION/ { print \$3 }")
if [ ! -z "${IMAGES:-}" ] ; then
docker rmi --force $IMAGES 2>&1 >/dev/null || true
fi
}
# Now that we've got a container running, we need to make sure to clean up
# at the end of the test run, even if something fails.
trap cleanup EXIT
# Do initial cleanup of images that might not be needed; they'll be cleaned at exit as well.
cleanup
# There are discrepancies in golang hash checking in 1.11+, so kill off modcache to solve.
# See https://github.com/golang/go/issues/27925
# This can probably be removed when current work is merged 2018-12-27
# go clean -modcache (Doesn't work due to current bug in golang)
chmod -R u+w ~/go/pkg && rm -rf ~/go/pkg/*
# Our testbot should now be sane, run the testbot checker to make sure.
./.buildkite/sanetestbot.sh
set -x
for dir in containers/*
do pushd $dir
echo "--- Build container $dir"
time make container DOCKER_ARGS=--no-cache
echo "--- Test container $dir"
time make test
popd
done