Skip to content

Commit

Permalink
[Travis] Add docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
GeLoLabs committed Feb 11, 2017
1 parent ccdf346 commit 3a40195
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .env.dist
@@ -1,7 +1,14 @@
# IDE
IDE_SERVER_NAME=ivory-http-adapter

# Permissions
GROUP_ID=1000
USER_ID=1000

# Symfony deprecations
SYMFONY_DEPRECATIONS_HELPER=strict

# XDebug
XDEBUG=0
XDEBUG_HOST=192.168.0.1
XDEBUG_PORT=9000
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,5 +1,6 @@
/docker export-ignore
/tests export-ignore
/travis export-ignore
/.env.dist export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
28 changes: 7 additions & 21 deletions .travis.yml
Expand Up @@ -16,33 +16,19 @@ env:
- TEST_SERVER=http://127.0.0.1:10000/server.php
- SYMFONY_DEPRECATIONS_HELPER=strict
- GUZZLE_VERSION=6.*
- DOCKER_BUILD=false
- COMPOSER_PREFER_LOWEST=false
- ENABLE_CURL=true

install:
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [[ "$TRAVIS_PHP_VERSION" != 7.* ]]; then printf "\n" | pecl install propro-1.0.2; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [[ "$TRAVIS_PHP_VERSION" != 7.* ]]; then printf "\n" | pecl install raphf-1.1.2; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [[ "$TRAVIS_PHP_VERSION" != 7.* ]]; then printf "\n" | pecl install pecl_http-2.5.6; fi
- if [[ "$TRAVIS_PHP_VERSION" = 7.* ]]; then printf "\n" | pecl install propro; fi
- if [[ "$TRAVIS_PHP_VERSION" = 7.* ]]; then printf "\n" | pecl install raphf; fi
- if [[ "$TRAVIS_PHP_VERSION" = 7.* ]]; then printf "\n" | pecl install pecl_http; fi
- if [[ "$ENABLE_CURL" = false ]]; then mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d; fi
- if [[ "$ENABLE_CURL" = false ]]; then echo "disable_functions = curl_init" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
- if [[ "$TRAVIS_PHP_VERSION" = "5.6" ]]; then echo "always_populate_raw_post_data = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
- php -S 127.0.0.1 -t tests/Fixtures > /dev/null 2>&1 &
- if [[ "$GUZZLE_VERSION" != "6.*" ]]; then composer require guzzlehttp/guzzle:${GUZZLE_VERSION} --no-update --dev; fi
- composer remove --no-update --dev friendsofphp/php-cs-fixer
- composer update --prefer-source `if [[ $COMPOSER_PREFER_LOWEST = true ]]; then echo "--prefer-lowest --prefer-stable"; fi`

script: vendor/bin/phpunit --configuration phpunit.travis.xml --coverage-clover build/clover.xml

after_success:
- sed -i "/^disable_functions =.*$/d" ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/clover.xml
install: travis/install.sh
script: travis/script.sh
after_success: travis/success.sh

matrix:
include:
- php: 5.6
services: [docker]
env: DOCKER_BUILD=true
- php: 5.6
env: GUZZLE_VERSION=4.*
- php: 5.6
Expand Down
11 changes: 4 additions & 7 deletions docker-compose.yml
Expand Up @@ -3,11 +3,9 @@ version: '2'
services:
php:
build: docker/php
env_file:
- .env
environment:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
SYMFONY_DEPRECATIONS_HELPER: ${SYMFONY_DEPRECATIONS_HELPER}
XDEBUG: ${XDEBUG}
XDEBUG_CONFIG: remote_host=${XDEBUG_HOST} remote_port=${XDEBUG_PORT} idekey=${XDEBUG_IDEKEY}
PHP_IDE_CONFIG: serverName=${IDE_SERVER_NAME}
volumes:
Expand All @@ -16,9 +14,8 @@ services:
- tmp:/tmp
server:
build: docker/server
environment:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
env_file:
- .env
volumes:
- .:/var/www/html
- tmp:/tmp
Expand Down
18 changes: 11 additions & 7 deletions docker/php/Dockerfile
Expand Up @@ -11,20 +11,24 @@ RUN apt-get update && apt-get install -y \
# PHP extensions
RUN docker-php-ext-install intl zip

# Propro & Raphf extensions must be loaded before compiling pecl-http
COPY config/propro.ini /usr/local/etc/php/conf.d/propro.ini
COPY config/raphf.ini /usr/local/etc/php/conf.d/raphf.ini
# Propro & Raphf extensions must be installed/loaded before compiling pecl-http
RUN pecl install propro raphf \
&& docker-php-ext-enable propro raphf

