-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea92410
commit e42d0df
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
[ "$DEBUG" ] && set -x | ||
|
||
set -eo pipefail | ||
|
||
# check if we have ipv6 available | ||
if [ ! -f "/proc/net/if_inet6" ]; then | ||
exit 0 | ||
fi | ||
|
||
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")" | ||
|
||
image="$1" | ||
|
||
clientImage='buildpack-deps:buster-curl' | ||
# ensure the clientImage is ready and available | ||
if ! docker image inspect "$clientImage" &> /dev/null; then | ||
docker pull "$clientImage" > /dev/null | ||
fi | ||
|
||
# Create a new Docker network | ||
nid="$(docker network create --ipv6 --subnet fd0c:7e57::/64 nginx-test-ipv6-network)" | ||
trap "docker network rm -f $nid > /dev/null" EXIT | ||
|
||
# Create an instance of the container-under-test | ||
serverImage="$("$HOME/oi/test/tests/image-name.sh" librarytest/nginx-template "$image")" | ||
"$HOME/oi/test/tests/docker-build.sh" "$dir" "$serverImage" <<EOD | ||
FROM $image | ||
COPY dir/server.conf.template /etc/nginx/templates/server.conf.template | ||
EOD | ||
cid="$(docker run -d --network $nid -e NGINX_ENTRYPOINT_LOCAL_RESOLVERS=true -e NGINX_MY_SERVER_NAME=example.com "$serverImage")" | ||
trap "docker rm -vf $cid > /dev/null" EXIT | ||
|
||
_request() { | ||
local method="$1" | ||
shift | ||
|
||
local proto="$1" | ||
shift | ||
|
||
local url="${1#/}" | ||
shift | ||
|
||
if [ "$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null)" != 'true' ]; then | ||
echo >&2 "$image stopped unexpectedly!" | ||
( set -x && docker logs "$cid" ) >&2 || true | ||
false | ||
fi | ||
|
||
docker run --rm \ | ||
--link "$cid":nginx \ | ||
"$clientImage" \ | ||
curl -fsSL -X"$method" --connect-to '::nginx:' "$@" "$proto://example.com/$url" | ||
} | ||
|
||
. "$HOME/oi/test/retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]' | ||
|
||
# Check that we can request / | ||
_request GET http '/resolver-templates' | grep 'example.com - OK' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resolver ${NGINX_LOCAL_RESOLVERS}; | ||
|
||
server { | ||
listen 80; | ||
server_name ${NGINX_MY_SERVER_NAME}; | ||
default_type text/plain; | ||
location = / { return 200 'OK\n'; } | ||
location / { return 200 "${NGINX_MY_SERVER_NAME} - OK\n"; } | ||
} |