2021-07-11 13:27:01 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-09-02 15:17:46 +02:00
|
|
|
MATCH_PATTERN=$1
|
|
|
|
IMAGE_TAG=${IMAGE_TAG:-canary}
|
2021-07-11 20:21:17 +02:00
|
|
|
|
2023-09-02 15:17:46 +02:00
|
|
|
sandbox="docker_volume_backup_test_sandbox"
|
|
|
|
tarball="$(mktemp -d)/image.tar.gz"
|
|
|
|
|
|
|
|
trap finish EXIT INT TERM
|
|
|
|
|
|
|
|
finish () {
|
|
|
|
rm -rf $(dirname $tarball)
|
|
|
|
if [ ! -z $(docker ps -aq --filter=name=$sandbox) ]; then
|
|
|
|
docker rm -f $(docker stop $sandbox)
|
|
|
|
fi
|
|
|
|
if [ ! -z $(docker volume ls -q --filter=name="^${sandbox}\$") ]; then
|
|
|
|
docker volume rm $sandbox
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
docker build -t offen/docker-volume-backup:test-sandbox .
|
|
|
|
|
|
|
|
if [ ! -z "$BUILD_IMAGE" ]; then
|
|
|
|
docker build -t offen/docker-volume-backup:$IMAGE_TAG $(dirname $(pwd))
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker save offen/docker-volume-backup:$IMAGE_TAG -o $tarball
|
|
|
|
|
|
|
|
find_args="-mindepth 1 -maxdepth 1 -type d"
|
|
|
|
if [ ! -z "$MATCH_PATTERN" ]; then
|
|
|
|
find_args="$find_args -name $MATCH_PATTERN"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for dir in $(find $find_args | sort); do
|
|
|
|
dir=$(echo $dir | cut -c 3-)
|
2021-07-11 13:27:01 +02:00
|
|
|
echo "################################################"
|
2023-09-02 15:17:46 +02:00
|
|
|
echo "Now running ${dir}"
|
2021-07-11 13:27:01 +02:00
|
|
|
echo "################################################"
|
|
|
|
echo ""
|
2023-09-02 15:17:46 +02:00
|
|
|
|
|
|
|
test="${dir}/run.sh"
|
|
|
|
docker_run_args="--name "$sandbox" --detach \
|
|
|
|
--privileged \
|
|
|
|
-v $(dirname $(pwd)):/code \
|
|
|
|
-v $tarball:/cache/image.tar.gz \
|
|
|
|
-v $sandbox:/var/lib/docker"
|
|
|
|
|
|
|
|
if [ -z "$NO_IMAGE_CACHE" ]; then
|
|
|
|
docker_run_args="$docker_run_args \
|
|
|
|
-v "${sandbox}_image":/var/lib/docker/image \
|
|
|
|
-v "${sandbox}_overlay2":/var/lib/docker/overlay2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker run $docker_run_args offen/docker-volume-backup:test-sandbox
|
|
|
|
|
|
|
|
until docker exec $sandbox /bin/sh -c 'docker info' > /dev/null 2>&1; do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
sleep 0.5
|
|
|
|
|
|
|
|
docker exec $sandbox /bin/sh -c "docker load -i /cache/image.tar.gz"
|
|
|
|
docker exec -e TEST_VERSION=$IMAGE_TAG $sandbox /bin/sh -c "/code/test/$test"
|
|
|
|
|
|
|
|
docker rm $(docker stop $sandbox)
|
|
|
|
docker volume rm $sandbox
|
2021-07-11 13:27:01 +02:00
|
|
|
echo ""
|
|
|
|
echo "$test passed"
|
|
|
|
echo ""
|
|
|
|
done
|