⬆️ ⬇️

Codeship.io: a free CI server for a private Github / Bitbucket repository



Immediately I intrigue: as a result, we will get a bunch of free private git repository on Bitbucket and a free * Continious Integration server (SAAS) that will build the project and run all the tests after each push.

* - free subscription allows you to test 5 private repositories and a maximum of 100 builds per month.



This is enough for my personal project.



I will give an example for PHP, a project on Symfony2, but this service also supports Ruby, Node.js, Python .

')



Task









Implementation





After registration, we create a new project, synchronize it with Bitbucket, and in the project settings we will write the commands necessary for the assembly.

There are predefined templates, after selecting PHP, our command set becomes:



# Set php version through phpenv. 5.3, 5.4 and 5.5 available phpenv local 5.5 # Install extensions through Pecl # pecl install memcache # Install dependencies through Composer composer install --prefer-source --no-interaction 




I still needed GeoIP extension, after a brief discussion with technical support everything was perfectly established, now the list of commands began to look like this:



Setup Commands
 # Set php version through phpenv. 5.3, 5.4 and 5.5 available phpenv local 5.5 # Install extensions through Pecl pecl install -f geoip wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz gunzip GeoLiteCity.dat.gz cp ./GeoLiteCity.dat ./GeoIPCity.dat #  ,        echo "geoip.custom_directory=/home/rof/clone" >> /home/rof/.phpenv/versions/5.5/etc/php.ini # Install dependencies through Composer composer install --prefer-source --no-interaction 






Technical support is worth noting very good. Helped with all the problems and answered all the questions.



Database





For Behat tests, you need to deploy the database, import test data through Fixtures, and run the tests themselves.

Codeship.io supports MySQL, MongoDB, PostgreSQL, SQLite (I was pleasantly surprised by the presence of Elasticsearch out of the box). In our case, we are working with MySQL, two databases have already been created: development and test.

The password and the user are stored in the environment variables MYSQL_PASSWORD, MYSQL_USER, respectively.



In Symfony2, environment variables can be used as parameters in configuration files, but using some rules , namely, the SYMFONY__ prefix of each variable should be present.



Change config_test.yml to use environment variables as user, password, and database name:



 // app/config/config_test.yml ... doctrine: dbal: dbname: "%test.database.name%" driver: pdo_mysql user: "%test.database.user%" password: "%test.database.password%" ... 




And we define these same variables in the “Setup Commands” in the settings of our project:

 export SYMFONY__TEST__DATABASE__USER=$MYSQL_USER export SYMFONY__TEST__DATABASE__PASSWORD=$MYSQL_PASSWORD export SYMFONY__TEST__DATABASE__NAME=test 




That's all, MySQL configuration is over. Now we will create a schema and run fixtures to import test data:



 php app/console doctrine:schema:update --force --env=test php app/console doctrine:fixtures:load --no-interaction --env=test 




Well, we run the embedded web server, an example of the launch is taken from the documentation and only the parameter to change the document root is added (in Symfony2, this is the web folder):

 nohup bash -c "php -S 127.0.0.1:8000 -t web/ 2>&1 &" && sleep 1; cat nohup.out 




Tests





Now you can run all our tests. To do this, there is a special block “Modify your Test Commands”, enter the commands there:

 phpunit -c app ./bin/behat "@AppApiBundle/api.feature" --profile=api --no-paths ./bin/behat "@AppCoreBundle/core.feature" --profile=core --no-paths 




When running the tests, I had a problem because of xDebug: “Fatal error: Maximum function nesting level of '100' reached '

Let's increase this parameter by changing php.ini in “Setup Commands”:



 echo "xdebug.max_nesting_level=200" >> /home/rof/.phpenv/versions/5.5/etc/php.ini 




In case your build was completed with an error, an email notification will automatically arrive, which looks like this:





Also comes a notification after the build is restored.

In addition, there is integration with a variety of services:



(picture from codeship.io)



This service has a lot of chips, for example, you can immediately deploy a successful build.



What did you like about codeship.io:





What did not like :





If you know any other SaaS services where you can test private repositories for free, please share in the comments.

Source: https://habr.com/ru/post/242685/



All Articles