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

  • Tutorial

I’ll immediately intrigue: as a result, we get a bunch of free private git repository on Bitbucket and a free * Continious Integration server (SAAS), which will collect the project and run all the tests after each push.
* - a 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



  • Install symfony2 and dependencies via composer
  • Run PHPUnit Tests
  • Run Behat Tests


Implementation



After registration, create a new project, synchronize with Bitbucket and in the project settings we will write the commands necessary for assembly.
There are predefined templates, after choosing PHP, our command set becomes like this:

# 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 also needed the GeoIP extension, after a short discussion with technical support everything was fine, 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, it is worth noting, is very good. They helped with all the problems and answered all the questions.

Database



For Behat tests, you need to deploy the database, import test data via Fixtures, and run the tests themselves.
Codeship.io supports MySQL, MongoDB, PostgreSQL, SQLite (pleasantly surprised by the presence of Elasticsearch out of the box). In our case, we work with MySQL, 2 databases have already been created automatically - development and test.
The password and 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, there must be a SYMFONY__ prefix for each variable.

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 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 it, the MySQL configuration is over. Now create the circuit and run fixtures to import the test data:

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


Well, we launch the built-in web server, the launch example is taken from the documentation and only the parameter for changing 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”, we 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


If your build failed, an email notification will automatically come up, which looks like this:


Also a notification comes after the build is restored.
In addition, there is integration with many services:

(picture from codeship.io)

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

What I liked about codeship.io:
  • Ability to test a free private repository. Killer feature
  • Great tech support
  • Detailed documentation
  • ElasticSearch support and easy configuration in builds.


What did not like :
  • Design. The one in the account after login. In my opinion it is terrible.
  • The limit is 100 builds per month, although thanks for the free subscription for that too.


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

Also popular now: