Skip to content

Commit

Permalink
Merge pull request #34 from exflickr/docker
Browse files Browse the repository at this point in the history
Docker support
  • Loading branch information
grantmd authored Oct 5, 2022
2 parents b6b8b75 + 903a059 commit 6a8a312
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.sh text eol=lf
* text=auto
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <code>include/config.php</code> 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.
2 changes: 1 addition & 1 deletion tests/02_http_codes.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]}";
Expand Down
10 changes: 5 additions & 5 deletions tests/02_http_methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);
49 changes: 49 additions & 0 deletions tests/docker/001-flamework.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<VirtualHost *:80>
DocumentRoot /var/www/html

<Directory /var/www/html>
Options +Indexes +FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
allow from all
require all granted
</Directory>

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
</VirtualHost>

<VirtualHost *:443>
DocumentRoot /var/www/html

<Directory /var/www/html>
Options +Indexes -MultiViews
AllowOverride All
Order allow,deny
allow from all
require all granted
</Directory>

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
</VirtualHost>
26 changes: 26 additions & 0 deletions tests/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6a8a312

Please sign in to comment.