test: Start to migrate to docker's upstream tests
* Follow the upstream test suite's conventions. * More migration to follow.
This commit is contained in:
39
test/tests/docker-build.sh
Executable file
39
test/tests/docker-build.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# wrapper around "docker build" that creates a temporary directory and copies files into it first so that arbitrary host directories can be copied into containers without bind mounts, but accepts a Dockerfile on stdin
|
||||
|
||||
# usage: ./docker-build.sh some-host-directory some-new-image:some-tag <<EOD
|
||||
# FROM ...
|
||||
# COPY dir/... /.../
|
||||
# EOD
|
||||
# ie: ./docker-build.sh .../hylang-hello-world librarytest/hylang <<EOD
|
||||
# FROM hylang
|
||||
# COPY dir/container.hy /dir/
|
||||
# CMD ["hy", "/dir/container.hy"]
|
||||
# EOD
|
||||
|
||||
dir="$1"; shift
|
||||
[ -d "$dir" ]
|
||||
|
||||
imageTag="$1"; shift
|
||||
|
||||
tmp="$(mktemp -t -d docker-library-test-build-XXXXXXXXXX)"
|
||||
trap "rm -rf '$tmp'" EXIT
|
||||
|
||||
cat > "$tmp/Dockerfile"
|
||||
|
||||
from="$(awk -F '[ \t]+' 'toupper($1) == "FROM" { print $2; exit }' "$tmp/Dockerfile")"
|
||||
onbuilds="$(docker inspect -f '{{len .Config.OnBuild}}' "$from")"
|
||||
if [ "$onbuilds" -gt 0 ]; then
|
||||
# crap, the image we want to build has some ONBUILD instructions
|
||||
# those are kind of going to ruin our day
|
||||
# let's do some hacks to strip those bad boys out in a new fake layer
|
||||
"$(dirname "$(readlink -f "$BASH_SOURCE")")/remove-onbuild.sh" "$from" "$imageTag"
|
||||
awk -F '[ \t]+' 'toupper($1) == "FROM" { $2 = "'"$imageTag"'" } { print }' "$tmp/Dockerfile" > "$tmp/Dockerfile.new"
|
||||
mv "$tmp/Dockerfile.new" "$tmp/Dockerfile"
|
||||
fi
|
||||
|
||||
cp -RL "$dir" "$tmp/dir"
|
||||
|
||||
docker build -t "$imageTag" "$tmp" > /dev/null
|
10
test/tests/image-name.sh
Executable file
10
test/tests/image-name.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# usage: ./image-name.sh librarytest/something some/image:some-tag
|
||||
# output: librarytest/something:some-image-some-tag
|
||||
|
||||
base="$1"; shift
|
||||
tag="$1"; shift
|
||||
|
||||
echo "$base:$(echo "$tag" | sed 's![:/]!-!g')"
|
22
test/tests/paranoid/container.sh
Normal file
22
test/tests/paranoid/container.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
|
||||
|
||||
#
|
||||
# Generate a simple configuration, returns nonzero on error
|
||||
#
|
||||
ovpn_genconfig -u udp://$SERV_IP 2>/dev/null
|
||||
|
||||
export EASYRSA_BATCH=1
|
||||
export EASYRSA_REQ_CN="Travis-CI Test CA"
|
||||
|
||||
#
|
||||
# Initialize the certificate PKI state, returns nonzero on error
|
||||
#
|
||||
ovpn_initpki nopass 2>/dev/null
|
||||
|
||||
#
|
||||
# Test back-up
|
||||
#
|
||||
ovpn_copy_server_files
|
1
test/tests/paranoid/run.sh
Symbolic link
1
test/tests/paranoid/run.sh
Symbolic link
@ -0,0 +1 @@
|
||||
../run-bash-in-container.sh
|
7
test/tests/run-bash-in-container.sh
Executable file
7
test/tests/run-bash-in-container.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
testDir="$(readlink -f "$(dirname "$BASH_SOURCE")")"
|
||||
runDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
||||
|
||||
source "$runDir/run-in-container.sh" "$testDir" "$1" bash ./container.sh
|
46
test/tests/run-in-container.sh
Executable file
46
test/tests/run-in-container.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# NOT INTENDED TO BE USED AS A TEST "run.sh" DIRECTLY
|
||||
# SEE OTHER "run-*-in-container.sh" SCRIPTS FOR USAGE
|
||||
|
||||
testDir="$1"
|
||||
shift
|
||||
|
||||
image="$1"
|
||||
shift
|
||||
entrypoint="$1"
|
||||
shift
|
||||
|
||||
# do some fancy footwork so that if testDir is /a/b/c, we mount /a/b and use c as the working directory (so relative symlinks work one level up)
|
||||
thisDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
||||
testDir="$(readlink -f "$testDir")"
|
||||
testBase="$(basename "$testDir")"
|
||||
hostMount="$(dirname "$testDir")"
|
||||
containerMount="/tmp/test-dir"
|
||||
workdir="$containerMount/$testBase"
|
||||
# TODO should we be doing something fancy with $BASH_SOURCE instead so we can be arbitrarily deep and mount the top level always?
|
||||
|
||||
newImage="$("$thisDir/image-name.sh" librarytest/run-in-container "$image--$testBase")"
|
||||
"$thisDir/docker-build.sh" "$hostMount" "$newImage" <<EOD
|
||||
FROM $image
|
||||
COPY dir $containerMount
|
||||
WORKDIR $workdir
|
||||
ENTRYPOINT ["$entrypoint"]
|
||||
EOD
|
||||
|
||||
args=( --rm )
|
||||
|
||||
# there is strong potential for nokogiri+overlayfs failure
|
||||
# see https://github.com/docker-library/ruby/issues/55
|
||||
gemHome="$(docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' "$newImage" | awk -F '=' '$1 == "GEM_HOME" { print $2; exit }')"
|
||||
if [ "$gemHome" ]; then
|
||||
# must be a Ruby image
|
||||
driver="$(docker info | awk -F ': ' '$1 == "Storage Driver" { print $2; exit }')"
|
||||
if [ "$driver" = 'overlay' ]; then
|
||||
# let's add a volume (_not_ a bind mount) on GEM_HOME to work around nokogiri+overlayfs issues
|
||||
args+=( -v "$gemHome" )
|
||||
fi
|
||||
fi
|
||||
|
||||
exec docker run "${args[@]}" "$newImage" "$@"
|
Reference in New Issue
Block a user