Skip to content

Commit 6a8a312

Browse files
authored
Merge pull request #34 from exflickr/docker
Docker support
2 parents b6b8b75 + 903a059 commit 6a8a312

8 files changed

Lines changed: 156 additions & 8 deletions

File tree

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
* text=auto
1+
*.sh text eol=lf
2+
* text=auto

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM ubuntu:14.04
2+
3+
# Install the packages we need
4+
RUN export DEBIAN_FRONTEND=noninteractive && \
5+
apt-get update && \
6+
apt-get upgrade -y && \
7+
apt-get install -y php5-cli git php5-mcrypt php5-curl apache2 libapache2-mod-php5 mysql-server php5-mysql memcached php5-memcache php5-mcrypt && \
8+
apt-get autoremove && \
9+
apt-get clean && apt-get autoclean
10+
11+
# Turn on the mcrypt php module and the rewrite\ssl apache modules
12+
RUN php5enmod mcrypt && \
13+
a2enmod rewrite && \
14+
a2enmod ssl
15+
16+
# TODO: Proper ssl certs via letsencrypt or something
17+
18+
# Configure our path for where we'll serve source-code from
19+
WORKDIR /mnt/flamework
20+
COPY tests/docker/001-flamework.conf /etc/apache2/sites-available/
21+
RUN a2ensite 001-flamework
22+
RUN a2dissite 000-default
23+
24+
RUN rm -rf /var/www/html
25+
RUN ln -fs /mnt/flamework/www /var/www/html
26+
27+
# TODO: PHPUnit via Pear is dead. Also, conditionally install only when running tests?
28+
#RUN apt-get install -y php-pear
29+
#RUN pear channel-discover pear.phpunit.de
30+
#RUN pear install phpunit/PHP_CodeCoverage
31+
32+
# TODO: Only install when running tests?
33+
#RUN apt-get install -y make
34+
#RUN pecl install xdebug
35+
#RUN echo "zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so" > /etc/php5/conf.d/xdebug.ini
36+
37+
# Allow mounting of source code from external to the container
38+
VOLUME ["/mnt/flamework"]
39+
40+
# Optional persistence of the mysql data
41+
VOLUME ["/var/lib/mysql"]
42+
43+
# Listen on the HTTP and HTTPS ports
44+
EXPOSE 80
45+
EXPOSE 443
46+
47+
# When the container is run, this script will start mysql and apache,
48+
# and put a sample config in place if necessary
49+
ENTRYPOINT [ "/bin/bash", "tests/docker/entrypoint.sh" ]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ cover:
3030
rm -rf ./coverage
3131
-make test
3232
php -q ./tests/coverage.php
33+
34+
docker:
35+
docker build -t flamework .
36+
docker run -ti -p80\:8081 -p443\:4331 -v ~/dev/flamework\:/mnt/flamework --name=flamework --rm flamework

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ And some random odds and ends:
8080

8181
## Tests
8282

83-
If you have `make` and and recent `perl` installed (you almost certainly do), you can run the tests using:
83+
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:
8484

8585
make test
8686

@@ -99,3 +99,22 @@ If you don't want to mess with your local development environment, you can run t
9999
vagrant ssh
100100
cd /vagrant
101101
make test
102+
103+
## Docker
104+
105+
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:
106+
107+
docker build -t flamework .
108+
docker run -ti -p80:8081 -p443:4331 -v ~/dev/flamework:/mnt/flamework --name=flamework --rm flamework
109+
110+
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.
111+
112+
Once the container is running, to run tests you can do:
113+
114+
docker exec -ti flamework make test
115+
116+
And to tail the error logs:
117+
118+
docker exec -ti flamework tail -F /var/log/apache2/error.log
119+
120+
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.

tests/02_http_codes.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
foreach ($codes as $row){
9393

94-
$ret = http_get("http://www.iamcal.com/misc/test/code.php?code={$row[0]}&msg=".urlencode($row[1]));
94+
$ret = http_get("https://www.iamcal.com/misc/test/code.php?code={$row[0]}&msg=".urlencode($row[1]));
9595

9696
$test = "{$row[0]}: {$row[1]}";
9797
if (isset($row[2])) $test .= " {$row[2]}";

tests/02_http_methods.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
}
2626

