diff --git a/.travis.yml b/.travis.yml index 2810d41..a5c0337 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,5 @@ -language: php -php: -# - 5.5 -# - 5.4 - - 5.3 - -#before_install: -# - sudo apt-get update +sudo: required +dist: trusty env: global: @@ -15,14 +9,14 @@ env: - secure: "XRsqGDqdu5uhdj2lF4SZ6qv6Y0PdcRPcvE13XvVGnIYRZaITelP3eJNSvLPO+Q5k4mBmKCz8t+ws/OVRRwSAXYaKe0Z8ZXgEcNyo1nEwGekC35mTuG1FFfB/pbuBp5/OWjw6bgz2tEHhKuFIbHytpT9zJQYy+D07rzOYeUsZjOY=" before_script: - - sudo chmod +x scripts/install.sh - - scripts/install.sh + - sudo chmod +x scripts/travis_install.sh + - scripts/travis_install.sh - cd /opt/codebender/builder/Symfony - sudo chmod -R 777 app/cache app/logs - - echo 'error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + - echo 'error_reporting = E_ALL' >> /etc/php5/cli/conf.d/travis.ini - cd /opt/codebender/builder - - sudo chmod +x scripts/apache_install.sh - - scripts/apache_install.sh + - sudo chmod +x scripts/travis_apache_install.sh + - scripts/travis_apache_install.sh - cd /opt/codebender/builder/Symfony script: @@ -37,6 +31,3 @@ after_script: notifications: irc: "chat.freenode.net#codebender.cc" -# email: -# recipients: -# - girder@codebender.cc diff --git a/Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php b/Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php index 969fb51..1bd8a1c 100644 --- a/Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php +++ b/Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php @@ -87,7 +87,7 @@ protected function compile($contents) { $apiHandler = $this->get('codebender_builder.handler'); - $contents = $this->checkForUserIdProjectId($contents); + $contents = $this->addUserIdProjectIdIfNotInRequest($contents); $files = $contents["files"]; @@ -210,17 +210,10 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari * @param array $requestContents * @return array */ - protected function checkForUserIdProjectId($requestContents) + protected function addUserIdProjectIdIfNotInRequest($requestContents) { - if (!array_key_exists('userId', $requestContents)) { - $requestContents['userId'] = 'null'; - } - - if (!array_key_exists('projectId', $requestContents)) { - $requestContents['projectId'] = 'null'; - } - - return $requestContents; + $nullDefaults = ['userId' => 'null', 'projectId' => 'null']; + return array_merge($nullDefaults, (array)$requestContents); } } diff --git a/Symfony/src/Codebender/BuilderBundle/Tests/Controller/DefaultControllerUnitTest.php b/Symfony/src/Codebender/BuilderBundle/Tests/Controller/DefaultControllerUnitTest.php index 2df3d13..32e2d31 100644 --- a/Symfony/src/Codebender/BuilderBundle/Tests/Controller/DefaultControllerUnitTest.php +++ b/Symfony/src/Codebender/BuilderBundle/Tests/Controller/DefaultControllerUnitTest.php @@ -158,7 +158,7 @@ public function testCompileNonJsonCompilerResponse() { // Override previous controller mock. More class member functions need to get mocked. $controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController') ->disableOriginalConstructor() - ->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries']) + ->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries']) ->getMock(); $controller->setContainer($container); @@ -170,7 +170,7 @@ public function testCompileNonJsonCompilerResponse() { $controller->expects($this->at(0))->method('get')->with('codebender_builder.handler') ->willReturn($apiHandler); - $controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []]) + $controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest')->with(['files' => []]) ->willReturn(['files' => []]); $controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([]) ->willReturn(['libraries' => []]); @@ -191,7 +191,7 @@ public function testCompileFalseCompilationWithoutStepIncluded() { // Override previous controller mock. More class member functions need to get mocked. $controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController') ->disableOriginalConstructor() - ->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries']) + ->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries']) ->getMock(); $controller->setContainer($container); @@ -203,7 +203,7 @@ public function testCompileFalseCompilationWithoutStepIncluded() { $controller->expects($this->at(0))->method('get')->with('codebender_builder.handler') ->willReturn($apiHandler); - $controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []]) + $controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest')->with(['files' => []]) ->willReturn(['files' => []]); $controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([]) ->willReturn(['libraries' => []]); @@ -228,7 +228,7 @@ public function testCompileFalseCompilationWithStepIncluded() { // Override previous controller mock. More class member functions need to get mocked. $controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController') ->disableOriginalConstructor() - ->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries']) + ->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries']) ->getMock(); $controller->setContainer($container); @@ -240,9 +240,10 @@ public function testCompileFalseCompilationWithStepIncluded() { $controller->expects($this->at(0))->method('get')->with('codebender_builder.handler') ->willReturn($apiHandler); - $controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []]) - ->willReturn(['files' => []]); - $controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([]) + $controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest') + ->with(['files' => [], 'libraries' => []]) + ->willReturn(['files' => [], 'libraries' => []]); + $controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([], []) ->willReturn(['libraries' => []]); $container->expects($this->once())->method('getParameter')->with('compiler') @@ -251,7 +252,7 @@ public function testCompileFalseCompilationWithStepIncluded() { ->with('http://compiler/url', '{"files":[],"libraries":[]}') ->willReturn('{"success":false,"message":"someError","step":5}'); - $functionResponse = $function->invoke($controller, ['files' => []]); + $functionResponse = $function->invoke($controller, ['files' => [], 'libraries' => []]); $this->assertEquals('{"success":false,"message":"someError","step":5,"additionalCode":[]}', $functionResponse); } @@ -435,7 +436,7 @@ public function testcheckUserIdProjectIdHasNone() { /* * Use ReflectionMethod class to make compile protected function accessible from current context */ - $function = $this->getMethod('checkForUserIdProjectId'); + $function = $this->getMethod('addUserIdProjectIdIfNotInRequest'); $requestContent = ['files' => [['filename' => 'project.ino', 'content' =>'']]]; @@ -451,7 +452,7 @@ public function testcheckUserIdProjectIdHasOnlyUserId() { /* * Use ReflectionMethod class to make compile protected function accessible from current context */ - $function = $this->getMethod('checkForUserIdProjectId'); + $function = $this->getMethod('addUserIdProjectIdIfNotInRequest'); $requestContent = ['userId' => 1, 'files' => [['filename' => 'project.ino', 'content' =>'']]]; @@ -467,7 +468,7 @@ public function testcheckUserIdProjectIdHasOnlyProjectId() { /* * Use ReflectionMethod class to make compile protected function accessible from current context */ - $function = $this->getMethod('checkForUserIdProjectId'); + $function = $this->getMethod('addUserIdProjectIdIfNotInRequest'); $projectFiles = ['projectId' => 1, 'files' => [['filename' => 'project.ino', 'content' =>'']]]; diff --git a/apache-config-2.2 b/apache-config-2.2 new file mode 100644 index 0000000..60dee98 --- /dev/null +++ b/apache-config-2.2 @@ -0,0 +1,9 @@ + + DocumentRoot /var/www + + Options -Indexes FollowSymLinks MultiViews + AllowOverride All + Order allow,deny + Allow from all + + diff --git a/apache-config b/apache-config-2.4 similarity index 100% rename from apache-config rename to apache-config-2.4 diff --git a/scripts/apache_install.sh b/scripts/apache_install.sh old mode 100644 new mode 100755 index 8c5e683..4d68ce8 --- a/scripts/apache_install.sh +++ b/scripts/apache_install.sh @@ -4,7 +4,8 @@ set -e PACKAGENAME=builder -sudo cp /opt/codebender/$PACKAGENAME/apache-config /etc/apache2/sites-available/codebender-$PACKAGENAME +sudo ln -s /opt/codebender/$PACKAGENAME/Symfony/web /var/www/$PACKAGENAME +sudo cp /opt/codebender/$PACKAGENAME/apache-config-2.4 /etc/apache2/sites-available/codebender-$PACKAGENAME cd /etc/apache2/sites-enabled sudo ln -s ../sites-available/codebender-$PACKAGENAME 00-codebender.conf sudo service apache2 restart diff --git a/scripts/install.sh b/scripts/install.sh old mode 100644 new mode 100755 index 19078e2..3ea0f2b --- a/scripts/install.sh +++ b/scripts/install.sh @@ -4,26 +4,25 @@ set -e PACKAGENAME=builder -if [[ "$OSTYPE" == "linux-gnu" ]]; then - echo "Configuring environment for Linux" - # Make sure we have up-to-date stuff - sudo apt-get update - if [[ ! $TRAVIS ]]; then - # Ubuntu Server (on AWS?) lacks UTF-8 for some reason. Give it that - sudo locale-gen en_US.UTF-8 - sudo apt-get install -y php5-intl - fi - # Install dependencies - sudo apt-get install -y apache2 libapache2-mod-php5 php-pear php5-xdebug php5-curl php5-sqlite php5-mysql acl curl git - # Enable Apache configs - sudo a2enmod rewrite - sudo a2enmod alias - # Restart Apache - sudo service apache2 restart -elif [[ "$OSTYPE" == "darwin"* ]]; then - # is there something comparable to this on os x? perhaps Homebrew - echo "Configuring environment for OS X (to be added..)" +if [[ "$OSTYPE" != "linux-gnu" ]]; then + echo "Only Linux environment is supported" fi +echo "Configuring environment for Linux" +# Make sure we have up-to-date stuff +sudo apt-get update +if [[ ! $TRAVIS ]]; then + # Ubuntu Server (on AWS?) lacks UTF-8 for some reason. Give it that + sudo locale-gen en_US.UTF-8 + sudo apt-get install -y php5-intl +fi +# Install dependencies +sudo apt-get install -y apache2 libapache2-mod-php5 php-pear php5-curl php5-sqlite php5-mysql acl curl git +# Enable Apache configs +sudo a2enmod rewrite +sudo a2enmod alias +# Restart Apache +sudo service apache2 restart + if [[ ! $TRAVIS ]]; then @@ -47,23 +46,14 @@ cd /opt/codebender/$PACKAGENAME rm -rf Symfony/app/cache/* rm -rf Symfony/app/logs/* -if [[ "$OSTYPE" == "linux-gnu" ]]; then - - if [[ ! $TRAVIS ]]; then - # Need to create cache and logs directories, as they do not pre-exist in new deployments - mkdir -p `pwd`/Symfony/app/cache/ - mkdir -p `pwd`/Symfony/app/logs/ - - # Set access control for both apache and current user on cache and logs directories - sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs - sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs - fi - -elif [[ "$OSTYPE" == "darwin"* ]]; then +if [[ ! $TRAVIS ]]; then + # Need to create cache and logs directories, as they do not pre-exist in new deployments + mkdir -p `pwd`/Symfony/app/cache/ + mkdir -p `pwd`/Symfony/app/logs/ - HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` - sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs - sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" Symfony/app/cache Symfony/app/logs + # Set access control for both apache and current user on cache and logs directories + sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs + sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx `pwd`/Symfony/app/cache `pwd`/Symfony/app/logs fi cd Symfony diff --git a/scripts/travis_apache_install.sh b/scripts/travis_apache_install.sh new file mode 100755 index 0000000..08635eb --- /dev/null +++ b/scripts/travis_apache_install.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -x +set -e + +PACKAGENAME=builder + +sudo ln -s /opt/codebender/$PACKAGENAME/Symfony/web /var/www/$PACKAGENAME +sudo cp /opt/codebender/$PACKAGENAME/apache-config-2.2 /etc/apache2/sites-available/codebender-$PACKAGENAME +cd /etc/apache2/sites-enabled +sudo ln -s ../sites-available/codebender-$PACKAGENAME 00-codebender.conf +sudo service apache2 restart diff --git a/scripts/travis_install.sh b/scripts/travis_install.sh new file mode 100755 index 0000000..852f039 --- /dev/null +++ b/scripts/travis_install.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -x +set -e + +PACKAGENAME=builder + +echo "Configuring environment for Linux (Ubuntu 12.04)" + +# Make sure we have up-to-date stuff +sudo apt-get update + +# Install dependencies +sudo apt-get install -y apache2 libapache2-mod-php5 php-pear php5-curl php5-sqlite php5-mysql acl curl git +# Enable Apache configs +sudo a2enmod rewrite +sudo a2enmod alias +# Restart Apache +sudo service apache2 restart + +HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` + +sudo mkdir -p /opt/codebender +sudo cp -r . /opt/codebender/$PACKAGENAME +sudo chown -R `whoami`:$HTTPDUSER /opt/codebender/$PACKAGENAME +cd /opt/codebender/$PACKAGENAME + +#Set permissions for app/cache and app/logs + +rm -rf Symfony/app/cache/* +rm -rf Symfony/app/logs/* + +# Need to create cache and logs directories, as they do not pre-exist in new deployments +mkdir -p `pwd`/Symfony/app/cache/ +mkdir -p `pwd`/Symfony/app/logs/ + +cd Symfony + +set +x +cat app/config/parameters.yml.dist | grep -iv "compiler:" | grep -iv "library:" > app/config/parameters.yml +echo " compiler: '$COMPILER_URL'" >> app/config/parameters.yml + +echo " library: '$LIBRARY_URL'" >> app/config/parameters.yml +set -x + + +curl -s http://getcomposer.org/installer | php +php composer.phar install