diff --git a/.gitattributes b/.gitattributes index 176a458..cdacba4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -* text=auto +*.sh text eol=lf +* text=auto \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4730c1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM ubuntu:14.04 + +# Install the packages we need +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y php5-cli git php5-mcrypt php5-curl apache2 libapache2-mod-php5 mysql-server php5-mysql memcached php5-memcache php5-mcrypt && \ + apt-get autoremove && \ + apt-get clean && apt-get autoclean + +# Turn on the mcrypt php module and the rewrite\ssl apache modules +RUN php5enmod mcrypt && \ + a2enmod rewrite && \ + a2enmod ssl + +# TODO: Proper ssl certs via letsencrypt or something + +# Configure our path for where we'll serve source-code from +WORKDIR /mnt/flamework +COPY tests/docker/001-flamework.conf /etc/apache2/sites-available/ +RUN a2ensite 001-flamework +RUN a2dissite 000-default + +RUN rm -rf /var/www/html +RUN ln -fs /mnt/flamework/www /var/www/html + +# TODO: PHPUnit via Pear is dead. Also, conditionally install only when running tests? +#RUN apt-get install -y php-pear +#RUN pear channel-discover pear.phpunit.de +#RUN pear install phpunit/PHP_CodeCoverage + +# TODO: Only install when running tests? +#RUN apt-get install -y make +#RUN pecl install xdebug +#RUN echo "zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so" > /etc/php5/conf.d/xdebug.ini + +# Allow mounting of source code from external to the container +VOLUME ["/mnt/flamework"] + +# Optional persistence of the mysql data +VOLUME ["/var/lib/mysql"] + +# Listen on the HTTP and HTTPS ports +EXPOSE 80 +EXPOSE 443 + +# When the container is run, this script will start mysql and apache, +# and put a sample config in place if necessary +ENTRYPOINT [ "/bin/bash", "tests/docker/entrypoint.sh" ] \ No newline at end of file diff --git a/Makefile b/Makefile index 8baafee..72fb4d5 100644 --- a/Makefile +++ b/Makefile @@ -30,3 +30,7 @@ cover: rm -rf ./coverage -make test php -q ./tests/coverage.php + +docker: + docker build -t flamework . + docker run -ti -p80\:8081 -p443\:4331 -v ~/dev/flamework\:/mnt/flamework --name=flamework --rm flamework diff --git a/README.md b/README.md index 2355149..a75d759 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ And some random odds and ends: ## Tests -If you have `make` and and recent `perl` installed (you almost certainly do), you can run the tests using: +If you have `make` and and recent `perl` installed (you almost certainly do, or if not see [Vagrant](#vagrant) and [Docker](#docker) sections below), you can run the tests using: make test @@ -99,3 +99,22 @@ If you don't want to mess with your local development environment, you can run t vagrant ssh cd /vagrant make test + +## Docker + +Similarly, Docker is an option for both local development and test running, but is not suitable for production use (really, REALLY don't use it for prod -- we (intentionally) do not have this configured securely). To build and run: + + docker build -t flamework . + docker run -ti -p80:8081 -p443:4331 -v ~/dev/flamework:/mnt/flamework --name=flamework --rm flamework + +Your local flamework copy should now be listening on ports `8081` and `4331`. Use `docker ps` to verify them. You'll need to edit include/config.php as usual. Since you mounted your local dev flamework directory into the container, any code changes you make should be reflected immediately. + +Once the container is running, to run tests you can do: + + docker exec -ti flamework make test + +And to tail the error logs: + + docker exec -ti flamework tail -F /var/log/apache2/error.log + +When killing the container using either `CTRL+C` or `docker stop flamework`, the container will be removed and all data will be reset next run. This is useful for running tests. \ No newline at end of file diff --git a/tests/02_http_codes.t b/tests/02_http_codes.t index 9717eee..9b523ed 100644 --- a/tests/02_http_codes.t +++ b/tests/02_http_codes.t @@ -91,7 +91,7 @@ foreach ($codes as $row){ - $ret = http_get("http://www.iamcal.com/misc/test/code.php?code={$row[0]}&msg=".urlencode($row[1])); + $ret = http_get("https://www.iamcal.com/misc/test/code.php?code={$row[0]}&msg=".urlencode($row[1])); $test = "{$row[0]}: {$row[1]}"; if (isset($row[2])) $test .= " {$row[2]}"; diff --git a/tests/02_http_methods.t b/tests/02_http_methods.t index 13ce7bf..9da59ab 100644 --- a/tests/02_http_methods.t +++ b/tests/02_http_methods.t @@ -25,17 +25,17 @@ } - $ret = http_get("http://www.iamcal.com/misc/test/method.php"); + $ret = http_get("https://www.iamcal.com/misc/test/method.php"); test_http_method($ret, 'GET', 0, 0); - $ret = http_get("http://www.iamcal.com/misc/test/method.php?a=1&b=2"); + $ret = http_get("https://www.iamcal.com/misc/test/method.php?a=1&b=2"); test_http_method($ret, 'GET', 2, 0); - $ret = http_head("http://www.iamcal.com/misc/test/method.php"); + $ret = http_head("https://www.iamcal.com/misc/test/method.php"); test_http_method($ret, 'HEAD', 0, 0); - $ret = http_post("http://www.iamcal.com/misc/test/method.php", array()); + $ret = http_post("https://www.iamcal.com/misc/test/method.php", array()); test_http_method($ret, 'POST', 0, 0); - $ret = http_post("http://www.iamcal.com/misc/test/method.php?a=1", array('b' => 2, 'c' => 3)); + $ret = http_post("https://www.iamcal.com/misc/test/method.php?a=1", array('b' => 2, 'c' => 3)); test_http_method($ret, 'POST', 1, 2); diff --git a/tests/docker/001-flamework.conf b/tests/docker/001-flamework.conf new file mode 100644 index 0000000..0e5a813 --- /dev/null +++ b/tests/docker/001-flamework.conf @@ -0,0 +1,49 @@ + + DocumentRoot /var/www/html + + + Options +Indexes +FollowSymLinks -MultiViews + AllowOverride All + Order allow,deny + allow from all + require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + + # Possible values include: debug, info, notice, warn, error, crit, + # alert, emerg. + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/access.log combined + + RewriteEngine on + #RewriteLog ${APACHE_LOG_DIR}/rewrite.log + #RewriteLogLevel 3 + + DirectoryIndex index.php + + + + DocumentRoot /var/www/html + + + Options +Indexes -MultiViews + AllowOverride All + Order allow,deny + allow from all + require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + LogLevel warn + CustomLog ${APACHE_LOG_DIR}/access.log combined + + RewriteEngine on + + DirectoryIndex index.php + + SSLEngine on + SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem + SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key + \ No newline at end of file diff --git a/tests/docker/entrypoint.sh b/tests/docker/entrypoint.sh new file mode 100644 index 0000000..c643748 --- /dev/null +++ b/tests/docker/entrypoint.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# We want to halt on errors and also print out what we're doing +set -eux + +# Start memcached +/etc/init.d/memcached start + +# Start mysql and create the database if it doesn't exist +/etc/init.d/mysql start +mysql -e 'CREATE DATABASE IF NOT EXISTS flamework;' +mysql -Dflamework < schema/db_main.schema + +# Put the example configuration in place if it doesn't exist +cd /mnt/flamework +if [[ ! -e www/include/config.php ]]; then + cp www/include/config.php.example www/include/config.php + perl -i -pe "s/'pass'\t=> 'root',/'pass'\t=> '',/g" www/include/config.php +fi + +# Templates need to be writable by the web server +chown www-data www/templates_c +chmod 755 www/templates_c + +# Start apache in the foreground so that the container stays running +exec apachectl -D FOREGROUND \ No newline at end of file