run.sh 986 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. set -e
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Build a client image with cgi-fcgi for testing
  6. client_image="php-fpm-client-$RANDOM-$RANDOM"
  7. docker build -q -t "$client_image" - > /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. cname="php-fpm-container-$RANDOM-$RANDOM"
  14. cid="$(docker run -d -v "$dir/index.php":/var/www/html/index.php:ro --name "$cname" "$image")"
  15. trap "docker rm -f $cid > /dev/null" EXIT
  16. cgi-fcgi() {
  17. docker run --rm -i --link "$cname":fpm \
  18. -e REQUEST_METHOD=GET \
  19. -e SCRIPT_NAME=/index.php \
  20. -e SCRIPT_FILENAME=/var/www/html/index.php \
  21. -e QUERY_STRING="$1" \
  22. "$client_image" \
  23. -bind -connect fpm:9000
  24. }
  25. # Check that our index.php echoes the value of the "hello" param
  26. hello="world-$RANDOM-$RANDOM"
  27. [ "$(cgi-fcgi hello="$hello" | tail -1)" = "$hello" ]