Integrity Continuous Integration

Integrity is a Continuous Integration Tool where we can run our tests (Rspec or Cucumber) to check whether the application is running fine or not.  Whenever there is a commit it will run the test cases and checks whether the specs are passed or failed.

Installation

For basic instructions on setting up the Integrity go through http://integrityapp.com/  The post below states errors you may encounter and their solution. Following steps are mentioned for setting up the integrity in the url given above:

$ gem install bundler
$ git clone git://github.com/integrity/integrity
$ cd integrity
$ git checkout -b deploy v22
$ bundle install
$ bundle lock
$ rake db

At the last step i.e. “rake db” – you may get error for require “.bundle/environment” under init.rb

Below is full error trace :

** Invoke db (first_time)
** Execute db
rake aborted!
no such file to load -- .bundle/environment
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
./init.rb:3
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
/home/amit/integrity/Rakefile:25
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Comment that line  i.e. require “.bundle/environment” and add following lines. The code in init.rb should look like this:

begin
 require File.expand_path("../.bundle/environment", __FILE__)
 rescue LoadError
 require "rubygems"
 require "bundler"
 Bundler.setup
end

Once it is added then run “rake db”.
Now as mentioned in the document run the integrity server by the command

$ bundle exec rackup

In the browser type the url as “http://0.0.0.0:9292” and the Integrity app will open.

Project Creation

Initially there will be no projects created. So lets create a project by clicking on the link.
Project creation page will open:

1: Enter the project name : Enter the name of the project

2: The github url from which we clone the project i.e.
git@github.com:amit/test.git

3: Enter branch to track as “master”.If there are any other branches which you want to run the Integrity then enter that branch

4: Enter build script as the script which you want to run for e.g. rake test
Here if you have already written a script then add that script

Handling database

Before going further you should know that Integrity is dumb 🙂 It takes a repository URL and a command to run in a working copy. It then reports success or failure depending on the exit status of the command. It does not create a database so we have to manually create a database for the application for which you want to run the integrity.

For this create a rake task in the project and enter below code:

 namespace :ci do

 # Be sure you check-in the config/database.yml.ci file which contains the same database details as for the project.
 task :copy_yml do
   system("cp config/database.yml.ci config/database.yml")
 end

 # Command for running the specs
 task :spec do
   system("bundle exec rspec spec/")
 end

 # Running the entire rake task
 desc "Prepare for CI and run entire test suite"
 task :build => ['ci:copy_yml', 'db:create', 'db:migrate', 'ci:spec'] do
 end

Once it is done you can mention the script as “rake ci:build” in the script field in the project creation page
Click on Update project. Now the project is created. Now click on Manual build. It will run the build.Now what happens here is it goes to the git url which we have specified, fetches the latest commit and clones the project.
Yes! For every build we called, it clones the project – this is the drawback of Integrity because it can eat a lot of space for every build. After running the build you can see the output in the UI.

NOTE: Initially when I ran the build i got an error which says

 Build 94fbea34a77d7b78a5572e82a3a490e556abe7b2 exited with false got

After searching i found that some of the code need to be replaced.

So in the integrity/lib/builder.rb do the following changes:

# integrity/lib/builder.rb
# Remove / comment these functions out!
def run
 cmd = "(cd #{repo.directory} && #{@build.project.command} 2>&1)"
 IO.popen(cmd, "r") { |io| @output = io.read }
 @status = $?.success?
end

def repo
 @repo ||= Repository.new(
 @build.id, @build.project.uri, @build.project.branch, commit
 )
end

def commit
 @build.commit.identifier
end

And replace with the below code:

def run
 cmd = "(cd #{repo.directory} && RUBYOPT=#{pre_bundler_rubyopt} PATH=#{pre_bundler_path} && #{@build.project.command} 2>&1)"
 Integrity.log cmd

 # cmd = "(cd #{repo.directory} && #{@build.project.command} 2>&1)"
 IO.popen(cmd, "r") { |io| @output = io.read }
 @status = $?.success?
end

def repo
 @repo ||= Repository.new(
 @build.id, @build.project.uri, @build.project.branch, commit
 )
end

def commit
 @build.commit.identifier
end

private
def pre_bundler_path
 ENV['PATH'] && ENV["PATH"].split(":").reject { |path| path.include?("vendor") }.join(":")
end

def pre_bundler_rubyopt
 path = ENV['RUBYOPT']
 #ENV['RUBYOPT'] && ENV["RUBYOPT"].split.reject { |opt| opt.include?("vendor") }.join(" ")
 path = path.gsub(' -rbundler', '/bundler')
 path && path.split.reject { |opt| opt.include?("vendor") }.join(" ")
end

Restart the server and the build will run successfully!

Email Notifications

After every build we can get email notification. Configure like this:

# Gemfile
gem "sinatra-ditties"
# init.rb
require 'integrity/notifer/email"

$ bundle install

Start the server.  Now in the UI click on the Edit button beside the project,you will see email configurations.  Enter the desired settings and click on update and again run the build.  Once the build is complete you will get email notification.

Post commit hook configuration

Till now we are running build manually. Now we want to run the build automatically after every commit has been done, you need to add the post-commit hook. For that go to the desired github repo

  • Click on the admin link
  • Below click on the Service hooks-> Post receive Url
  • In the textfield,add the url as : http://(integrity-url):9292/(project-name)/builds

Once it is added click on update settings and click on test hook

After clicking the build should be started. Now do a dummy commit and check whether the build is getting running automatically or not. It should run! 🙂  You can run Integrity for number of projects.

Deploying Integrity on Heroku

The Integrity installation for heroku deployment does mention that need to uncomment the postgres gem in Gemfile and do the standard ‘git push heroku master’.

Once all is done run heroku open and in the browser you will see integrity running 🙂

Following is the link where you can have a look at the Integrity app in heroku

http://gentle-summer-888.heroku.com/

Make sure to deploy your github tokens. More detailed instructions at http://integrityapp.com/

 $ c.github ENV["GITHUB_TOKEN"] || "TOKEN"
 $ heroku config:add GITHUB_TOKEN=secret

Issues:

  1. The problem with Integrity running on heroku is it does not run builds for private repositories (Update: This should work now – http://comments.gmane.org/gmane.comp.lang.ruby.rails.heroku/5931.)
  2. For every build integrity will clone the whole project which will gradually eat up the spaces.

Let me know if you have any doubts. I would love to help you set this up / fix some issues.

Feedback is more than welcome — after all, this is all about continuous integration!

2 thoughts on “Integrity Continuous Integration

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.