From a8faafda991ea83f26f0f0f1d5b1635d9e286854 Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Sat, 11 Feb 2017 10:47:24 +0100 Subject: [PATCH] [Travis] Add docker build --- .env.dist | 7 ++++ .gitattributes | 1 + .travis.yml | 22 ++++------- Model/Base64FileTrait.php | 82 +++++++++++++++++++-------------------- docker-compose.yml | 6 +-- docker/Dockerfile | 12 ++++-- docker/config/xdebug.ini | 1 - docker/entrypoint.sh | 6 +-- travis/install.sh | 31 +++++++++++++++ travis/script.sh | 13 +++++++ travis/success.sh | 10 +++++ 11 files changed, 123 insertions(+), 68 deletions(-) create mode 100755 travis/install.sh create mode 100755 travis/script.sh create mode 100755 travis/success.sh diff --git a/.env.dist b/.env.dist index ed70570..484e2bb 100644 --- a/.env.dist +++ b/.env.dist @@ -1,7 +1,14 @@ +# IDE IDE_SERVER_NAME=ivory-base64-file-bundle + +# 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 diff --git a/.gitattributes b/.gitattributes index 5edbe7c..414f039 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ /docker export-ignore +/travis export-ignore /Tests export-ignore .env.dist export-ignore .gitattributes export-ignore diff --git a/.travis.yml b/.travis.yml index 8e08215..0bb3a2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,27 +14,19 @@ branches: env: global: - COMPOSER_PREFER_LOWEST=false + - DOCKER_BUILD=false - SYMFONY_DEPRECATIONS_HELPER=weak - SYMFONY_VERSION=2.3.* -install: - - composer self-update - - composer require --no-update symfony/form:${SYMFONY_VERSION} - - composer require --no-update symfony/framework-bundle:${SYMFONY_VERSION} - - composer require --no-update --dev symfony/validator:${SYMFONY_VERSION} - - composer require --no-update --dev symfony/yaml:${SYMFONY_VERSION} - - composer remove --no-update --dev friendsofphp/php-cs-fixer - - if [[ "$SYMFONY_VERSION" = *dev* ]]; then sed -i "s/\"MIT\"/\"MIT\",\"minimum-stability\":\"dev\"/g" composer.json; fi - - composer update --prefer-source `if [[ $COMPOSER_PREFER_LOWEST = true ]]; then echo "--prefer-lowest --prefer-stable"; fi` - -script: vendor/bin/phpunit --coverage-clover build/clover.xml - -after_success: - - 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: SYMFONY_VERSION=2.3.* COMPOSER_PREFER_LOWEST=true - php: 5.6 diff --git a/Model/Base64FileTrait.php b/Model/Base64FileTrait.php index e772cc0..f5d1948 100644 --- a/Model/Base64FileTrait.php +++ b/Model/Base64FileTrait.php @@ -26,47 +26,6 @@ trait Base64FileTrait */ private $resource; - /** - * @param string|resource $value - * @param bool $encoded - * - * @return string - */ - private function load($value, $encoded = true) - { - $this->path = tempnam(sys_get_temp_dir(), 'ivory_base64'); - $this->resource = fopen($this->path, 'w+'); - - if ($encoded) { - $filter = stream_filter_append($this->resource, 'convert.base64-decode', STREAM_FILTER_WRITE); - } - - try { - if (is_string($value)) { - $this->copyStringToStream($value, $this->resource); - } elseif (is_resource($value)) { - $this->copyStreamToStream($value, $this->resource); - } else { - throw new \InvalidArgumentException(sprintf( - 'The base64 file value must be a string or a resource, got "%s".', - gettype($value) - )); - } - } catch (\Exception $e) { - fclose($this->resource); - - throw $e; - } - - if (isset($filter)) { - stream_filter_remove($filter); - } - - fflush($this->resource); - - return $this->path; - } - /** * {@inheritdoc} */ @@ -111,6 +70,47 @@ public function getData($encoded = true, $asResource = true) return $content; } + /** + * @param string|resource $value + * @param bool $encoded + * + * @return string + */ + private function load($value, $encoded = true) + { + $this->path = tempnam(sys_get_temp_dir(), 'ivory_base64'); + $this->resource = fopen($this->path, 'w+'); + + if ($encoded) { + $filter = stream_filter_append($this->resource, 'convert.base64-decode', STREAM_FILTER_WRITE); + } + + try { + if (is_string($value)) { + $this->copyStringToStream($value, $this->resource); + } elseif (is_resource($value)) { + $this->copyStreamToStream($value, $this->resource); + } else { + throw new \InvalidArgumentException(sprintf( + 'The base64 file value must be a string or a resource, got "%s".', + gettype($value) + )); + } + } catch (\Exception $e) { + fclose($this->resource); + + throw $e; + } + + if (isset($filter)) { + stream_filter_remove($filter); + } + + fflush($this->resource); + + return $this->path; + } + /** * @param string $from * @param resource $to diff --git a/docker-compose.yml b/docker-compose.yml index 30bdd14..7531bce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,9 @@ version: '2' services: php: build: docker + 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: diff --git a/docker/Dockerfile b/docker/Dockerfile index 6a07e64..39cc8c6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,15 +10,19 @@ RUN apt-get update && apt-get install -y \ RUN docker-php-ext-install zip # XDebug extensions -RUN pecl install xdebug && rm -rf /tmp/pear -COPY config/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini +RUN pecl install xdebug \ + && docker-php-ext-enable 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 diff --git a/docker/config/xdebug.ini b/docker/config/xdebug.ini index 507430a..1f23853 100644 --- a/docker/config/xdebug.ini +++ b/docker/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 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 47185e0..bdce58a 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -7,8 +7,8 @@ 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 @@ -16,7 +16,7 @@ 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 "$*" diff --git a/travis/install.sh b/travis/install.sh new file mode 100755 index 0000000..0f18385 --- /dev/null +++ b/travis/install.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -e + +SYMFONY_VERSION=${SYMFONY_VERSION-2.3.*} +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 + +composer self-update + +composer require --no-update symfony/form:${SYMFONY_VERSION} +composer require --no-update symfony/framework-bundle:${SYMFONY_VERSION} +composer require --no-update --dev symfony/validator:${SYMFONY_VERSION} +composer require --no-update --dev symfony/yaml:${SYMFONY_VERSION} + +composer remove --no-update --dev friendsofphp/php-cs-fixer + +if [[ "$SYMFONY_VERSION" = *dev* ]]; then + composer config minimum-stability dev +fi + +composer update --prefer-source `if [ "$COMPOSER_PREFER_LOWEST" = true ]; then echo "--prefer-lowest --prefer-stable"; fi` diff --git a/travis/script.sh b/travis/script.sh new file mode 100755 index 0000000..0e8067b --- /dev/null +++ b/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 --coverage-clover build/clover.xml +fi + +if [ "$DOCKER_BUILD" = true ]; then + docker-compose run --rm php vendor/bin/phpunit +fi diff --git a/travis/success.sh b/travis/success.sh new file mode 100755 index 0000000..eca3c0f --- /dev/null +++ b/travis/success.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +DOCKER_BUILD=${DOCKER_BUILD-false} + +if [ "$DOCKER_BUILD" = false ]; then + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover build/clover.xml +fi