From 2afe41b32b9c4faa7f168767baae4947e1cba007 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 20 Apr 2018 14:50:57 -0600 Subject: [PATCH 01/34] Added docker-compose for development --- .gitignore | 1 + docker-compose.yml | 17 +++++++++++++++++ docker/Dockerfile | 11 +++++++++++ docker/connect | 1 + docker/data/.gitkeep | 0 5 files changed, 30 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile create mode 100755 docker/connect create mode 100644 docker/data/.gitkeep diff --git a/.gitignore b/.gitignore index 7fffcbdb..33d60c72 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ test/data/ test/assets/module/*/config/module.config.php clover.xml coveralls-upload.json +docker/data/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3aecf69d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3" +services: + php: + build: + context: . + dockerfile: docker/Dockerfile + links: + - mongo + ports: + - "9000:9000" + volumes: + - ./:/docker + tty: true + mongo: + image: mongo:latest + ports: + - "27017:27017" diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..4421e01b --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,11 @@ +FROM php:latest +RUN apt-get update +RUN apt-get --yes install vim +RUN apt-get --yes install git +RUN apt-get --yes install inetutils-ping +RUN pecl install mongodb \ + && docker-php-ext-enable mongodb +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN php -r "unlink('composer-setup.php');" +RUN mv composer.phar /bin/composer diff --git a/docker/connect b/docker/connect new file mode 100755 index 00000000..1fcf5c2b --- /dev/null +++ b/docker/connect @@ -0,0 +1 @@ +docker exec -it $(docker ps -f name=zfapigilitydoctrine_php_1 | awk '{print $1;}' | tail -n 1) bash diff --git a/docker/data/.gitkeep b/docker/data/.gitkeep new file mode 100644 index 00000000..e69de29b From 857298a5836c7a87851a7ec2ea64441a05e1d0dc Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 20 Apr 2018 15:50:27 -0600 Subject: [PATCH 02/34] Instructions for Docker --- DOCKER.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++ docker/Dockerfile | 4 ++-- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 DOCKER.md diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 00000000..f9f544fe --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,57 @@ +# Using Docker for Development + +This library requires a running instance of Mongo in order to run and pass +the unit tests. It is not expected for each developer to configure their +individual machine to match this environment so Docker is provided. + + +## Running docker-compose + +You will need docker-compose installed on your machine. + +From the root directory of this project run + +``` +docker-compose build +``` + +This will build the php container. Next run + +``` +docker-compose up +``` + +This will spin up the php container and a mongo container. + +To connect to the php container and run the unit tests +run + +``` +docker/connect +``` + +You will connect to the php container a the root directory. +`cd` to `docker` to work with the mapped local files. + + +## Configuration + +Because you're in a Docker environment with a differnet IP address and name for each +container you need to either change the config files in the project to point to `mongo` +or with a simple hack map localhost to the `mongo` container. + +* To edit the config file to point to the `mongo` container instaed of `localhost` edit +`test/config/ODM/local.php` and change the configuration. + +* Optionally you can map localhost to mongo with +``` +echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts +``` + +## Unit Tests + +You may now run the unit tests + +``` +vendor/bin/phpunit +``` diff --git a/docker/Dockerfile b/docker/Dockerfile index 4421e01b..2fb4f22e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,8 +3,8 @@ RUN apt-get update RUN apt-get --yes install vim RUN apt-get --yes install git RUN apt-get --yes install inetutils-ping -RUN pecl install mongodb \ - && docker-php-ext-enable mongodb +RUN apt-get --yes install host +RUN pecl install mongodb && docker-php-ext-enable mongodb RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php composer-setup.php RUN php -r "unlink('composer-setup.php');" From e6c646570abee6dac06fefcb6081b9a25e1a7e59 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 20 Apr 2018 16:31:06 -0600 Subject: [PATCH 03/34] proofreading DOCKER.md --- DOCKER.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index f9f544fe..73fe969d 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -38,9 +38,9 @@ You will connect to the php container a the root directory. Because you're in a Docker environment with a differnet IP address and name for each container you need to either change the config files in the project to point to `mongo` -or with a simple hack map localhost to the `mongo` container. +or with a simple hack map `localhost` to the `mongo` container. -* To edit the config file to point to the `mongo` container instaed of `localhost` edit +* To edit the config file to point to the `mongo` container instead of `localhost` edit `test/config/ODM/local.php` and change the configuration. * Optionally you can map localhost to mongo with @@ -50,7 +50,7 @@ echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts ## Unit Tests -You may now run the unit tests +Having run `composer install` you may now run the unit tests ``` vendor/bin/phpunit From 97ca995895227316fe2372a54db5c513d1944688 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 21 Apr 2018 22:47:26 -0600 Subject: [PATCH 04/34] Added docker-compose and unit tests to travis --- .travis.docker | 3 +++ .travis.yml | 6 ++++++ docker-compose.yml | 2 -- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .travis.docker diff --git a/.travis.docker b/.travis.docker new file mode 100644 index 00000000..2170e81f --- /dev/null +++ b/.travis.docker @@ -0,0 +1,3 @@ +cd /docker +echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts +vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml index 4bc4ae69..6de2676b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ language: php services: - mongodb + - docker cache: directories: @@ -59,17 +60,21 @@ matrix: env: - DEPS=lowest - MONGO_DRIVER=mongodb + - DOCKER=true - php: 7.2 env: - DEPS=locked - MONGO_DRIVER=mongodb + - DOCKER=true - php: 7.2 env: - DEPS=latest - MONGO_DRIVER=mongodb + - DOCKER=true before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + - if [[ $DOCKER == 'true' ]]; then docker-compose up -d; fi install: - yes '' | pecl -q install -f $MONGO_DRIVER @@ -85,6 +90,7 @@ install: script: - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi + - if [[ $DOCKER == 'true' ]]; then docker exec -it $(docker ps -f name=zfapigilitydoctrine_php_1 | awk '{print $1;}' | tail -n 1) bash /docker/.travis.docker; fi after_script: - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi diff --git a/docker-compose.yml b/docker-compose.yml index 3aecf69d..e0db246f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,5 +13,3 @@ services: tty: true mongo: image: mongo:latest - ports: - - "27017:27017" From a6b1272f1d0f5cfe02d33dec204f6c72898e5fc3 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 1 Apr 2018 22:52:27 -0600 Subject: [PATCH 05/34] The results in this test have changed order but are still valid. Rewrote to account for unknown order --- .../Model/DoctrineAutodiscoveryModelTest.php | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/test/src/Admin/Model/DoctrineAutodiscoveryModelTest.php b/test/src/Admin/Model/DoctrineAutodiscoveryModelTest.php index 6ea39cfe..6dd24207 100644 --- a/test/src/Admin/Model/DoctrineAutodiscoveryModelTest.php +++ b/test/src/Admin/Model/DoctrineAutodiscoveryModelTest.php @@ -29,17 +29,34 @@ public function testORMAutodiscoveryEntitiesWithFields() $this->assertInternalType('array', $result); $this->assertCount(3, $result); - $this->assertEquals(Album::class, $result[0]['entity_class']); - $this->assertEquals('Album', $result[0]['service_name']); - $this->assertCount(2, $result[0]['fields']); + $resultProcessed = []; + foreach ($result as $row) { + switch ($row['entity_class']) { + case Album::class: + $this->assertEquals('Album', $row['service_name']); + $this->assertCount(2, $row['fields']); + break; + case Artist::class: + $this->assertEquals('Artist', $row['service_name']); + $this->assertCount(2, $row['fields']); + break; + case Product::class: + $this->assertEquals('Product', $row['service_name']); + $this->assertCount(1, $row['fields']); + break; + default: + throw new \Exception("Unexpected result: " . $row['entity_class']); + } - $this->assertEquals(Artist::class, $result[1]['entity_class']); - $this->assertEquals('Artist', $result[1]['service_name']); - $this->assertCount(2, $result[1]['fields']); + if (isset($resultProcessed[$row['entity_class']])) { + $resultProcessed[$row['entity_class']] ++; + } else { + $resultProcessed[$row['entity_class']] = 1; + } + } - $this->assertEquals(Product::class, $result[2]['entity_class']); - $this->assertEquals('Product', $result[2]['service_name']); - $this->assertCount(1, $result[2]['fields']); + $this->assertEquals(3, sizeof($resultProcessed)); + $this->assertEquals(3, array_sum($resultProcessed)); } public function testODMAutodiscoveryEntitiesWithFields() From 32cec0494052556a82073979edc7e1935427dd91 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 22 Apr 2018 13:11:09 -0600 Subject: [PATCH 06/34] Incorporated suggestions from @thomasvargiu for Docker --- .travis.docker | 3 --- .travis.yml | 3 ++- DOCKER.md | 17 +---------------- docker-compose.yml | 11 +++++++---- docker/Dockerfile | 33 +++++++++++++++++++++++---------- test/config/ODM/local.php | 4 ++-- 6 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 .travis.docker diff --git a/.travis.docker b/.travis.docker deleted file mode 100644 index 2170e81f..00000000 --- a/.travis.docker +++ /dev/null @@ -1,3 +0,0 @@ -cd /docker -echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts -vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml index 6de2676b..0ab847d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,6 +56,8 @@ matrix: env: - DEPS=latest - MONGO_DRIVER=mongodb + - PHP_VERSION=7.1 + - DOCKER=true - php: 7.2 env: - DEPS=lowest @@ -74,7 +76,6 @@ matrix: before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - - if [[ $DOCKER == 'true' ]]; then docker-compose up -d; fi install: - yes '' | pecl -q install -f $MONGO_DRIVER diff --git a/DOCKER.md b/DOCKER.md index 73fe969d..72e1379c 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -27,27 +27,12 @@ To connect to the php container and run the unit tests run ``` -docker/connect +docker-compose run php bash ``` You will connect to the php container a the root directory. `cd` to `docker` to work with the mapped local files. - -## Configuration - -Because you're in a Docker environment with a differnet IP address and name for each -container you need to either change the config files in the project to point to `mongo` -or with a simple hack map `localhost` to the `mongo` container. - -* To edit the config file to point to the `mongo` container instead of `localhost` edit -`test/config/ODM/local.php` and change the configuration. - -* Optionally you can map localhost to mongo with -``` -echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts -``` - ## Unit Tests Having run `composer install` you may now run the unit tests diff --git a/docker-compose.yml b/docker-compose.yml index e0db246f..cf757006 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,16 @@ services: php: build: context: . + args: + - PHP_VERSION=${PHP_VERSION:-7.2} dockerfile: docker/Dockerfile - links: + depends_on: - mongo - ports: - - "9000:9000" volumes: - ./:/docker - tty: true + environment: + - MONGO_HOST=mongo + - MONGO_PORT=27017 + mongo: image: mongo:latest diff --git a/docker/Dockerfile b/docker/Dockerfile index 2fb4f22e..13c8d0a3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,11 +1,24 @@ -FROM php:latest -RUN apt-get update -RUN apt-get --yes install vim -RUN apt-get --yes install git -RUN apt-get --yes install inetutils-ping -RUN apt-get --yes install host +ARG PHP_VERSION=7.2 +FROM php:${PHP_VERSION}-alpine + +RUN apk add --no-cache \ + autoconf \ + make \ + g++ \ + bash + RUN pecl install mongodb && docker-php-ext-enable mongodb -RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -RUN php composer-setup.php -RUN php -r "unlink('composer-setup.php');" -RUN mv composer.phar /bin/composer +RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN echo -e '#!/bin/sh' > /usr/local/bin/entrypoint.sh \ + && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ + && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ + && chmod +x /usr/local/bin/entrypoint.sh +WORKDIR /docker +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["./vendor/bin/phpunit"] + +# RUN apt-get update +# RUN apt-get --yes install vim +# RUN apt-get --yes install git +# RUN apt-get --yes install inetutils-ping +# RUN apt-get --yes install host diff --git a/test/config/ODM/local.php b/test/config/ODM/local.php index 33f3db12..e8ecad78 100644 --- a/test/config/ODM/local.php +++ b/test/config/ODM/local.php @@ -8,8 +8,8 @@ 'doctrine' => [ 'connection' => [ 'odm_default' => [ - 'server' => 'localhost', - 'port' => '27017', + 'server' => (getenv('MONGO_HOST')) ? getenv('MONGO_HOST') : 'localhost', + 'port' => (getenv('MONGO_PORT')) ? getenv('MONGO_PORT') : '27017', 'user' => '', 'password' => '', 'dbname' => 'zf_apigility_doctrine_server_test', From c7b4d02ea3ad9d675171e86362741c984bef99ff Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 22 Apr 2018 13:18:45 -0600 Subject: [PATCH 07/34] Added docker tests to travis --- .travis.yml | 7 +------ DOCKER.md | 21 +++++++++++---------- docker/Dockerfile => Dockerfile | 15 ++++++--------- docker-compose.yml | 4 ++-- docker/connect | 1 - docker/data/.gitkeep | 0 6 files changed, 20 insertions(+), 28 deletions(-) rename docker/Dockerfile => Dockerfile (62%) delete mode 100755 docker/connect delete mode 100644 docker/data/.gitkeep diff --git a/.travis.yml b/.travis.yml index 0ab847d0..f7b619b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,23 +56,18 @@ matrix: env: - DEPS=latest - MONGO_DRIVER=mongodb - - PHP_VERSION=7.1 - - DOCKER=true - php: 7.2 env: - DEPS=lowest - MONGO_DRIVER=mongodb - - DOCKER=true - php: 7.2 env: - DEPS=locked - MONGO_DRIVER=mongodb - - DOCKER=true - php: 7.2 env: - DEPS=latest - MONGO_DRIVER=mongodb - - DOCKER=true before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi @@ -91,7 +86,7 @@ install: script: - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi - - if [[ $DOCKER == 'true' ]]; then docker exec -it $(docker ps -f name=zfapigilitydoctrine_php_1 | awk '{print $1;}' | tail -n 1) bash /docker/.travis.docker; fi + - docker-compose run --rm php after_script: - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi diff --git a/DOCKER.md b/DOCKER.md index 72e1379c..72955c39 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -15,19 +15,12 @@ From the root directory of this project run docker-compose build ``` -This will build the php container. Next run +This will build the php container. -``` -docker-compose up -``` - -This will spin up the php container and a mongo container. - -To connect to the php container and run the unit tests -run +To connect to the php container and run the unit tests run ``` -docker-compose run php bash +docker-compose run --rm php bash ``` You will connect to the php container a the root directory. @@ -36,7 +29,15 @@ You will connect to the php container a the root directory. ## Unit Tests Having run `composer install` you may now run the unit tests +inside the container with ``` vendor/bin/phpunit ``` + +You may run the unit tests through the container without connecting +with bash via + +``` +docker-composer run --rm php +``` diff --git a/docker/Dockerfile b/Dockerfile similarity index 62% rename from docker/Dockerfile rename to Dockerfile index 13c8d0a3..126ac964 100644 --- a/docker/Dockerfile +++ b/Dockerfile @@ -5,20 +5,17 @@ RUN apk add --no-cache \ autoconf \ make \ g++ \ - bash + bash \ + git \ + openssl-dev -RUN pecl install mongodb && docker-php-ext-enable mongodb +RUN echo "memory_limit=2G" >> /usr/local/etc/php/php.ini +RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl install mongo && echo "extension=mongo.so" >> /usr/local/etc/php/php.ini ; else pecl install mongodb && docker-php-ext-enable mongodb ; fi RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN echo -e '#!/bin/sh' > /usr/local/bin/entrypoint.sh \ +RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ && chmod +x /usr/local/bin/entrypoint.sh WORKDIR /docker ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["./vendor/bin/phpunit"] - -# RUN apt-get update -# RUN apt-get --yes install vim -# RUN apt-get --yes install git -# RUN apt-get --yes install inetutils-ping -# RUN apt-get --yes install host diff --git a/docker-compose.yml b/docker-compose.yml index cf757006..8fbd1b3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,8 @@ services: build: context: . args: - - PHP_VERSION=${PHP_VERSION:-7.2} - dockerfile: docker/Dockerfile + - PHP_VERSION=${TRAVIS_PHP_VERSION:-7.2} + dockerfile: Dockerfile depends_on: - mongo volumes: diff --git a/docker/connect b/docker/connect deleted file mode 100755 index 1fcf5c2b..00000000 --- a/docker/connect +++ /dev/null @@ -1 +0,0 @@ -docker exec -it $(docker ps -f name=zfapigilitydoctrine_php_1 | awk '{print $1;}' | tail -n 1) bash diff --git a/docker/data/.gitkeep b/docker/data/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 689456241a2cae308a813f351e644a6a9f6751d6 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 22 Apr 2018 22:02:50 -0600 Subject: [PATCH 08/34] Organized .travis.yml --- .travis.yml | 14 ++++---------- DOCKER.md | 14 ++------------ 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7b619b9..8f5fe4c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,59 +15,53 @@ env: - COMPOSER_ARGS="--no-interaction" - ADAPTER_DEPS="alcaeus/mongo-php-adapter" - COVERAGE_DEPS="php-coveralls/php-coveralls" - - MONGO_DRIVER=mongo + - MONGO_DRIVER=mongodb matrix: include: - php: 5.6 env: - DEPS=lowest + - MONGO_DRIVER=mongo - php: 5.6 env: - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" + - MONGO_DRIVER=mongo - php: 5.6 env: - DEPS=latest + - MONGO_DRIVER=mongo - php: 7 env: - DEPS=lowest - - MONGO_DRIVER=mongodb - php: 7 env: - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - - MONGO_DRIVER=mongodb - php: 7 env: - DEPS=latest - - MONGO_DRIVER=mongodb - php: 7.1 env: - DEPS=lowest - - MONGO_DRIVER=mongodb - php: 7.1 env: - DEPS=locked - CS_CHECK=true - TEST_COVERAGE=true - - MONGO_DRIVER=mongodb - php: 7.1 env: - DEPS=latest - - MONGO_DRIVER=mongodb - php: 7.2 env: - DEPS=lowest - - MONGO_DRIVER=mongodb - php: 7.2 env: - DEPS=locked - - MONGO_DRIVER=mongodb - php: 7.2 env: - DEPS=latest - - MONGO_DRIVER=mongodb before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi diff --git a/DOCKER.md b/DOCKER.md index 72955c39..d751f9ba 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -1,4 +1,4 @@ -# Using Docker for Development +# Docker for Development This library requires a running instance of Mongo in order to run and pass the unit tests. It is not expected for each developer to configure their @@ -16,24 +16,14 @@ docker-compose build ``` This will build the php container. - To connect to the php container and run the unit tests run ``` docker-compose run --rm php bash ``` -You will connect to the php container a the root directory. -`cd` to `docker` to work with the mapped local files. - -## Unit Tests - -Having run `composer install` you may now run the unit tests -inside the container with -``` -vendor/bin/phpunit -``` +## Unit Tests Only You may run the unit tests through the container without connecting with bash via From 05aa0002f15e8bf8204889f7e54a6a8bb04cf7ee Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Apr 2018 09:53:32 -0600 Subject: [PATCH 09/34] Made changes based on feedback on github --- .gitattributes | 2 ++ .gitignore | 1 - test/config/ODM/local.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index 2ca26bea..25b1bd1d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,3 +5,5 @@ .travis.yml export-ignore phpcs.xml export-ignore phpunit.xml.dist export-ignore +docker-compose.yml export-ignore +Dockerfile export-ignore diff --git a/.gitignore b/.gitignore index 33d60c72..7fffcbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ test/data/ test/assets/module/*/config/module.config.php clover.xml coveralls-upload.json -docker/data/ diff --git a/test/config/ODM/local.php b/test/config/ODM/local.php index e8ecad78..1c167d45 100644 --- a/test/config/ODM/local.php +++ b/test/config/ODM/local.php @@ -8,8 +8,8 @@ 'doctrine' => [ 'connection' => [ 'odm_default' => [ - 'server' => (getenv('MONGO_HOST')) ? getenv('MONGO_HOST') : 'localhost', - 'port' => (getenv('MONGO_PORT')) ? getenv('MONGO_PORT') : '27017', + 'server' => getenv('MONGO_HOST') ?: 'localhost', + 'port' => getenv('MONGO_PORT') ?: '27017', 'user' => '', 'password' => '', 'dbname' => 'zf_apigility_doctrine_server_test', From a2c7bdb10f08a4b98bd3c3877e72643c4cb60f82 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Apr 2018 18:46:14 -0600 Subject: [PATCH 10/34] First test run of non-php specific travis test --- .travis.yml | 56 +++++---------------------------- docker-compose.yml | 2 +- Dockerfile => docker/Dockerfile | 0 3 files changed, 9 insertions(+), 49 deletions(-) rename Dockerfile => docker/Dockerfile (100%) diff --git a/.travis.yml b/.travis.yml index 8f5fe4c6..0d6465cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,7 @@ sudo: false -language: php - services: - mongodb - - docker - -cache: - directories: - - $HOME/.composer/cache env: global: @@ -19,49 +12,19 @@ env: matrix: include: - - php: 5.6 - env: + - env: + - TRAVIS_PHP_VERSION=5.6 - DEPS=lowest - MONGO_DRIVER=mongo - - php: 5.6 - env: + - env: + - TRAVIS_PHP_VERSION=5.6 - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - MONGO_DRIVER=mongo - - php: 5.6 - env: + - env: + - TRAVIS_PHP_VERSION=5.6 - DEPS=latest - MONGO_DRIVER=mongo - - php: 7 - env: - - DEPS=lowest - - php: 7 - env: - - DEPS=locked - - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - - php: 7 - env: - - DEPS=latest - - php: 7.1 - env: - - DEPS=lowest - - php: 7.1 - env: - - DEPS=locked - - CS_CHECK=true - - TEST_COVERAGE=true - - php: 7.1 - env: - - DEPS=latest - - php: 7.2 - env: - - DEPS=lowest - - php: 7.2 - env: - - DEPS=locked - - php: 7.2 - env: - - DEPS=latest before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi @@ -78,12 +41,9 @@ install: - stty cols 120 && composer show script: - - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi + - if [[ $TEST_COVERAGE == 'asdf' ]]; then composer test-coverage ; else composer test ; fi - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi - docker-compose run --rm php after_script: - - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi - -notifications: - email: false + - if [[ $TEST_COVERAGE == 'asdf' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi diff --git a/docker-compose.yml b/docker-compose.yml index 8fbd1b3a..744eccbf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: context: . args: - PHP_VERSION=${TRAVIS_PHP_VERSION:-7.2} - dockerfile: Dockerfile + dockerfile: docker/Dockerfile depends_on: - mongo volumes: diff --git a/Dockerfile b/docker/Dockerfile similarity index 100% rename from Dockerfile rename to docker/Dockerfile From 50dfd852186541a2a1ea48980f6ca51e75db30c3 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Apr 2018 18:52:41 -0600 Subject: [PATCH 11/34] none = language? --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d6465cd..58f9a134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ sudo: false -services: - - mongodb +language: none env: global: From 08fd71a0f97d6ff896ba923ebc362ba46e4b9fb1 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Apr 2018 19:07:11 -0600 Subject: [PATCH 12/34] Added all tests back in --- .travis.yml | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58f9a134..2cccf74f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ sudo: false - language: none env: @@ -24,6 +23,36 @@ matrix: - TRAVIS_PHP_VERSION=5.6 - DEPS=latest - MONGO_DRIVER=mongo + - env: + - TRAVIS_PHP_VERSION=7 + - DEPS=lowest + - env: + - TRAVIS_PHP_VERSION=7 + - DEPS=locked + - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" + - env: + - TRAVIS_PHP_VERSION=7 + - DEPS=latest + - env: + - TRAVIS_PHP_VERSION=7.1 + - DEPS=lowest + - env: + - TRAVIS_PHP_VERSION=7.1 + - DEPS=locked + - CS_CHECK=true + - TEST_COVERAGE=true + - env: + - TRAVIS_PHP_VERSION=7.1 + - DEPS=latest + - env: + - TRAVIS_PHP_VERSION=7.2 + - DEPS=lowest + - env: + - TRAVIS_PHP_VERSION=7.2 + - DEPS=locked + - env: + - TRAVIS_PHP_VERSION=7.2 + - DEPS=latest before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi @@ -40,9 +69,8 @@ install: - stty cols 120 && composer show script: - - if [[ $TEST_COVERAGE == 'asdf' ]]; then composer test-coverage ; else composer test ; fi - - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi - - docker-compose run --rm php + - if [[ $TEST_COVERAGE == 'true' ]]; then docker-compose run php composer test-coverage ; else docker-compose run php composer test ; fi + - if [[ $CS_CHECK == 'true' ]]; then docker-compose run php composer cs-check ; fi after_script: - - if [[ $TEST_COVERAGE == 'asdf' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then docker-compose run php vendor/bin/php-coveralls -v ; fi From 26f53c05bf5491da6c8aae8caaa64c47557f461d Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Apr 2018 19:31:05 -0600 Subject: [PATCH 13/34] Added build to install script --- .travis.yml | 25 +++++++++++++------------ docker-compose.yml | 2 +- docker/Dockerfile | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2cccf74f..0999a2a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,47 +11,47 @@ env: matrix: include: - env: - - TRAVIS_PHP_VERSION=5.6 + - PHP_VERSION=5.6 - DEPS=lowest - MONGO_DRIVER=mongo - env: - - TRAVIS_PHP_VERSION=5.6 + - PHP_VERSION=5.6 - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - MONGO_DRIVER=mongo - env: - - TRAVIS_PHP_VERSION=5.6 + - PHP_VERSION=5.6 - DEPS=latest - MONGO_DRIVER=mongo - env: - - TRAVIS_PHP_VERSION=7 + - PHP_VERSION=7 - DEPS=lowest - env: - - TRAVIS_PHP_VERSION=7 + - PHP_VERSION=7 - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - env: - - TRAVIS_PHP_VERSION=7 + - PHP_VERSION=7 - DEPS=latest - env: - - TRAVIS_PHP_VERSION=7.1 + - PHP_VERSION=7.1 - DEPS=lowest - env: - - TRAVIS_PHP_VERSION=7.1 + - PHP_VERSION=7.1 - DEPS=locked - CS_CHECK=true - TEST_COVERAGE=true - env: - - TRAVIS_PHP_VERSION=7.1 + - PHP_VERSION=7.1 - DEPS=latest - env: - - TRAVIS_PHP_VERSION=7.2 + - PHP_VERSION=7.2 - DEPS=lowest - env: - - TRAVIS_PHP_VERSION=7.2 + - PHP_VERSION=7.2 - DEPS=locked - env: - - TRAVIS_PHP_VERSION=7.2 + - PHP_VERSION=7.2 - DEPS=latest before_install: @@ -67,6 +67,7 @@ install: - if [[ $MONGO_DRIVER == 'mongodb' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show + - docker build --build-arg PHP_VERSION=$PHP_VERSION docker script: - if [[ $TEST_COVERAGE == 'true' ]]; then docker-compose run php composer test-coverage ; else docker-compose run php composer test ; fi diff --git a/docker-compose.yml b/docker-compose.yml index 744eccbf..cf757006 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: . args: - - PHP_VERSION=${TRAVIS_PHP_VERSION:-7.2} + - PHP_VERSION=${PHP_VERSION:-7.2} dockerfile: docker/Dockerfile depends_on: - mongo diff --git a/docker/Dockerfile b/docker/Dockerfile index 126ac964..0a176387 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,7 +10,7 @@ RUN apk add --no-cache \ openssl-dev RUN echo "memory_limit=2G" >> /usr/local/etc/php/php.ini -RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl install mongo && echo "extension=mongo.so" >> /usr/local/etc/php/php.ini ; else pecl install mongodb && docker-php-ext-enable mongodb ; fi +RUN if [ ${PHP_VERSION} == "5.6" ] ; then pecl install mongo && echo "extension=mongo.so" >> /usr/local/etc/php/php.ini ; else pecl install mongodb && docker-php-ext-enable mongodb ; fi RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ From e62c69a5a76382db244ad229b09c9aa9e83c15ba Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Apr 2018 12:49:19 -0600 Subject: [PATCH 14/34] composer-build works; extenting to .travis.yml --- .travis.yml | 32 ++++++++++++++++---------------- docker-compose.yml | 2 +- docker/Dockerfile | 9 +++++++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0999a2a6..99acc667 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,23 +6,23 @@ env: - COMPOSER_ARGS="--no-interaction" - ADAPTER_DEPS="alcaeus/mongo-php-adapter" - COVERAGE_DEPS="php-coveralls/php-coveralls" - - MONGO_DRIVER=mongodb + - MONGO_DRIVER="mongodb" matrix: include: - env: - PHP_VERSION=5.6 - DEPS=lowest - - MONGO_DRIVER=mongo + - MONGO_DRIVER="mongo" - env: - PHP_VERSION=5.6 - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - - MONGO_DRIVER=mongo + - MONGO_DRIVER="mongo" - env: - PHP_VERSION=5.6 - DEPS=latest - - MONGO_DRIVER=mongo + - MONGO_DRIVER="mongo" - env: - PHP_VERSION=7 - DEPS=lowest @@ -58,20 +58,20 @@ before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi install: - - yes '' | pecl -q install -f $MONGO_DRIVER - - composer config platform.ext-mongo '1.999' - - travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs - - if [[ $LEGACY_DEPS != '' ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi - - if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi - - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi - - if [[ $MONGO_DRIVER == 'mongodb' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi - - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi + - docker-compose build --no-cache php + - travis_retry docker-compose run --rm php composer install $COMPOSER_ARGS --ignore-platform-reqs + + - composer config "platform.ext-mongo" "1.6.16" + - if [[ $LEGACY_DEPS != '' ]]; then travis_retry docker-compose run --rm php composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi + - if [[ $DEPS == 'latest' ]]; then travis_retry docker-compose run --rm php composer update $COMPOSER_ARGS ; fi + - if [[ $DEPS == 'lowest' ]]; then travis_retry docker-compose run --rm php composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi + - if [[ $MONGO_DRIVER == 'mongodb' ]] ; then travis_retry docker-compose run --rm php composer config "platform.ext-mongo" "1.6.16" && travis_retry docker-compose run --rm php composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show - - docker build --build-arg PHP_VERSION=$PHP_VERSION docker script: - - if [[ $TEST_COVERAGE == 'true' ]]; then docker-compose run php composer test-coverage ; else docker-compose run php composer test ; fi - - if [[ $CS_CHECK == 'true' ]]; then docker-compose run php composer cs-check ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php composer test-coverage ; else docker-compose run --rm php composer test ; fi + - if [[ $CS_CHECK == 'true' ]]; then travis_retry docker-compose run --rm php composer cs-check ; fi after_script: - - if [[ $TEST_COVERAGE == 'true' ]]; then docker-compose run php vendor/bin/php-coveralls -v ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php vendor/bin/php-coveralls -v ; fi diff --git a/docker-compose.yml b/docker-compose.yml index cf757006..1494b157 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,9 @@ services: php: build: context: . + dockerfile: docker/Dockerfile args: - PHP_VERSION=${PHP_VERSION:-7.2} - dockerfile: docker/Dockerfile depends_on: - mongo volumes: diff --git a/docker/Dockerfile b/docker/Dockerfile index 0a176387..6ac948e3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,6 @@ ARG PHP_VERSION=7.2 +ARG XDEBUG=0 + FROM php:${PHP_VERSION}-alpine RUN apk add --no-cache \ @@ -9,9 +11,12 @@ RUN apk add --no-cache \ git \ openssl-dev -RUN echo "memory_limit=2G" >> /usr/local/etc/php/php.ini -RUN if [ ${PHP_VERSION} == "5.6" ] ; then pecl install mongo && echo "extension=mongo.so" >> /usr/local/etc/php/php.ini ; else pecl install mongodb && docker-php-ext-enable mongodb ; fi +RUN php --ini | sed -n -e 's/^.*Path: //p' +RUN echo "memory_limit=2G" >> 'test' >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl -q install -f mongo && echo "extension=mongo.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi +RUN if [ ${PHP_VERSION:0:1} == "7" ] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl install mongodb && docker-php-ext-enable mongodb && echo "extension=mongodb.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini; fi +RUN if [[ ${XDEBUG:0:1} == "1" ]] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl -q install -f xdebug && docker-php-ext-enable xdebug && echo "zend_extension=xdebug.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ From 91f75800793a01029ede6ca70381faa6784e600f Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Apr 2018 13:01:32 -0600 Subject: [PATCH 15/34] Added xdebug --- .travis.yml | 1 + docker-compose.yml | 1 + docker/Dockerfile | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 99acc667..39f23757 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,7 @@ matrix: - DEPS=locked - CS_CHECK=true - TEST_COVERAGE=true + - XDEBUG=1 - env: - PHP_VERSION=7.1 - DEPS=latest diff --git a/docker-compose.yml b/docker-compose.yml index 1494b157..8cc3bdf1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: dockerfile: docker/Dockerfile args: - PHP_VERSION=${PHP_VERSION:-7.2} + - XDEBUG=${XDEBUG:-0} depends_on: - mongo volumes: diff --git a/docker/Dockerfile b/docker/Dockerfile index 6ac948e3..f9cb1c68 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,8 +1,8 @@ ARG PHP_VERSION=7.2 -ARG XDEBUG=0 - FROM php:${PHP_VERSION}-alpine +ARG XDEBUG=0 + RUN apk add --no-cache \ autoconf \ make \ @@ -16,7 +16,7 @@ RUN echo "memory_limit=2G" >> 'test' >> `php --ini | sed -n -e 's/^.*Path: //p'` RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl -q install -f mongo && echo "extension=mongo.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi RUN if [ ${PHP_VERSION:0:1} == "7" ] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl install mongodb && docker-php-ext-enable mongodb && echo "extension=mongodb.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini; fi -RUN if [[ ${XDEBUG:0:1} == "1" ]] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl -q install -f xdebug && docker-php-ext-enable xdebug && echo "zend_extension=xdebug.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi +RUN if [ ${XDEBUG} == "1" ] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl -q install -f xdebug && docker-php-ext-enable xdebug && echo "zend_extension=xdebug.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ From 00faa668de7fec8750861ec7ad5214ddcde0788e Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Apr 2018 16:49:20 -0600 Subject: [PATCH 16/34] Contributing Docker docs --- CONTRIBUTING.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62fdd144..8cd0e436 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,10 +39,38 @@ contributors a chance to resolve the vulnerability and issue a new release prior to any public exposure; this helps protect Apigility users, and provides them with a chance to upgrade and/or update in order to protect their applications. -For sensitive email communications, please use +For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc). -## RUNNING TESTS +## DOCKER FOR DEVELOPMENT + +This library requires a running instance of Mongo in order to run and pass +the unit tests. It is not expected for each developer to configure their +individual machine to match this environment so Docker is provided. + +### Running docker-compose + +You will need docker-compose installed on your machine. +Docker supports many PHP versions. You may specify the version of PHP you +want to build against before running `docker-compose`. + +``` +export PHP_VERSION=7.1 +``` + +Next, from the root directory of this project, run + +``` +docker-compose build +``` + +To connect to the php container for development run + +``` +docker-compose run php bash +``` + +### RUNNING UNIT TESTS IN THE CONTAINER First, use [Composer](https://getcomposer.org) to install all dependencies: @@ -56,6 +84,20 @@ To run tests: $ composer test ``` +### RUNNING UNIT TESTS ON DOCKER + +You may run the unit tests through the container without running bash via + +``` +docker-composer run --rm php +``` + +## CONTINUOUS INTEGRATION + +When you have made a change and created a pull request for it Travis-CI is used +to validate the build. For this a Docker container is created on travis for each +build matrix and the unit tests are ran identical to running unit tests on Docker locally. + ## CODING STANDARDS While Apigility uses Zend Framework 2 coding standards, in practice, we check From 6661ae8312b31eb39b5e55afbfa2b2d6a06cbd8f Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Apr 2018 17:06:16 -0600 Subject: [PATCH 17/34] Tidy contributing --- CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8cd0e436..973f0f23 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,14 +48,16 @@ This library requires a running instance of Mongo in order to run and pass the unit tests. It is not expected for each developer to configure their individual machine to match this environment so Docker is provided. -### Running docker-compose +### RUNNING DOCKER-COMPOSE You will need docker-compose installed on your machine. Docker supports many PHP versions. You may specify the version of PHP you -want to build against before running `docker-compose`. +want (default:7.2) to build against before running `docker-compose` and flag XDEBUG to +install (1) or not (default:0). ``` export PHP_VERSION=7.1 +export XDEBUG=1 ``` Next, from the root directory of this project, run @@ -92,7 +94,7 @@ You may run the unit tests through the container without running bash via docker-composer run --rm php ``` -## CONTINUOUS INTEGRATION +### DOCKER AND CONTINUOUS INTEGRATION When you have made a change and created a pull request for it Travis-CI is used to validate the build. For this a Docker container is created on travis for each From 0ee75b031dbbdd515a9ec1927764e92ba24850dc Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Apr 2018 19:06:27 -0600 Subject: [PATCH 18/34] Removed DOCKER.md --- DOCKER.md | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 DOCKER.md diff --git a/DOCKER.md b/DOCKER.md deleted file mode 100644 index d751f9ba..00000000 --- a/DOCKER.md +++ /dev/null @@ -1,33 +0,0 @@ -# Docker for Development - -This library requires a running instance of Mongo in order to run and pass -the unit tests. It is not expected for each developer to configure their -individual machine to match this environment so Docker is provided. - - -## Running docker-compose - -You will need docker-compose installed on your machine. - -From the root directory of this project run - -``` -docker-compose build -``` - -This will build the php container. -To connect to the php container and run the unit tests run - -``` -docker-compose run --rm php bash -``` - - -## Unit Tests Only - -You may run the unit tests through the container without connecting -with bash via - -``` -docker-composer run --rm php -``` From 76bbabe0c09133a16c8583755d06dc5195a6f907 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Apr 2018 19:48:28 -0600 Subject: [PATCH 19/34] Removed ini debugging line --- docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f9cb1c68..1f79210d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,6 @@ RUN apk add --no-cache \ git \ openssl-dev -RUN php --ini | sed -n -e 's/^.*Path: //p' RUN echo "memory_limit=2G" >> 'test' >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl -q install -f mongo && echo "extension=mongo.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi From 8c767ad911d57830640af1692f059ddc83646dbd Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 26 Apr 2018 07:49:04 +0100 Subject: [PATCH 20/34] Use aliases and simplify installing php extensions --- .travis.yml | 84 +++++++++++++++++++++++------------------------ docker/Dockerfile | 17 ++++++---- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39f23757..811cb1b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,78 +1,76 @@ sudo: false -language: none +language: php env: global: - COMPOSER_ARGS="--no-interaction" - ADAPTER_DEPS="alcaeus/mongo-php-adapter" - COVERAGE_DEPS="php-coveralls/php-coveralls" - - MONGO_DRIVER="mongodb" matrix: include: - - env: - - PHP_VERSION=5.6 + - php: 5.6 + env: - DEPS=lowest - - MONGO_DRIVER="mongo" - - env: - - PHP_VERSION=5.6 + - php: 5.6 + env: - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - - MONGO_DRIVER="mongo" - - env: - - PHP_VERSION=5.6 + - php: 5.6 + env: - DEPS=latest - - MONGO_DRIVER="mongo" - - env: - - PHP_VERSION=7 + - php: 7 + env: - DEPS=lowest - - env: - - PHP_VERSION=7 + - php: 7 + env: - DEPS=locked - LEGACY_DEPS="doctrine/doctrine-module doctrine/doctrine-orm-module phpunit/phpunit zendframework/zend-code" - - env: - - PHP_VERSION=7 + - php: 7 + env: - DEPS=latest - - env: - - PHP_VERSION=7.1 + - php: 7.1 + env: - DEPS=lowest - - env: - - PHP_VERSION=7.1 + - php: 7.1 + env: - DEPS=locked - CS_CHECK=true - TEST_COVERAGE=true - - XDEBUG=1 - - env: - - PHP_VERSION=7.1 + - php: 7.1 + env: - DEPS=latest - - env: - - PHP_VERSION=7.2 + - php: 7.2 + env: - DEPS=lowest - - env: - - PHP_VERSION=7.2 + - php: 7.2 + env: - DEPS=locked - - env: - - PHP_VERSION=7.2 + - php: 7.2 + env: - DEPS=latest before_install: - - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + - shopt -s expand_aliases + - alias composer="travis_retry docker-compose run --rm php composer" + - alias php="travis_retry docker-compose run --rm php php" + - docker-compose build --build-arg PHP_VERSION=${TRAVIS_PHP_VERSION} --build-arg XDEBUG=${TEST_COVERAGE:+1} --no-cache php + - composer --version + - php -v + - php -m install: - - docker-compose build --no-cache php - - travis_retry docker-compose run --rm php composer install $COMPOSER_ARGS --ignore-platform-reqs - - - composer config "platform.ext-mongo" "1.6.16" - - if [[ $LEGACY_DEPS != '' ]]; then travis_retry docker-compose run --rm php composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi - - if [[ $DEPS == 'latest' ]]; then travis_retry docker-compose run --rm php composer update $COMPOSER_ARGS ; fi - - if [[ $DEPS == 'lowest' ]]; then travis_retry docker-compose run --rm php composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi - - if [[ $MONGO_DRIVER == 'mongodb' ]] ; then travis_retry docker-compose run --rm php composer config "platform.ext-mongo" "1.6.16" && travis_retry docker-compose run --rm php composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi - - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi + - composer install $COMPOSER_ARGS --ignore-platform-reqs + - if [[ $LEGACY_DEPS != '' ]]; then composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi + - if [[ $DEPS == 'latest' ]]; then composer update $COMPOSER_ARGS ; fi + - if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi + - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show script: - - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php composer test-coverage ; else docker-compose run --rm php composer test ; fi - - if [[ $CS_CHECK == 'true' ]]; then travis_retry docker-compose run --rm php composer cs-check ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi + - if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi after_script: - - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry docker-compose run --rm php vendor/bin/php-coveralls -v ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then php vendor/bin/php-coveralls -v ; fi diff --git a/docker/Dockerfile b/docker/Dockerfile index 1f79210d..7a8501fd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,6 @@ ARG PHP_VERSION=7.2 -FROM php:${PHP_VERSION}-alpine - ARG XDEBUG=0 +FROM php:${PHP_VERSION}-alpine RUN apk add --no-cache \ autoconf \ @@ -11,15 +10,19 @@ RUN apk add --no-cache \ git \ openssl-dev -RUN echo "memory_limit=2G" >> 'test' >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini +RUN echo -e 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then pecl -q install -f mongo && echo "extension=mongo.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi -RUN if [ ${PHP_VERSION:0:1} == "7" ] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl install mongodb && docker-php-ext-enable mongodb && echo "extension=mongodb.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini; fi -RUN if [ ${XDEBUG} == "1" ] ; then pecl config-set php_ini `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini && pecl -q install -f xdebug && docker-php-ext-enable xdebug && echo "zend_extension=xdebug.so" >> `php --ini | sed -n -e 's/^.*Path: //p'`/php.ini ; fi +RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then \ + pecl install mongo && docker-php-ext-enable mongo ; \ + else \ + pecl install mongodb && docker-php-ext-enable mongodb ; \ + fi +RUN if [ ${XDEBUG} == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi +RUN composer config --global "platform.ext-mongo" "1.999" ; + RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ && chmod +x /usr/local/bin/entrypoint.sh WORKDIR /docker ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] -CMD ["./vendor/bin/phpunit"] From 7fb7d96f0266b976c2a834376907188b7a0e19f6 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 10:04:06 -0600 Subject: [PATCH 21/34] Minor tweeks and documentation for Docker --- .travis.yml | 13 ++++++------- CONTRIBUTING.md | 9 ++------- docker/Dockerfile | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 811cb1b8..4a9209d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php env: global: - - COMPOSER_ARGS="--no-interaction" - ADAPTER_DEPS="alcaeus/mongo-php-adapter" - COVERAGE_DEPS="php-coveralls/php-coveralls" @@ -60,12 +59,12 @@ before_install: - php -m install: - - composer install $COMPOSER_ARGS --ignore-platform-reqs - - if [[ $LEGACY_DEPS != '' ]]; then composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi - - if [[ $DEPS == 'latest' ]]; then composer update $COMPOSER_ARGS ; fi - - if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi - - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi - - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi + - composer install --no-interaction --ignore-platform-reqs + - if [[ $LEGACY_DEPS != '' ]]; then composer update --no-interaction --with-dependencies $LEGACY_DEPS ; fi + - if [[ $DEPS == 'latest' ]]; then composer update --no-interaction ; fi + - if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable --no-interaction ; fi + - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev --no-interaction $ADAPTER_DEPS ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-interaction $COVERAGE_DEPS ; fi - stty cols 120 && composer show script: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 973f0f23..93434659 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,18 +52,13 @@ individual machine to match this environment so Docker is provided. You will need docker-compose installed on your machine. Docker supports many PHP versions. You may specify the version of PHP you -want (default:7.2) to build against before running `docker-compose` and flag XDEBUG to +want (default:7.2) to build against when running `docker-compose` and flag XDEBUG to install (1) or not (default:0). -``` -export PHP_VERSION=7.1 -export XDEBUG=1 -``` - Next, from the root directory of this project, run ``` -docker-compose build +docker-compose build --build-arg PHP_VERSION=7.2 --build-arg XDEBUG=0 --no-cache php ``` To connect to the php container for development run diff --git a/docker/Dockerfile b/docker/Dockerfile index 7a8501fd..1c15b432 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -19,10 +19,10 @@ RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then \ fi RUN if [ ${XDEBUG} == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi RUN composer config --global "platform.ext-mongo" "1.999" ; - RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ && chmod +x /usr/local/bin/entrypoint.sh + WORKDIR /docker ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] From 79ae7f3bd38e1299f686893f1717609cd7a3eb54 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 12:40:42 -0600 Subject: [PATCH 22/34] Moved XDEBUG arg back below FROM --- docker/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1c15b432..9d364494 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,8 @@ ARG PHP_VERSION=7.2 -ARG XDEBUG=0 FROM php:${PHP_VERSION}-alpine +ARG XDEBUG=0 + RUN apk add --no-cache \ autoconf \ make \ From 7954365298befdaae9cf4a50cebd5df2c86e1699 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 12:56:04 -0600 Subject: [PATCH 23/34] Re-added COMPOSER_ARGS --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a9209d6..cf60e625 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ env: global: - ADAPTER_DEPS="alcaeus/mongo-php-adapter" - COVERAGE_DEPS="php-coveralls/php-coveralls" + - COMPOSER_ARGS="--no-interaction" matrix: include: @@ -59,12 +60,12 @@ before_install: - php -m install: - - composer install --no-interaction --ignore-platform-reqs - - if [[ $LEGACY_DEPS != '' ]]; then composer update --no-interaction --with-dependencies $LEGACY_DEPS ; fi - - if [[ $DEPS == 'latest' ]]; then composer update --no-interaction ; fi - - if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable --no-interaction ; fi - - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev --no-interaction $ADAPTER_DEPS ; fi - - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-interaction $COVERAGE_DEPS ; fi + - composer install $COMPOSER_ARGS --ignore-platform-reqs + - if [[ $LEGACY_DEPS != '' ]]; then composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi + - if [[ $DEPS == 'latest' ]]; then composer update $COMPOSER_ARGS ; fi + - if [[ $DEPS == 'lowest' ]]; then composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi + - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show script: From 7a075488600a490b456b75f32ecc1f853fecbb4a Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 20:28:24 -0600 Subject: [PATCH 24/34] Implemented all ideas from @webimpress --- {docker => .docker}/Dockerfile | 4 ++-- .travis.yml | 3 +++ CONTRIBUTING.md | 12 +++++++++--- docker-compose.yml | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) rename {docker => .docker}/Dockerfile (86%) diff --git a/docker/Dockerfile b/.docker/Dockerfile similarity index 86% rename from docker/Dockerfile rename to .docker/Dockerfile index 9d364494..a1484fca 100644 --- a/docker/Dockerfile +++ b/.docker/Dockerfile @@ -13,12 +13,12 @@ RUN apk add --no-cache \ RUN echo -e 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then \ +RUN if [ $PHP_VERSION == "5.6" ] ; then \ pecl install mongo && docker-php-ext-enable mongo ; \ else \ pecl install mongodb && docker-php-ext-enable mongodb ; \ fi -RUN if [ ${XDEBUG} == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi +RUN if [ $XDEBUG == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi RUN composer config --global "platform.ext-mongo" "1.999" ; RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ diff --git a/.travis.yml b/.travis.yml index cf60e625..65b865ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,3 +74,6 @@ script: after_script: - if [[ $TEST_COVERAGE == 'true' ]]; then php vendor/bin/php-coveralls -v ; fi + +notifications: + email: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 93434659..1515c3b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,13 +58,19 @@ install (1) or not (default:0). Next, from the root directory of this project, run ``` -docker-compose build --build-arg PHP_VERSION=7.2 --build-arg XDEBUG=0 --no-cache php +$ docker-compose build +``` + +To build a custom container use the flags + +``` +$ docker-compose build --build-arg PHP_VERSION=7.1 --build-arg XDEBUG=1 ``` To connect to the php container for development run ``` -docker-compose run php bash +$ docker-compose run --rm php bash ``` ### RUNNING UNIT TESTS IN THE CONTAINER @@ -86,7 +92,7 @@ $ composer test You may run the unit tests through the container without running bash via ``` -docker-composer run --rm php +$ docker-compose run --rm php composer test ``` ### DOCKER AND CONTINUOUS INTEGRATION diff --git a/docker-compose.yml b/docker-compose.yml index 8cc3bdf1..0bf06a6a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: php: build: context: . - dockerfile: docker/Dockerfile + dockerfile: .docker/Dockerfile args: - PHP_VERSION=${PHP_VERSION:-7.2} - XDEBUG=${XDEBUG:-0} From b6f19ce7af3170c8ed90c831028cef9ce6f752cb Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 20:34:09 -0600 Subject: [PATCH 25/34] Put brackets back around variables --- .docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index a1484fca..8ee46596 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -13,12 +13,12 @@ RUN apk add --no-cache \ RUN echo -e 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN if [ $PHP_VERSION == "5.6" ] ; then \ +RUN if [ ${PHP_VERSION} == "5.6" ] ; then \ pecl install mongo && docker-php-ext-enable mongo ; \ else \ pecl install mongodb && docker-php-ext-enable mongodb ; \ fi -RUN if [ $XDEBUG == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi +RUN if [ ${XDEBUG} == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi RUN composer config --global "platform.ext-mongo" "1.999" ; RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ From f91132a208318600c9c4c5fbfd83879170b38e11 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Apr 2018 20:43:41 -0600 Subject: [PATCH 26/34] Put brackets back around variables --- .docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 8ee46596..9d364494 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -13,7 +13,7 @@ RUN apk add --no-cache \ RUN echo -e 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory.ini RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN if [ ${PHP_VERSION} == "5.6" ] ; then \ +RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then \ pecl install mongo && docker-php-ext-enable mongo ; \ else \ pecl install mongodb && docker-php-ext-enable mongodb ; \ From 8173b69c31bd542063403c649600f9ae4ccefa16 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 27 Apr 2018 12:00:11 -0600 Subject: [PATCH 27/34] Move docker-compose to dist; move entrypoint to file; add ascii art --- .docker/Dockerfile | 6 ++---- .docker/ascii.txt | 18 ++++++++++++++++++ .docker/entrypoint.sh | 9 +++++++++ .gitattributes | 2 +- .gitignore | 1 + .travis.yml | 2 ++ docker-compose.yml => docker-compose.yml.dist | 0 7 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 .docker/ascii.txt create mode 100644 .docker/entrypoint.sh rename docker-compose.yml => docker-compose.yml.dist (100%) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 9d364494..f2169746 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -3,6 +3,8 @@ FROM php:${PHP_VERSION}-alpine ARG XDEBUG=0 +COPY .docker/entrypoint.sh /usr/local/bin/ + RUN apk add --no-cache \ autoconf \ make \ @@ -20,10 +22,6 @@ RUN if [ ${PHP_VERSION:0:3} == "5.6" ] ; then \ fi RUN if [ ${XDEBUG} == "1" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; fi RUN composer config --global "platform.ext-mongo" "1.999" ; -RUN echo -e '#!/bin/sh ' > /usr/local/bin/entrypoint.sh \ - && echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \ - && echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \ - && chmod +x /usr/local/bin/entrypoint.sh WORKDIR /docker ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/.docker/ascii.txt b/.docker/ascii.txt new file mode 100644 index 00000000..d357c154 --- /dev/null +++ b/.docker/ascii.txt @@ -0,0 +1,18 @@ + _ _ _ + __| | ___ ___ | |_ _ __ (_) _ __ ___ + / _` | / _ \ / __|| __|| '__|| || '_ \ / _ \ +| (_| || (_) || (__ | |_ | | | || | | || __/ + \__,_| \___/ \___| \__||_| |_||_| |_| \___| + + _ +(_) _ __ +| || '_ \ +| || | | | +|_||_| |_| + + _ _ _ _ _ + __ _ _ __ (_) __ _ (_)| |(_)| |_ _ _ + / _` || '_ \ | | / _` || || || || __|| | | | +| (_| || |_) || || (_| || || || || |_ | |_| | + \__,_|| .__/ |_| \__, ||_||_||_| \__| \__, | + |_| |___/ |___/ diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100644 index 00000000..eec9bae3 --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; + do sleep 1; + done + +cat ascii.txt + +exec "$@" diff --git a/.gitattributes b/.gitattributes index 25b1bd1d..8bd0baf5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,4 +6,4 @@ phpcs.xml export-ignore phpunit.xml.dist export-ignore docker-compose.yml export-ignore -Dockerfile export-ignore +/.docker export-ignore diff --git a/.gitignore b/.gitignore index 7fffcbdb..9bb3dd67 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ test/data/ test/assets/module/*/config/module.config.php clover.xml coveralls-upload.json +docker-compose.yml diff --git a/.travis.yml b/.travis.yml index 65b865ca..25748c33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,7 @@ matrix: - DEPS=latest before_install: + - cp docker-compose.yml.dist docker-compose.yml - shopt -s expand_aliases - alias composer="travis_retry docker-compose run --rm php composer" - alias php="travis_retry docker-compose run --rm php php" @@ -67,6 +68,7 @@ install: - if [[ $TRAVIS_PHP_VERSION != "5.6" ]] ; then composer require --dev $COMPOSER_ARGS $ADAPTER_DEPS ; fi - if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi - stty cols 120 && composer show + - composer show script: - if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi diff --git a/docker-compose.yml b/docker-compose.yml.dist similarity index 100% rename from docker-compose.yml rename to docker-compose.yml.dist From acf0cf066957c6cc5890110b6cdab783fe964efd Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 27 Apr 2018 12:04:51 -0600 Subject: [PATCH 28/34] Made entrypoint.sh executable --- .docker/{ascii.txt => ascii.art} | 0 .docker/entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .docker/{ascii.txt => ascii.art} (100%) mode change 100644 => 100755 .docker/entrypoint.sh diff --git a/.docker/ascii.txt b/.docker/ascii.art similarity index 100% rename from .docker/ascii.txt rename to .docker/ascii.art diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh old mode 100644 new mode 100755 index eec9bae3..724c1046 --- a/.docker/entrypoint.sh +++ b/.docker/entrypoint.sh @@ -4,6 +4,6 @@ while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done -cat ascii.txt +cat ascii.art exec "$@" From 3043a2321548f75c687fd2cae0a50e36a445749b Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 27 Apr 2018 12:52:07 -0600 Subject: [PATCH 29/34] Added ascii art --- .docker/ascii.art | 2 -- .docker/entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.docker/ascii.art b/.docker/ascii.art index d357c154..e6ce467f 100644 --- a/.docker/ascii.art +++ b/.docker/ascii.art @@ -3,13 +3,11 @@ / _` | / _ \ / __|| __|| '__|| || '_ \ / _ \ | (_| || (_) || (__ | |_ | | | || | | || __/ \__,_| \___/ \___| \__||_| |_||_| |_| \___| - _ (_) _ __ | || '_ \ | || | | | |_||_| |_| - _ _ _ _ _ __ _ _ __ (_) __ _ (_)| |(_)| |_ _ _ / _` || '_ \ | | / _` || || || || __|| | | | diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh index 724c1046..ec0ac712 100755 --- a/.docker/entrypoint.sh +++ b/.docker/entrypoint.sh @@ -4,6 +4,6 @@ while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done -cat ascii.art +cat ./.docker/ascii.art exec "$@" From a7c06577334aba17131c0ad2f9ba3e94829d2b7d Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Fri, 27 Apr 2018 13:15:28 -0600 Subject: [PATCH 30/34] Updated docs and ascii art --- .docker/ascii.art | 36 ++++++++++++++++++++---------------- CONTRIBUTING.md | 6 ++++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.docker/ascii.art b/.docker/ascii.art index e6ce467f..1b47addf 100644 --- a/.docker/ascii.art +++ b/.docker/ascii.art @@ -1,16 +1,20 @@ - _ _ _ - __| | ___ ___ | |_ _ __ (_) _ __ ___ - / _` | / _ \ / __|| __|| '__|| || '_ \ / _ \ -| (_| || (_) || (__ | |_ | | | || | | || __/ - \__,_| \___/ \___| \__||_| |_||_| |_| \___| - _ -(_) _ __ -| || '_ \ -| || | | | -|_||_| |_| - _ _ _ _ _ - __ _ _ __ (_) __ _ (_)| |(_)| |_ _ _ - / _` || '_ \ | | / _` || || || || __|| | | | -| (_| || |_) || || (_| || || || || |_ | |_| | - \__,_|| .__/ |_| \__, ||_||_||_| \__| \__, | - |_| |___/ |___/ ++-------------------------+ && %&&( +|ooooo:. .:ooooooooooooo| &&&&&&&&&&&& +|ooooo. ::ooooooooooo| ,& &&& +|ooooo:. .oooooooooo| ,//&& (&&&&& +|ooooooo:. .:ooooooo| / ////&&%&&% #(&&&& +|ooooo:... :ooooo| ,*////######&&& &&&&& +|ooo:. .. .:ooo| //////########&&&&&&&&& +|o:. :ooo. :o| ///////#########&&&&&&& +|o. .:oooo. o| ////////&######&&&&&&& +|. . ..ooooo.. .| &%(/////&&&&&####&&&&&&& +| :oooooooooooooo. | &&& &&&&&&##&&&&&&&& +| .:::::::oooooo: | / * & (&&&&&&&%&&&&&&&&&( +|. .:oooo:. .| & % / &&&&&&&&& &&& +|o. :oooo:. .o| & ( & ( . &&&&& %&& +|oo. :o::. .oo| ( & &&&& +|ooo:.. .oooo| ** * &&&& +|oooooo:.. ..:oooooo| / ++-------------------------+ / / + + Doctrine in Apigility diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1515c3b5..6f0e15ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,6 +48,12 @@ This library requires a running instance of Mongo in order to run and pass the unit tests. It is not expected for each developer to configure their individual machine to match this environment so Docker is provided. +To use Docker you must copy the included `docker-compose.yml.dist` to `docker-compose.yml` + +``` +$ cp docker-compose.yml.dist docker-compose.yml +``` + ### RUNNING DOCKER-COMPOSE You will need docker-compose installed on your machine. From 142233a2fa3515263125ecb3ee1da753d477d657 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 28 Apr 2018 13:04:18 -0600 Subject: [PATCH 31/34] Removed .dist in favor of Docker override --- .travis.yml | 1 - CONTRIBUTING.md | 12 ++++++------ docker-compose.yml.dist => docker-compose.yml | 0 3 files changed, 6 insertions(+), 7 deletions(-) rename docker-compose.yml.dist => docker-compose.yml (100%) diff --git a/.travis.yml b/.travis.yml index 25748c33..bfa98267 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,6 @@ matrix: - DEPS=latest before_install: - - cp docker-compose.yml.dist docker-compose.yml - shopt -s expand_aliases - alias composer="travis_retry docker-compose run --rm php composer" - alias php="travis_retry docker-compose run --rm php php" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6f0e15ce..c36ed6f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,12 +48,6 @@ This library requires a running instance of Mongo in order to run and pass the unit tests. It is not expected for each developer to configure their individual machine to match this environment so Docker is provided. -To use Docker you must copy the included `docker-compose.yml.dist` to `docker-compose.yml` - -``` -$ cp docker-compose.yml.dist docker-compose.yml -``` - ### RUNNING DOCKER-COMPOSE You will need docker-compose installed on your machine. @@ -107,6 +101,12 @@ When you have made a change and created a pull request for it Travis-CI is used to validate the build. For this a Docker container is created on travis for each build matrix and the unit tests are ran identical to running unit tests on Docker locally. +### OVERRIDING DOCKER FOR LOCAL DEVELOPMENT + +Docker supports overriding the docker-compose.yml file. See +[https://docs.docker.com/compose/extends/#multiple-compose-files](https://docs.docker.com/compose/extends/#multiple-compose-files) +for more information. + ## CODING STANDARDS While Apigility uses Zend Framework 2 coding standards, in practice, we check diff --git a/docker-compose.yml.dist b/docker-compose.yml similarity index 100% rename from docker-compose.yml.dist rename to docker-compose.yml From 4469bfb2439cd364e63fab9170309e0fb89b54f7 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 30 Apr 2018 10:48:51 -0600 Subject: [PATCH 32/34] Add override to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9bb3dd67..970d4ecc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ test/data/ test/assets/module/*/config/module.config.php clover.xml coveralls-upload.json -docker-compose.yml +docker-compose.override.yml From 1090652e6bcdc2197a71680e9eb8dbca1c6b0a8f Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 30 Apr 2018 12:00:48 -0600 Subject: [PATCH 33/34] Added install and update hooks for comopser for MongoDB Shim --- composer.json | 5 +++++ scripts/mongodb-shim | 1 + scripts/mongodb-shim.php | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 120000 scripts/mongodb-shim create mode 100755 scripts/mongodb-shim.php diff --git a/composer.json b/composer.json index 868b9c6f..b3deef9e 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,12 @@ "ZFTest\\Apigility\\Doctrine\\": "test/src/" } }, + "bin": [ + "./scripts/mongodb-shim" + ], "scripts": { + "pre-install-cmd": "mongodb-shim", + "pre-update-cmd": "mongodb-shim", "check": [ "@cs-check", "@test" diff --git a/scripts/mongodb-shim b/scripts/mongodb-shim new file mode 120000 index 00000000..0b6dfe48 --- /dev/null +++ b/scripts/mongodb-shim @@ -0,0 +1 @@ +mongodb-shim.php \ No newline at end of file diff --git a/scripts/mongodb-shim.php b/scripts/mongodb-shim.php new file mode 100755 index 00000000..2f6f0811 --- /dev/null +++ b/scripts/mongodb-shim.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php + + */ + +$version = explode('.', PHP_VERSION); +if ($version[0] <= 5) { + return; +} + +$config = json_decode(file_get_contents(__DIR__ . '/../composer.json'), true); +$change = false; + +if (! in_array('alcaeus/mongo-php-adapter', array_keys($config['require']))) { + $config['require']['alcaeus/mongo-php-adapter'] = '^1.1'; + $change = true; +} + +if (! isset($config['config']) + || ! isset($config['config']['platform']) + || ! isset($config['config']['platform']['ext-mongo']) +) { + $config['config']['platform']['ext-mongo'] = '1.6.16'; + $change = true; +} + +if ($change) { + echo "Including MongoDB shim alcaeus/mongo-php-adapter\n"; + $contents = json_encode($config, JSON_PRETTY_PRINT); + $contents = str_replace('\\/', '/', $contents); + file_put_contents(__DIR__ . '/../composer.json', $contents); +} From 78cdf710b90b457f1f6392208e18e4bb0220d712 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 30 Apr 2018 14:53:12 -0600 Subject: [PATCH 34/34] Added JSON_UNESCAPED_SLASHES --- scripts/mongodb-shim.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/mongodb-shim.php b/scripts/mongodb-shim.php index 2f6f0811..fbefca7f 100755 --- a/scripts/mongodb-shim.php +++ b/scripts/mongodb-shim.php @@ -29,7 +29,9 @@ if ($change) { echo "Including MongoDB shim alcaeus/mongo-php-adapter\n"; - $contents = json_encode($config, JSON_PRETTY_PRINT); - $contents = str_replace('\\/', '/', $contents); - file_put_contents(__DIR__ . '/../composer.json', $contents); + + file_put_contents( + __DIR__ . '/../composer.json', + json_encode($config, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES) + ); }