continuous integration for ruby on rails
play

Continuous Integration for Ruby on Rails Ross Niemi ThoughtWorks, - PowerPoint PPT Presentation

Continuous Integration for Ruby on Rails Ross Niemi ThoughtWorks, Inc. Email: rniemi@thoughtworks.com Blog: http://rossniemi.wordpress.com March 12th, 2007 Agenda What is Continuous Integration (CI)? What CI tools are currently


  1. Continuous Integration for Ruby on Rails Ross Niemi ThoughtWorks, Inc. Email: rniemi@thoughtworks.com Blog: http://rossniemi.wordpress.com March 12th, 2007

  2. Agenda • What is Continuous Integration (CI)? • What CI tools are currently available for Ruby and Ruby on Rails (RoR)? • How do these tools compare? • Demo • Questions

  3. Agile Software Development • Agile Manifesto – Individuals and interactions over processes and tools – Working software over comprehensive documentation – Customer collaboration over contract negotiation – Responding to change over following a plan • Continuous Integration helps us to deliver working software

  4. Continuous Integration • “… is a software development practice where members of a team integrate their work frequently…” • “Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible” - Martin Fowler

  5. Before we continue… • It is important to note that Continuous Integration: – IS NOT a tool or product – IT IS a practice or philosophy that a team has to buy into • Recall: Individuals and interactions over processes and tools • Tools can be used to help automate Continuous Integration “Continuous Integration is an Attitude, Not a Tool” - James Shore

  6. Early Days • Check-in “token” – Developer wanting to check in code into the repository must acquire the “token” – Only one person can check in at a time – The same person would then check out the code on a different machine and run the build in a clean environment – If the build “breaks”, the offender fixes it on their machine and tries the verification step again – Once the build passes, the “token” is returned so someone else could perform a check in – Very serial process, time consuming

  7. Early Days • Cron / Scheduler Jobs – An attempt to automate the verification build – Schedule builds to happen during set times • Nightly or Daily Builds (quiet times) • Depending on the length of the build, you typically would want to increase the build frequency – The greater the time between scheduled builds • The less useful the feedback from the build would be • The more difficult debugging a broken build would be

  8. Present Day • CI Tools are responsible for orchestrating the verification build – Detects a change in the code repository – Update its working copy – Runs the build and executes tests – Notifies interested parties of success or failure • The repetition of these steps is known as a build cycle or build loop • Typically implemented as a server / daemon

  9. CI Tool Realizations • By automating the verification build: – The verification step is done for the committer automatically – Verification builds can be done more often • For example, after every checkin – The tool can notify the developer(s) of a broken or successful build as soon as the verification build finishes – Shorter verification build cycles means: • The developer can check in code more often (XP) • Faster feedback will lead to greater productive

  10. Typical Architecture

  11. CI for Ruby On Rails • Jay Field � s Poor Man � s CI • Continuous Builder • Cerberus • CruiseControl with CI_Reporter • CruiseControl.rb

  12. Jay Field � s Poor Man � s CI • If using Subversion, use a post-commit hook to fire off a build • Pass a revision number as an argument – Use number to create output directories for running build • If on a Mac, use Growl to send a status message to developer workstation • http://jayfields.blogspot.com/2006/07/ruby- continuous-integration.html

  13. Continuous Builder • Simple Rails plugin written by DHH • Add a Subversion post-commit hook to build the latest revision and notify the developer on success / failure by: – Email – Campfire • http://dev.rubyonrails.org/browser/plugins/con tinuous_builder

  14. Cerberus • Designed to be a light-weight CI solution with a small memory footprint – Loaded into memory and executed only when needed • Similar to previous approaches, but offers support for managing multiple projects – Command line – YML • http://cerberus.rubyforge.org/

  15. Commands # Add application directory to monitor cerberus add directory APPLICATION_NAME= application RECIPIENTS= email address, … # Add application SVN repository to monitor cerberus add subversion_url APPLICATION_NAME= application RECIPIENTS= email address, … # List of active projects cerberus list # Build a single or all applications cerberus build application cerberus buildall # Command line help cerberus --help

  16. Files and Directories # Default home $CERBERUS_HOME=~/.cerberus # Server artifacts ~/.cerberus/config.yml ~/.cerberus/error.log # Project artifacts ~/.cerberus/config/ application .yml ~/.cerberus/work/ application /logs - timestamped build logs /Status.log - status of last build

  17. Build Loop • Cerberus will check if there were any changes to application directory or Subversion repository – Build only if there were • Since build and buildall are one time shots, you will either need to setup Cerberus with: – Cron (polling) – Subversion post-commit hook (trigger)

  18. CruiseControl • The defacto standard for Continuous Integration in the Java world • CruiseControl 2.6 has direct support for Rake – Leverage existing plugins • Source Code Management (SCM) systems • Publishers / Notifiers • Using CI Reporter with CruiseControl will allow for reporting on test failure • http://cruisecontrol.sourceforge.net

  19. Commands cruise_dir /cruisecontrol.sh cruise_dir /cruisecontrol.bat • Windows service now available

  20. Files and Directories # Server / Project configuration cruise_dir /config.xml # Project artifacts - can override locations cruise_dir / project .ser cruise_dir /projects/ project cruise_dir /logs/ project cruise_dir /artifacts/ project

  21. Configuration • CruiseControl build projects are defined in cruise_dir /config.xml • Each build project has the following sections: – Bootstrappers are operations done before the build takes place, regardless if a build is necessary or not – ModificationSet is scheduled to poll to see if change in the code repository occurred – Schedule is a reoccurring event used to perform a build provided that there are modifications – Publishers distribute the results of a build – Log is used to report on the build execution

  22. CI Reporter • Can use with existing CI solutions that understand JUnit XML – CruiseControl, Bamboo, etc. • Support for Test::Unit or RSpec • http://svn.caldersphere.net/svn/main/ci_ reporter/

  23. Files and Directories • Modify Rakefile require 'rubygems' gem 'ci_reporter’ # use the following if using RSpec require 'ci/reporter/rake/rspec’ # use the following if using Test::Unit require 'ci/reporter/rake/test_unit’ • Make ci:setup:<rspec|testunit> a dependency of your test tasks

  24. CruiseControl.rb • CruiseControl for Ruby and RoR • Written from the ground up on Rails • http://cruisecontrolrb.rubyforge.org/

  25. Commands # Start the web server ./cruise start [options ] --port=port --binding=ip --daemon --environment=test|development|production # Add application SVN repository to monitor ./cruise add your_project --url subversion-url [--username username --password password] # Build your_project ./cruise build your_project [--trace ] # Command line help ./cruise help [command ]

  26. Files and Directories # Server artifacts cruise_dir /config/site_config.rb # Project artifacts cruise_dir /projects/ your_project /work /build- rev /build.log /build_status. status /changeset.log /cruise_config.rb

  27. Build Loop • Assumption: – Rails application built by Rake • Alternatively : – Use Rake to build other applications • Ruby, Java – Could call a shell script

  28. Rake Execution • Loads all Rake files from cruise_dir/tasks and then the Rakefile of your_project • The cc:build task is invoked and looks for all other Rake tasks defined in your_project – cruise_dir /tasks/cc_build.rake

  29. Rake Execution Note : project.rake_task and project.build_command both cannot be set

  30. Build Scheduling • Specify a polling interval in the cruise_config.rb – project.scheduler.polling_interval = 5.minutes • Provide your own custom scheduler – project.scheduler = MyCustomScheduler.new(project)

  31. Build Artifacts • Artifacts are visible via dashboard • CC_BUILD_ARTIFACTS environment variable is set by CruiseControl.rb – Make sure your Rakefile task writes to this directory or in a subdirectory • Coverage reports, build products, etc.

  32. Comparison Matrix • Just the facts, please – http://rossniemi.wordpress.com/docs

  33. Slides make me sleepy… • Where is my Demo!

  34. Questions?

Recommend


More recommend