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 448e008 commit a8faafd
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 68 deletions.
7 changes: 7 additions & 0 deletions .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
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,4 +1,5 @@
/docker export-ignore
/travis export-ignore
/Tests export-ignore
.env.dist export-ignore
.gitattributes export-ignore
Expand Down
22 changes: 7 additions & 15 deletions .travis.yml
Expand Up @@ -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
Expand Down
82 changes: 41 additions & 41 deletions Model/Base64FileTrait.php
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions docker-compose.yml
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions docker/Dockerfile
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion 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
6 changes: 3 additions & 3 deletions docker/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
31 changes: 31 additions & 0 deletions 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`
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 --coverage-clover build/clover.xml
fi

if [ "$DOCKER_BUILD" = true ]; then
docker-compose run --rm php vendor/bin/phpunit
fi
10 changes: 10 additions & 0 deletions 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

0 comments on commit a8faafd

Please sign in to comment.