2727

28-
$ret = http_get("http://www.iamcal.com/misc/test/method.php");
28+
$ret = http_get("https://www.iamcal.com/misc/test/method.php");
2929
test_http_method($ret, 'GET', 0, 0);
3030

31-
$ret = http_get("http://www.iamcal.com/misc/test/method.php?a=1&b=2");
31+
$ret = http_get("https://www.iamcal.com/misc/test/method.php?a=1&b=2");
3232
test_http_method($ret, 'GET', 2, 0);
3333

34-
$ret = http_head("http://www.iamcal.com/misc/test/method.php");
34+
$ret = http_head("https://www.iamcal.com/misc/test/method.php");
3535
test_http_method($ret, 'HEAD', 0, 0);
3636

37-
$ret = http_post("http://www.iamcal.com/misc/test/method.php", array());
37+
$ret = http_post("https://www.iamcal.com/misc/test/method.php", array());
3838
test_http_method($ret, 'POST', 0, 0);
3939

40-
$ret = http_post("http://www.iamcal.com/misc/test/method.php?a=1", array('b' => 2, 'c' => 3));
40+
$ret = http_post("https://www.iamcal.com/misc/test/method.php?a=1", array('b' => 2, 'c' => 3));
4141
test_http_method($ret, 'POST', 1, 2);

tests/docker/001-flamework.conf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/html
3+
4+
<Directory /var/www/html>
5+
Options +Indexes +FollowSymLinks -MultiViews
6+
AllowOverride All
7+
Order allow,deny
8+
allow from all
9+
require all granted
10+
</Directory>
11+
12+
ErrorLog ${APACHE_LOG_DIR}/error.log
13+
14+
# Possible values include: debug, info, notice, warn, error, crit,
15+
# alert, emerg.
16+
LogLevel warn
17+
18+
CustomLog ${APACHE_LOG_DIR}/access.log combined
19+
20+
RewriteEngine on
21+
#RewriteLog ${APACHE_LOG_DIR}/rewrite.log
22+
#RewriteLogLevel 3
23+
24+
DirectoryIndex index.php
25+
</VirtualHost>
26+
27+
<VirtualHost *:443>
28+
DocumentRoot /var/www/html
29+
30+
<Directory /var/www/html>
31+
Options +Indexes -MultiViews
32+
AllowOverride All
33+
Order allow,deny
34+
allow from all
35+
require all granted
36+
</Directory>
37+
38+
ErrorLog ${APACHE_LOG_DIR}/error.log
39+
LogLevel warn
40+
CustomLog ${APACHE_LOG_DIR}/access.log combined
41+
42+
RewriteEngine on
43+
44+
DirectoryIndex index.php
45+
46+
SSLEngine on
47+
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
48+
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
49+
</VirtualHost>

tests/docker/entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to halt on errors and also print out what we're doing
4+
set -eux
5+
6+
# Start memcached
7+
/etc/init.d/memcached start
8+
9+
# Start mysql and create the database if it doesn't exist
10+
/etc/init.d/mysql start
11+
mysql -e 'CREATE DATABASE IF NOT EXISTS flamework;'
12+
mysql -Dflamework < schema/db_main.schema
13+
14+
# Put the example configuration in place if it doesn't exist
15+
cd /mnt/flamework
16+
if [[ ! -e www/include/config.php ]]; then
17+
cp www/include/config.php.example www/include/config.php
18+
perl -i -pe "s/'pass'\t=> 'root',/'pass'\t=> '',/g" www/include/config.php
19+
fi
20+
21+
# Templates need to be writable by the web server
22+
chown www-data www/templates_c
23+
chmod 755 www/templates_c
24+
25+
# Start apache in the foreground so that the container stays running
26+
exec apachectl -D FOREGROUND

0 commit comments

Comments
 (0)