Skip to content

Commit c6d7a86

Browse files
author
Jonathan Gaillard
committed
Merge pull request #26 from nubs/docker-build
Create a docker-based build.
2 parents 48f9537 + eac41c4 commit c6d7a86

6 files changed

Lines changed: 79 additions & 5 deletions

File tree

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM base/archlinux
2+
3+
RUN pacman --sync --refresh --noconfirm --noprogressbar --quiet
4+
RUN pacman --sync --noconfirm --noprogressbar --quiet php xdebug php-mongo git openssh
5+
6+
ADD provisioning/php/php-extensions.ini /etc/php/conf.d/extensions.ini
7+
ADD provisioning/php/xdebug.ini /etc/php/conf.d/xdebug.ini
8+
ADD provisioning/set-env.sh /set-env.sh
9+
10+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
11+
12+
VOLUME ["/code"]
13+
14+
ENTRYPOINT ["/set-env.sh"]
15+
CMD ["/code/build.php"]

dockerBuild.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env php
2+
<?php
3+
$returnStatus = null;
4+
passthru('docker build --tag=mongo-queue-php ' . __DIR__, $returnStatus);
5+
if ($returnStatus !== 0) {
6+
exit(1);
7+
}
8+
9+
passthru(
10+
'docker run --name mongo-queue-php-build --tty --rm --volume ' . __DIR__ . ':/code ' . createLink('mongo') . ' mongo-queue-php',
11+
$returnStatus
12+
);
13+
if ($returnStatus !== 0) {
14+
exit(1);
15+
}
16+
17+
function createLink($name)
18+
{
19+
$returnStatus = null;
20+
passthru("docker inspect --format='{{.Name}}' mongo-queue-php-{$name}", $returnStatus);
21+
if ($returnStatus !== 0) {
22+
passthru("docker run --name mongo-queue-php-{$name} --detach {$name}", $returnStatus);
23+
if ($returnStatus !== 0) {
24+
exit(1);
25+
}
26+
}
27+
28+
return "--link mongo-queue-php-{$name}:{$name}";
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[PHP]
2+
open_basedir =
3+
4+
extension = openssl.so
5+
extension = phar.so
6+
extension = zip.so
7+
8+
[Date]
9+
date.timezone = America/New_York

provisioning/php/xdebug.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zend_extension=/usr/lib/php/modules/xdebug.so

provisioning/set-env.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
if test -z "${MONGO_PORT_27017_TCP_ADDR}" -o -z "${MONGO_PORT_27017_TCP_PORT}"; then
3+
echo "You must link this container with mongo first"
4+
exit 1
5+
fi
6+
7+
export TESTING_MONGO_URL="mongodb://${MONGO_PORT_27017_TCP_ADDR}:${MONGO_PORT_27017_TCP_PORT}"
8+
9+
# See http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
10+
while ! exec 6<>/dev/tcp/${MONGO_PORT_27017_TCP_ADDR}/${MONGO_PORT_27017_TCP_PORT}; do
11+
echo "$(date) - still trying to connect to mongo at ${TESTING_MONGO_URL}"
12+
sleep 1
13+
done
14+
15+
exec 6>&-
16+
exec 6<&-
17+
18+
$@

tests/QueueTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
final class QueueTest extends \PHPUnit_Framework_TestCase
1010
{
1111
private $_collection;
12+
private $_mongoUrl;
1213
private $_queue;
1314

1415
public function setUp()
1516
{
16-
$mongo = new \MongoClient('mongodb://localhost');
17+
$this->_mongoUrl = getenv('TESTING_MONGO_URL') ?: 'mongodb://localhost:27017';
18+
$mongo = new \MongoClient($this->_mongoUrl);
1719
$this->_collection = $mongo->selectDB('testing')->selectCollection('messages');
1820
$this->_collection->drop();
1921

20-
$this->_queue = new Queue('mongodb://localhost', 'testing', 'messages');
22+
$this->_queue = new Queue($this->_mongoUrl, 'testing', 'messages');
2123
}
2224

2325
/**
@@ -37,7 +39,7 @@ public function constructWithNonStringUrl()
3739
*/
3840
public function constructWithNonStringDb()
3941
{
40-
new Queue('mongodb://localhost', true, 'messages');
42+
new Queue($this->_mongoUrl, true, 'messages');
4143
}
4244

4345
/**
@@ -47,7 +49,7 @@ public function constructWithNonStringDb()
4749
*/
4850
public function constructWithNonStringCollection()
4951
{
50-
new Queue('mongodb://localhost', 'testing', new \stdClass());
52+
new Queue($this->_mongoUrl, 'testing', new \stdClass());
5153
}
5254

5355
/**
@@ -84,7 +86,7 @@ public function ensureGetIndexWithTooLongCollectionName()
8486
$collectionName = 'messages012345678901234567890123456789012345678901234567890123456789';
8587
$collectionName .= '012345678901234567890123456789012345678901234567890123456789';//128 chars
8688

87-
$queue = new Queue('mongodb://localhost', 'testing', $collectionName);
89+
$queue = new Queue($this->_mongoUrl, 'testing', $collectionName);
8890
$queue->ensureGetIndex(array());
8991
}
9092

0 commit comments

Comments
 (0)