From 1d24de0ded460dd0fd42cb40b83c2ba8d2829be8 Mon Sep 17 00:00:00 2001 From: Ross Singer Date: Wed, 12 Jan 2022 10:03:32 -0500 Subject: [PATCH] 90%: Migrate build to circleci (#139) * wip * Add workflow * Use right image tag * Try a newer php image to test something * Continue futzing with docker images * Just doing what the error message says * use php orb * Take out matrix * wip * Updated config.yml * Updated config.yml * Updated config.yml * Use older machine * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Use docker for build * Simplify logic * wip * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Updated config.yml * Don't build the docker images as part of the build * Updated config.yml * Leave out the build config for one service and see what happens * Disable for each service * Add PHP 7.2 support * Abstract away mongo version * depend on the right service name * Use network and alias * Wrong syntax for matrix * Another stab at the parameters * Alias mongo via links instead * See if this install the correct version of phpunit * Add build status to readme * Remove php 7.4 --- .circleci/config.yml | 48 +++++++++++++++++ .env | 1 + .gitignore | 1 + README.md | 2 +- composer.json | 2 +- docker-compose.yml | 53 +++++++++++++++++-- docker/Dockerfile-php55 | 10 ++++ docker/Dockerfile-php56 | 10 ++++ docker/Dockerfile-php70 | 10 ++++ docker/Dockerfile-php72 | 10 ++++ src/classes/ExtendedGraph.class.php | 1 - test/unit/mongo/MongoTripodConfigTest.php | 28 +++++----- test/unit/mongo/data/config.json | 4 +- .../mongo/data/configQueueOperations.json | 2 +- 14 files changed, 158 insertions(+), 24 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .env create mode 100644 docker/Dockerfile-php55 create mode 100644 docker/Dockerfile-php56 create mode 100644 docker/Dockerfile-php70 create mode 100644 docker/Dockerfile-php72 diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..1df99f1e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,48 @@ +version: 2.1 +parameters: &version + version: + type: string + default: "php55" + +commands: + install_composer_dependencies: + parameters: *version + description: Install composer dependencies for << parameters.version >> + steps: + - run: docker-compose run << parameters.version >> composer install + unit_tests: + parameters: *version + description: Run unit tests for << parameters.version >> + steps: + - run: docker-compose run << parameters.version >> ./vendor/bin/phpunit test/unit + performance_tests: + parameters: *version + description: Run performance tests for << parameters.version >> + steps: + - run: docker-compose run << parameters.version >> ./vendor/bin/phpunit test/performance + +jobs: + test: + parameters: *version + machine: + image: ubuntu-2004:202010-01 + steps: + - checkout + - install_composer_dependencies: + version: << parameters.version >> + - unit_tests: + version: << parameters.version >> + - performance_tests: + version: << parameters.version >> + +workflows: + build_and_test: + jobs: + - test: + matrix: + parameters: + version: + - php55 + - php56 + - php70 + - php72 \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 00000000..0227720f --- /dev/null +++ b/.env @@ -0,0 +1 @@ +RESQUE_SERVER=redis \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3f246e37..a3d2da46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.cache .idea composer.phar composer.lock diff --git a/README.md b/README.md index 4b08361b..e39c9b61 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![tripod-php](logo.png) ========== -[![Build status](https://travis-ci.org/talis/tripod-php.svg)](https://travis-ci.org/talis/tripod-php) +[![](https://circleci.com/gh/talis/tripod-php.svg?style=svg)]() Object Graph Mapper for managing [RDF](http://www.w3.org/TR/rdf-primer/) data stored in [MongoDB](http://www.mongodb.org/). See also [tripod-node](https://github.com/talis/tripod-node). diff --git a/composer.json b/composer.json index 9659031e..63fe554d 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "mongodb/mongodb": "1.0.4" }, "require-dev": { - "phpunit/phpunit": "4.8.", + "phpunit/phpunit": "^4.8", "squizlabs/php_codesniffer": "3.2.*" }, "autoload": { diff --git a/docker-compose.yml b/docker-compose.yml index 95fae1a8..2785bd37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,49 @@ -mongo: - image: rossfsinger/mongo-2.6.12:latest - ports: - - "27017:27017" \ No newline at end of file +version: "3.7" + +x-base-config: &base-config + volumes: + - ./:/var/tripod-php + - ./vendor:/var/tripod-php/vendor:delegated + links: + - "mongo26:mongodb" + - redis + depends_on: + - mongo26 + - redis + working_dir: /var/tripod-php + env_file: .env + +services: + php55: + # build: + # context: ./docker + # dockerfile: Dockerfile-php55 + image: talis/tripod-php:php55-latest + <<: *base-config + + php56: + # build: + # context: ./docker + # dockerfile: Dockerfile-php56 + image: talis/tripod-php:php56-latest + <<: *base-config + + php70: + # build: + # context: ./docker + # dockerfile: Dockerfile-php70 + image: talis/tripod-php:php70-latest + <<: *base-config + + php72: + # build: + # context: ./docker + # dockerfile: Dockerfile-php72 + image: talis/tripod-php:php72-latest + <<: *base-config + + mongo26: + image: rossfsinger/mongo-2.6.12:latest + + redis: + image: redis:latest diff --git a/docker/Dockerfile-php55 b/docker/Dockerfile-php55 new file mode 100644 index 00000000..b4d5dafa --- /dev/null +++ b/docker/Dockerfile-php55 @@ -0,0 +1,10 @@ +FROM php:5.5-cli + +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN apt-get update && apt-get install -y git ca-certificates && \ + chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions pcntl redis mongodb-1.1.9 && \ + curl https://getcomposer.org/installer > /tmp/composer-setup.php && \ + php /tmp/composer-setup.php --install-dir /usr/local/bin/ --filename composer \ + && rm /tmp/composer-setup.php \ No newline at end of file diff --git a/docker/Dockerfile-php56 b/docker/Dockerfile-php56 new file mode 100644 index 00000000..b133506d --- /dev/null +++ b/docker/Dockerfile-php56 @@ -0,0 +1,10 @@ +FROM php:5.6-cli + +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions pcntl redis mongodb-1.1.9 && \ + curl https://getcomposer.org/installer > /tmp/composer-setup.php && \ + php /tmp/composer-setup.php --install-dir /usr/local/bin/ --filename composer \ + && rm /tmp/composer-setup.php && \ + apt-get update && apt-get install -y git \ No newline at end of file diff --git a/docker/Dockerfile-php70 b/docker/Dockerfile-php70 new file mode 100644 index 00000000..b37b1579 --- /dev/null +++ b/docker/Dockerfile-php70 @@ -0,0 +1,10 @@ +FROM php:7.0-cli + +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions pcntl redis mongodb-1.1.9 && \ + curl https://getcomposer.org/installer > /tmp/composer-setup.php && \ + php /tmp/composer-setup.php --install-dir /usr/local/bin/ --filename composer \ + && rm /tmp/composer-setup.php && \ + apt-get update && apt-get install -y git \ No newline at end of file diff --git a/docker/Dockerfile-php72 b/docker/Dockerfile-php72 new file mode 100644 index 00000000..416b0402 --- /dev/null +++ b/docker/Dockerfile-php72 @@ -0,0 +1,10 @@ +FROM php:7.2-cli + +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions pcntl redis mongodb-1.4.4 && \ + curl https://getcomposer.org/installer > /tmp/composer-setup.php && \ + php /tmp/composer-setup.php --install-dir /usr/local/bin/ --filename composer \ + && rm /tmp/composer-setup.php && \ + apt-get update && apt-get install -y git \ No newline at end of file diff --git a/src/classes/ExtendedGraph.class.php b/src/classes/ExtendedGraph.class.php index 4285acd5..d5c6f113 100644 --- a/src/classes/ExtendedGraph.class.php +++ b/src/classes/ExtendedGraph.class.php @@ -69,7 +69,6 @@ public function __construct($graph=null){ public function __destruct(){ unset($this->_index); - unset($this); } /** diff --git a/test/unit/mongo/MongoTripodConfigTest.php b/test/unit/mongo/MongoTripodConfigTest.php index 4477f630..f6412eb9 100644 --- a/test/unit/mongo/MongoTripodConfigTest.php +++ b/test/unit/mongo/MongoTripodConfigTest.php @@ -76,7 +76,7 @@ public function testTConfigRepSetConnStr() "connection"=>"mongodb://tloghost:27017,tloghost:27018/admin", "replicaSet" => "tlogrepset" ), - "mongo"=>array("type"=>"mongo","connection" => "mongodb://localhost") + "mongo"=>array("type"=>"mongo","connection" => "mongodb://mongodb") ); $config["defaultContext"] = "http://talisaspire.com/"; $config["stores"] = array( @@ -111,7 +111,7 @@ public function testTConfigRepSetConnStrThrowsException() $config["data_sources"] = array( "mongo1"=>array( "type"=>"mongo", - "connection"=>"mongodb://localhost" + "connection"=>"mongodb://mongodb" ), "rs1"=>array( "type"=>"mongo", @@ -150,7 +150,7 @@ public function testCardinality() public function testGetConnectionString() { - $this->assertEquals("mongodb://localhost:27017/",\Tripod\Config::getInstance()->getConnStr("tripod_php_testing")); + $this->assertEquals("mongodb://mongodb:27017/",\Tripod\Config::getInstance()->getConnStr("tripod_php_testing")); } public function testGetConnectionStringThrowsException() @@ -158,7 +158,7 @@ public function testGetConnectionStringThrowsException() $this->setExpectedException( '\Tripod\Exceptions\ConfigException', 'Database notexists does not exist in configuration'); - $this->assertEquals("mongodb://localhost:27017/",\Tripod\Config::getInstance()->getConnStr("notexists")); + $this->assertEquals("mongodb://mongodb:27017/",\Tripod\Config::getInstance()->getConnStr("notexists")); } public function testGetConnectionStringForReplicaSet(){ @@ -167,7 +167,7 @@ public function testGetConnectionStringForReplicaSet(){ $config["data_sources"] = array( "rs"=>array( "type"=>"mongo", - "connection"=>"mongodb://localhost:27017,localhost:27018/admin", + "connection"=>"mongodb://mongodb:27017,localhost:27018/admin", "replicaSet" => "myrepset" ) ); @@ -184,7 +184,7 @@ public function testGetConnectionStringForReplicaSet(){ \Tripod\Config::setConfig($config); $mtc = \Tripod\Config::getInstance(); - $this->assertEquals("mongodb://localhost:27017,localhost:27018/admin",$mtc->getConnStr("tripod_php_testing")); + $this->assertEquals("mongodb://mongodb:27017,localhost:27018/admin",$mtc->getConnStr("tripod_php_testing")); } public function testGetConnectionStringThrowsExceptionForReplicaSet(){ @@ -196,11 +196,11 @@ public function testGetConnectionStringThrowsExceptionForReplicaSet(){ $config["data_sources"] = array( "mongo1"=>array( "type"=>"mongo", - "connection"=>"mongodb://localhost" + "connection"=>"mongodb://mongodb" ), "rs1"=>array( "type"=>"mongo", - "connection" => "mongodb://localhost:27017,localhost:27018", + "connection" => "mongodb://mongodb:27017,localhost:27018", "replicaSet" => "myrepset" ) ); @@ -230,7 +230,7 @@ public function testCompoundIndexAllArraysThrowsException() $config["data_sources"] = array( "db1"=>array( "type"=>"mongo", - "connection"=>"mongodb://localhost" + "connection"=>"mongodb://mongodb" ), "db2"=>array( "type"=>"mongo", @@ -952,7 +952,7 @@ public function testSearchConfigNotPresent() $config["data_sources"] = array( "mongo1"=>array( "type"=>"mongo", - "connection"=>"mongodb://localhost" + "connection"=>"mongodb://mongodb" ) ); $config["stores"] = array( @@ -1702,7 +1702,7 @@ public function testGetResqueServer() if(!getenv(MONGO_TRIPOD_RESQUE_SERVER)) { - putenv(MONGO_TRIPOD_RESQUE_SERVER . "=localhost:6379"); + putenv(MONGO_TRIPOD_RESQUE_SERVER . "=redis"); } $this->assertEquals(getenv(MONGO_TRIPOD_RESQUE_SERVER), \Tripod\Mongo\Config::getResqueServer()); } @@ -1714,7 +1714,7 @@ public function testMongoConnectionNoExceptions() $mockConfig->loadConfig(json_decode(file_get_contents(dirname(__FILE__).'/data/config.json'), true)); $mockConfig->expects($this->exactly(1)) ->method('getMongoClient') - ->with('mongodb://localhost:27017/?connectTimeoutMS=20000') + ->with('mongodb://mongodb:27017/?connectTimeoutMS=20000') ->will($this->returnCallback( function() { @@ -1733,7 +1733,7 @@ public function testMongoConnectionExceptionThrown() $mockConfig->loadConfig(json_decode(file_get_contents(dirname(__FILE__).'/data/config.json'), true)); $mockConfig->expects($this->exactly(30)) ->method('getMongoClient') - ->with('mongodb://localhost:27017/?connectTimeoutMS=20000') + ->with('mongodb://mongodb:27017/?connectTimeoutMS=20000') ->will($this->throwException(new ConnectionTimeoutException('Exception thrown when connecting to Mongo'))); $mockConfig->getDatabase('tripod_php_testing', 'rs1', ReadPreference::RP_SECONDARY_PREFERRED); @@ -1744,7 +1744,7 @@ public function testMongoConnectionNoExceptionThrownWhenConnectionThrowsSomeExce $mockConfig->loadConfig(json_decode(file_get_contents(dirname(__FILE__).'/data/config.json'), true)); $mockConfig->expects($this->exactly(5)) ->method('getMongoClient') - ->with('mongodb://localhost:27017/?connectTimeoutMS=20000') + ->with('mongodb://mongodb:27017/?connectTimeoutMS=20000') ->will($this->onConsecutiveCalls( $this->throwException(new ConnectionTimeoutException('Exception thrown when connecting to Mongo')), $this->throwException(new ConnectionTimeoutException('Exception thrown when connecting to Mongo')), diff --git a/test/unit/mongo/data/config.json b/test/unit/mongo/data/config.json index b8d78c30..8775545d 100644 --- a/test/unit/mongo/data/config.json +++ b/test/unit/mongo/data/config.json @@ -21,12 +21,12 @@ "data_sources" : { "rs1" : { "type" : "mongo", - "connection": "mongodb:\/\/localhost:27017/", + "connection": "mongodb:\/\/mongodb:27017/", "replicaSet": "" }, "rs2" : { "type" : "mongo", - "connection": "mongodb:\/\/localhost:27017/", + "connection": "mongodb:\/\/mongodb:27017/", "replicaSet": "" } }, diff --git a/test/unit/mongo/data/configQueueOperations.json b/test/unit/mongo/data/configQueueOperations.json index d6a1b5f3..d04987bc 100644 --- a/test/unit/mongo/data/configQueueOperations.json +++ b/test/unit/mongo/data/configQueueOperations.json @@ -21,7 +21,7 @@ "data_sources" : { "rs1" : { "type" : "mongo", - "connection": "mongodb:\/\/localhost", + "connection": "mongodb:\/\/mongodb", "replicaSet": "" } },