Files
Tianon Gravi c16b7e1cc2 Fix "docker-build.sh" wrapper to handle images with ONBUILD instructions more automatically
The way we handle this semi-gracefully is to create a fake "docker save" tarball that contains just a single layer whose parent is the image we're wanting to test, and whose "config" is the same as the parent image, but with "OnBuild" nulled out, and adjust the build to use that new layer as the base for the build instead.
2015-11-13 11:17:30 -08:00

46 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -eo pipefail
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
image="$1"
serverImage="$("$dir/../image-name.sh" librarytest/postgres-initdb "$image")"
"$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
FROM $image
COPY dir/initdb.sql /docker-entrypoint-initdb.d/
EOD
export POSTGRES_USER='my cool postgres user'
export POSTGRES_PASSWORD='my cool postgres password'
export POSTGRES_DB='my cool postgres database'
cname="postgres-container-$RANDOM-$RANDOM"
cid="$(
docker run -d \
-e POSTGRES_USER \
-e POSTGRES_PASSWORD \
-e POSTGRES_DB \
--name "$cname" \
"$serverImage"
)"
trap "docker rm -vf $cid > /dev/null" EXIT
psql() {
docker run --rm -i \
--link "$cname":postgres \
--entrypoint psql \
-e PGPASSWORD="$POSTGRES_PASSWORD" \
"$image" \
--host postgres \
--username "$POSTGRES_USER" \
--dbname "$POSTGRES_DB" \
--quiet --no-align --tuples-only \
"$@"
}
. "$dir/../../retry.sh" --tries "$POSTGRES_TEST_TRIES" --sleep "$POSTGRES_TEST_SLEEP" "echo 'SELECT 1' | psql"
[ "$(echo 'SELECT COUNT(*) FROM test' | psql)" = 1 ]
[ "$(echo 'SELECT c FROM test' | psql)" = 'goodbye!' ]