run.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Build a client image with cgi-fcgi for testing
  6. clientImage='librarytest/php-fpm-hello-web:fcgi'
  7. docker build -t "$clientImage" - > /dev/null <<'EOF'
  8. FROM debian:jessie
  9. RUN set -x && apt-get update && apt-get install -y libfcgi0ldbl && rm -rf /var/lib/apt/lists/*
  10. ENTRYPOINT ["cgi-fcgi"]
  11. EOF
  12. # Create an instance of the container-under-test
  13. cid="$(docker run -d -v "$dir/index.php":/var/www/html/index.php:ro "$image")"
  14. trap "docker rm -vf $cid > /dev/null" EXIT
  15. # RACY TESTS ARE RACY
  16. sleep 1
  17. # TODO find a cleaner solution to this, similar to what we do in mysql-basics
  18. fcgi-request() {
  19. local method="$1"
  20. local url="$2"
  21. local queryString=
  22. if [[ "$url" == *\?* ]]; then
  23. queryString="${url#*\?}"
  24. url="${url%%\?*}"
  25. fi
  26. docker run --rm -i --link "$cid":fpm \
  27. -e REQUEST_METHOD="$method" \
  28. -e SCRIPT_NAME="$url" \
  29. -e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
  30. -e QUERY_STRING="$queryString" \
  31. "$clientImage" \
  32. -bind -connect fpm:9000
  33. }
  34. # Check that we can request /index.php with no params
  35. [ -n "$(fcgi-request GET "/index.php")" ]
  36. # Check that our index.php echoes the value of the "hello" param
  37. hello="world-$RANDOM-$RANDOM"
  38. [ "$(fcgi-request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]