Skip to content

Commit b867131

Browse files
author
Eugene Leonovich
committed
Generate dockerfiles on the fly
1 parent ff3826f commit b867131

File tree

5 files changed

+50
-43
lines changed

5 files changed

+50
-43
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
vendor/
2-
composer.lock
3-
phpunit.xml
1+
/vendor/
2+
/composer.lock
3+
/coverage.clover
4+
/phpunit.xml

.travis.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,27 @@ services:
66
- docker
77

88
env:
9-
- PHP_VERSION=5.4
10-
- PHP_VERSION=5.5
11-
- PHP_VERSION=5.6
9+
- PHP_RUNTIME='php:5.4-cli'
10+
- PHP_RUNTIME='php:5.5-cli'
11+
- PHP_RUNTIME='php:5.6-cli' PHPUNIT_OPTS='--coverage-clover coverage.clover'
12+
- PHP_RUNTIME='php:7.0-cli'
1213

1314
before_install:
1415
# https://github.com/travis-ci/travis-ci/issues/4778
1516
# https://github.com/zuazo/kitchen-in-travis-native/issues/1#issuecomment-142230889
1617
- sudo iptables -L DOCKER || (echo "DOCKER iptables chain missing"; sudo iptables -N DOCKER)
1718

18-
# https://github.com/docker/docker/issues/14634
19-
# https://github.com/docker/docker/pull/15182
20-
- sed -i -r "s/^(FROM\s+php:).*(-cli)$/\1$PHP_VERSION\2/g" Dockerfile
21-
2219
install:
23-
- docker build -t queue .
24-
25-
before_script:
26-
- if [[ $PHP_VERSION == 5.6 ]]; then COVERAGE="--coverage-clover coverage.clover"; else COVERAGE=""; fi
20+
- ./dockerfile.sh | docker build -t msgpack -
2721

2822
script:
2923
- docker run -d --name tarantool -v $(pwd):/queue tarantool/tarantool /queue/tests/Integration/instance.lua
30-
- docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue bash -c "composer install && TARANTOOL_HOST=tarantool TARANTOOL_PORT=3301 phpunit $COVERAGE"
24+
- docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue
3125

3226
after_script:
33-
- >
34-
if [[ ! -z "$COVERAGE" ]]; then
35-
docker run --rm --name queue -v $(pwd):/queue -w /queue queue bash -c "
36-
curl -sSOL https://scrutinizer-ci.com/ocular.phar &&
37-
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
38-
"
27+
docker run --rm --name queue -v $(pwd):/queue -w /queue queue bash -c "
28+
if [[ -f coverage.clover ]]; then
29+
curl -sSOL https://scrutinizer-ci.com/ocular.phar &&
30+
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
3931
fi
32+
"

Dockerfile

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,14 @@ $ docker run -d --name tarantool -v $(pwd):/queue tarantool/tarantool \
233233
And then run both unit and integration tests:
234234

235235
```sh
236-
$ docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue \
237-
bash -c "composer install && \
238-
TARANTOOL_HOST=tarantool TARANTOOL_PORT=3301 \
239-
phpunit"
236+
$ docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue
240237
```
241238

242-
To run only unit or integration tests, add either `--testsuite Unit` or `--testsuite Integration` respectively, e.g.:
239+
To run only unit or integration tests, set the `PHPUNIT_OPTS` environment variable to either `--testsuite Unit`
240+
or `--testsuite Integration` respectively, e.g.:
243241

244242
```sh
245-
$ docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue \
246-
bash -c "composer install && \
247-
TARANTOOL_HOST=tarantool TARANTOOL_PORT=3301 \
248-
phpunit --testsuite Integration"
243+
$ PHPUNIT_OPTS='--testsuite Integration' docker run --rm --name queue --link tarantool -v $(pwd):/queue -w /queue queue
249244
```
250245

251246

dockerfile.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z "$PHP_RUNTIME" ]] ; then
4+
PHP_RUNTIME='php:5.6-cli'
5+
fi
6+
7+
RUN_CMDS=''
8+
9+
if [[ $PHP_RUNTIME == php* ]]; then
10+
RUN_CMDS="$RUN_CMDS && \\\\\n docker-php-ext-install zip"
11+
fi
12+
13+
if [[ $PHPUNIT_OPTS =~ (^|[[:space:]])--clover-[[:alpha:]] ]]; then
14+
RUN_CMDS="$RUN_CMDS && \\\\\n git clone https://github.com/xdebug/xdebug.git /usr/src/php/ext/xdebug"
15+
RUN_CMDS="$RUN_CMDS && \\\\\n docker-php-ext-install xdebug"
16+
fi
17+
18+
echo -e "
19+
FROM $PHP_RUNTIME
20+
21+
RUN apt-get update && \\
22+
apt-get install -y git curl zlib1g-dev${RUN_CMDS} && \\
23+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \\
24+
composer global require 'phpunit/phpunit:^4.8|^5.0'
25+
26+
ENV PATH ~/.composer/vendor/bin:\$PATH
27+
ENV TARANTOOL_HOST=tarantool
28+
ENV TARANTOOL_PORT=3301
29+
30+
CMD if [ ! -f composer.lock ]; then composer install; fi && ~/.composer/vendor/bin/phpunit${PHPUNIT_OPTS:+ }$PHPUNIT_OPTS
31+
"

0 commit comments

Comments
 (0)