run.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-client'
  7. docker build -t "$clientImage" - > /dev/null <<'EOF'
  8. FROM debian:stretch-slim
  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. serverImage="$("$dir/../image-name.sh" librarytest/php-fpm-hello-web "$image")"
  13. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  14. FROM $image
  15. COPY dir/index.php /var/www/html/
  16. EOD
  17. # Create an instance of the container-under-test
  18. cid="$(docker run -d "$serverImage")"
  19. trap "docker rm -vf $cid > /dev/null" EXIT
  20. # RACY TESTS ARE RACY
  21. sleep 1
  22. # TODO find a cleaner solution to this, similar to what we do in mysql-basics
  23. fcgi-request() {
  24. local method="$1"
  25. local url="$2"
  26. local queryString=
  27. if [[ "$url" == *\?* ]]; then
  28. queryString="${url#*\?}"
  29. url="${url%%\?*}"
  30. fi
  31. docker run --rm -i --link "$cid":fpm \
  32. -e REQUEST_METHOD="$method" \
  33. -e SCRIPT_NAME="$url" \
  34. -e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
  35. -e QUERY_STRING="$queryString" \
  36. "$clientImage" \
  37. -bind -connect fpm:9000
  38. }
  39. # Check that we can request /index.php with no params
  40. [ -n "$(fcgi-request GET "/index.php")" ]
  41. # Check that our index.php echoes the value of the "hello" param
  42. hello="world-$RANDOM-$RANDOM"
  43. [ "$(fcgi-request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]