# Pecl extensions
RUN pecl install propro raphf pecl_http xdebug && rm -rf /tmp/pear
COPY config/* /usr/local/etc/php/conf.d/
RUN pecl install pecl_http xdebug \
&& docker-php-ext-enable pecl_http xdebug
&& rm -rf /tmp/pear

# Bash
RUN chsh -s /bin/bash www-data
# XDebug configuration
COPY config/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin

# Bash
RUN chsh -s /bin/bash www-data

# Workdir
WORKDIR /var/www/html

Expand Down
1 change: 0 additions & 1 deletion docker/php/config/pecl-http.ini

This file was deleted.

1 change: 0 additions & 1 deletion docker/php/config/propro.ini

This file was deleted.

1 change: 0 additions & 1 deletion docker/php/config/raphf.ini

This file was deleted.

1 change: 0 additions & 1 deletion docker/php/config/xdebug.ini
@@ -1,3 +1,2 @@
zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
xdebug.cli_color=1
xdebug.remote_enable=1
6 changes: 3 additions & 3 deletions docker/php/entrypoint.sh
Expand Up @@ -7,16 +7,16 @@ USER_ID=${USER_ID-1000}
XDEBUG=${XDEBUG-0}

# Disable XDebug
if [ ! ${XDEBUG} = 1 ]; then
rm -f /usr/local/etc/php/conf.d/xdebug.ini
if [ ! "$XDEBUG" = 1 ]; then
rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
fi

# Permissions
groupmod -g ${GROUP_ID} www-data
usermod -u ${USER_ID} www-data

# Start bash or forward command
if [ $1 = "bash" ]; then
if [ "$1" = "bash" ]; then
su www-data
else
su www-data -c "$*"
Expand Down
50 changes: 50 additions & 0 deletions travis/install.sh
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -e

TRAVIS_PHP_VERSION=${TRAVIS_PHP_VERSION-5.6}
SYMFONY_VERSION=${SYMFONY_VERSION-2.3.*}
ENABLE_CURL=${ENABLE_CURL-false}
GUZZLE_VERSION=${GUZZLE_VERSION-6.*}
COMPOSER_PREFER_LOWEST=${COMPOSER_PREFER_LOWEST-false}
DOCKER_BUILD=${DOCKER_BUILD-false}

if [ "$DOCKER_BUILD" = true ]; then
cp .env.dist .env

docker-compose build
docker-compose run --rm php composer update --prefer-source

exit
fi

if [ "$TRAVIS_PHP_VERSION" = 5.* ]]; then
printf "\n" | pecl install propro-1.0.2
printf "\n" | pecl install raphf-1.1.2
printf "\n" | pecl install pecl_http-2.5.6
fi

if [[ "$TRAVIS_PHP_VERSION" = 7.* ]]; then
printf "\n" | pecl install propro
printf "\n" | pecl install raphf
printf "\n" | pecl install pecl_http
fi

if [ "$ENABLE_CURL" = false ]; then
mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d
echo "disable_functions = curl_init" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
fi

if [ "$TRAVIS_PHP_VERSION" = "5.6" ]; then
echo "always_populate_raw_post_data = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
fi

php -S 127.0.0.1 -t tests/Fixtures > /dev/null 2>&1 &

if [ ! "$GUZZLE_VERSION" = "6.*" ]; then
composer require --no-update --dev guzzlehttp/guzzle:${GUZZLE_VERSION}
fi

composer remove --no-update --dev friendsofphp/php-cs-fixer

composer update --prefer-source `if [ "$COMPOSER_PREFER_LOWEST" = true ]; then echo "--prefer-lowest --prefer-stable"; fi`
13 changes: 13 additions & 0 deletions travis/script.sh
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

DOCKER_BUILD=${DOCKER_BUILD-false}

if [ "$DOCKER_BUILD" = false ]; then
vendor/bin/phpunit --configuration phpunit.travis.xml --coverage-clover build/clover.xml
fi

if [ "$DOCKER_BUILD" = true ]; then
docker-compose run --rm php vendor/bin/phpunit
fi
11 changes: 11 additions & 0 deletions travis/success.sh
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

DOCKER_BUILD=${DOCKER_BUILD-false}

if [ "$DOCKER_BUILD" = false ]; then
sed -i "/^disable_functions =.*$/d" ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/clover.xml
fi

0 comments on commit 3a40195

Please sign in to comment.