Ver código fonte

Add simple initial wordpress-apache-run and wordpress-fpm-run tests

Tianon Gravi 9 anos atrás
pai
commit
092458e6fd

+ 5 - 1
test/config.sh

@@ -171,7 +171,11 @@ imageTests+=(
 	[tomcat]='
 		tomcat-hello-world
 	'
-	[wordpress]='
+	[wordpress:apache]='
+		wordpress-apache-run
+	'
+	[wordpress:fpm]='
+		wordpress-fpm-run
 	'
 # example onbuild
 #	[python:onbuild]='

+ 11 - 5
test/run.sh

@@ -99,11 +99,17 @@ for dockerImage in "$@"; do
 	#version="${tagVar%-*}"
 	variant="${tagVar##*-}"
 	
-	if [[ "$tagVar" == *onbuild* ]]; then
-		# "maven:onbuild-alpine" is still onbuild
-		# ONCE ONBUILD, ALWAYS ONBUILD
-		variant='onbuild'
-	fi
+	case "$tagVar" in
+		*onbuild*)
+			# "maven:onbuild-alpine" is still onbuild
+			# ONCE ONBUILD, ALWAYS ONBUILD
+			variant='onbuild'
+			;;
+		*fpm-alpine)
+			# lolPHP
+			variant='fpm'
+			;;
+	esac
 	
 	testRepo="$repo"
 	if [ -z "$keepNamespace" ]; then

+ 36 - 0
test/tests/wordpress-apache-run/run.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+set -eo pipefail
+
+dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+# since we have curl in the php image, we'll use that
+clientImage="$1"
+
+mysqlImage='mysql:5.7'
+serverImage="$1"
+
+# Create an instance of the container-under-test
+mysqlCid="$(docker run -d -e MYSQL_ROOT_PASSWORD="test-$RANDOM-password-$RANDOM-$$" "$mysqlImage")"
+trap "docker rm -vf $mysqlCid > /dev/null" EXIT
+cid="$(docker run -d --link "$mysqlCid":mysql "$serverImage")"
+trap "docker rm -vf $cid $mysqlCid > /dev/null" EXIT
+
+_request() {
+	local method="$1"
+	shift
+
+	local url="${1#/}"
+	shift
+
+	docker run --rm --link "$cid":apache "$clientImage" \
+		curl -fsL -X"$method" "$@" "http://apache/$url"
+}
+
+# Make sure that Apache is listening and ready
+. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
+# (give it a bit long since it won't start until MySQL is started and ready)
+
+# Check that we can request / and that it contains the word "setup" somewhere
+# <form id="setup" method="post" action="?step=1"><label class='screen-reader-text' for='language'>Select a default language</label>
+_request GET '/' |tac|tac| grep -iq setup
+# (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)

+ 31 - 0
test/tests/wordpress-fpm-run/nginx-default.conf

@@ -0,0 +1,31 @@
+# adapted from https://gist.github.com/md5/d9206eacb5a0ff5d6be0#file-wordpress-fpm-conf
+
+server {
+	listen 80;
+	root /var/www/html;
+
+	client_max_body_size 0;
+
+	index index.php;
+
+	location / {
+		try_files $uri $uri/ /index.php?$args;
+	}
+
+	rewrite /wp-admin$ $scheme://$host$uri/ permanent;
+
+	location ~ [^/]\.php(/|$) {
+		fastcgi_split_path_info ^(.+?\.php)(/.*)$;
+		if (!-f $document_root$fastcgi_script_name) {
+			return 404;
+		}
+
+		include fastcgi_params;
+		fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
+		#fastcgi_param PATH_INFO       $fastcgi_path_info;
+		#fastcgi_param PATH_TRANSLATED /var/www/html/$fastcgi_path_info;
+
+		fastcgi_pass fpm:9000;
+		fastcgi_index index.php;
+	}
+}

+ 45 - 0
test/tests/wordpress-fpm-run/run.sh

@@ -0,0 +1,45 @@
+#!/bin/bash
+set -eo pipefail
+
+dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+# since we have curl in the php image, we'll use that
+clientImage="$1"
+
+# Build a client image with cgi-fcgi for testing
+nginxImage="$("$dir/../image-name.sh" librarytest/wordpress-fpm-run-nginx "$1")"
+"$dir/../docker-build.sh" "$dir" "$nginxImage" <<EOD
+FROM nginx:alpine
+COPY dir/nginx-default.conf /etc/nginx/conf.d/default.conf
+EOD
+
+mysqlImage='mysql:5.7'
+serverImage="$1"
+
+# Create an instance of the container-under-test
+mysqlCid="$(docker run -d -e MYSQL_ROOT_PASSWORD="test-$RANDOM-password-$RANDOM-$$" "$mysqlImage")"
+trap "docker rm -vf $mysqlCid > /dev/null" EXIT
+cid="$(docker run -d --link "$mysqlCid":mysql "$serverImage")"
+trap "docker rm -vf $cid $mysqlCid > /dev/null" EXIT
+nginxCid="$(docker run -d --link "$cid":fpm --volumes-from "$cid" "$nginxImage")"
+trap "docker rm -vf $nginxCid $cid $mysqlCid > /dev/null" EXIT
+
+_request() {
+	local method="$1"
+	shift
+
+	local url="${1#/}"
+	shift
+
+	docker run --rm --link "$nginxCid":nginx "$clientImage" \
+		curl -fsL -X"$method" "$@" "http://nginx/$url"
+}
+
+# Make sure that PHP-FPM is listening and ready
+. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
+# (give it a bit long since it won't start until MySQL is started and ready)
+
+# Check that we can request / and that it contains the word "setup" somewhere
+# <form id="setup" method="post" action="?step=1"><label class='screen-reader-text' for='language'>Select a default language</label>
+_request GET '/' |tac|tac| grep -iq setup
+# (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)