Skip to content

Commit

Permalink
90%: Migrate build to circleci (#139)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rsinger authored Jan 12, 2022
1 parent 1e47bec commit 1d24de0
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 24 deletions.
48 changes: 48 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RESQUE_SERVER=redis
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cache
.idea
composer.phar
composer.lock
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
[![<CircleCI>](https://circleci.com/gh/talis/tripod-php.svg?style=svg)](<https://circleci.com/gh/talis/tripod-php>)

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).

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
53 changes: 49 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
mongo:
image: rossfsinger/mongo-2.6.12:latest
ports:
- "27017:27017"
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
10 changes: 10 additions & 0 deletions docker/Dockerfile-php55
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions docker/Dockerfile-php56
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions docker/Dockerfile-php70
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions docker/Dockerfile-php72
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion src/classes/ExtendedGraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function __construct($graph=null){

public function __destruct(){
unset($this->_index);
unset($this);
}

/**
Expand Down
28 changes: 14 additions & 14 deletions test/unit/mongo/MongoTripodConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -150,15 +150,15 @@ 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()
{
$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(){
Expand All @@ -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"
)
);
Expand All @@ -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(){
Expand All @@ -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"
)
);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -952,7 +952,7 @@ public function testSearchConfigNotPresent()
$config["data_sources"] = array(
"mongo1"=>array(
"type"=>"mongo",
"connection"=>"mongodb://localhost"
"connection"=>"mongodb://mongodb"
)
);
$config["stores"] = array(
Expand Down Expand Up @@ -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());
}
Expand All @@ -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()
{
Expand All @@ -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);
Expand All @@ -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')),
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mongo/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mongo/data/configQueueOperations.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"data_sources" : {
"rs1" : {
"type" : "mongo",
"connection": "mongodb:\/\/localhost",
"connection": "mongodb:\/\/mongodb",
"replicaSet": ""
}
},
Expand Down

0 comments on commit 1d24de0

Please sign in to comment.