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

continuous integration for ruby on rails
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Continuous Integration for Ruby on Rails

Ross Niemi ThoughtWorks, Inc. Email: rniemi@thoughtworks.com Blog: http://rossniemi.wordpress.com March 12th, 2007

slide-2
SLIDE 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
slide-3
SLIDE 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

slide-4
SLIDE 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
slide-5
SLIDE 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

  • James Shore

“Continuous Integration is an Attitude, Not a Tool”

slide-6
SLIDE 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

slide-7
SLIDE 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
slide-8
SLIDE 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
slide-9
SLIDE 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
slide-10
SLIDE 10

Typical Architecture

slide-11
SLIDE 11

CI for Ruby On Rails

  • Jay Fields Poor Mans CI
  • Continuous Builder
  • Cerberus
  • CruiseControl with CI_Reporter
  • CruiseControl.rb
slide-12
SLIDE 12

Jay Fields Poor Mans 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

slide-13
SLIDE 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

slide-14
SLIDE 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/
slide-15
SLIDE 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

slide-16
SLIDE 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

slide-17
SLIDE 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)

slide-18
SLIDE 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
slide-19
SLIDE 19

Commands

cruise_dir/cruisecontrol.sh cruise_dir/cruisecontrol.bat

  • Windows service now available
slide-20
SLIDE 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

slide-21
SLIDE 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

slide-22
SLIDE 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/

slide-23
SLIDE 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

slide-24
SLIDE 24

CruiseControl.rb

  • CruiseControl for Ruby and RoR
  • Written from the ground up on Rails
  • http://cruisecontrolrb.rubyforge.org/
slide-25
SLIDE 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 ]

slide-26
SLIDE 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

slide-27
SLIDE 27

Build Loop

  • Assumption:

– Rails application built by Rake

  • Alternatively:

– Use Rake to build other applications

  • Ruby, Java

– Could call a shell script

slide-28
SLIDE 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

slide-29
SLIDE 29

Rake Execution

Note: project.rake_task and project.build_command both cannot be set

slide-30
SLIDE 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)

slide-31
SLIDE 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.
slide-32
SLIDE 32

Comparison Matrix

  • Just the facts, please

– http://rossniemi.wordpress.com/docs

slide-33
SLIDE 33

Slides make me sleepy…

  • Where is my Demo!
slide-34
SLIDE 34

Questions?