thewoolleyman / cinabox

Continuous Integration. In a Box!

This URL has Read+Write access

cinabox / setup_ci.rb
e436c5d7 » thewoolleyman 2008-07-21 update readme and change sh... 1 #!/usr/bin/env ruby
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 2
3 class Cinabox
4 def self.setup
5 require 'fileutils'
2cf6ccb3 » thewoolleyman 2008-07-19 postfix 6 require 'socket'
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 7
432e641b » thewoolleyman 2008-07-19 fix package check and reorg 8 # Settings
a03786c5 » thewoolleyman 2009-08-18 use CRUISE_HOME and CRUISE_... 9 cruise_user = ENV['CRUISE_USER'] || ENV['USER']
10 cruise_home = ENV['CRUISE_HOME'] || "#{ENV['HOME']}/ccrb"
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 11 cruise_branch = ENV['CRUISE_BRANCH'] || "git://github.com/thoughtworks/cruisecontrol.rb.git"
12 # cruise_tag = ENV['CRUISE_TAG']
e1311e5f » thewoolleyman 2009-09-16 allow hostname to be set vi... 13 cruise_tag = ENV['CRUISE_TAG']
27881877 » thewoolleyman 2008-07-18 fix dir 14 cinabox_dir = File.expand_path(File.dirname(__FILE__))
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 15 cruise_daemon_template = ENV['CRUISE_DAEMON_TEMPLATE'] || "#{cruise_home}/daemon/cruise"
e1311e5f » thewoolleyman 2009-09-16 allow hostname to be set vi... 16 hostname = ENV['HOSTNAME']
17
18 # set hostname
19 run "sudo echo '#{hostname}' > /etc/hostname" if hostname
27881877 » thewoolleyman 2008-07-18 fix dir 20
432e641b » thewoolleyman 2008-07-19 fix package check and reorg 21 # Build/download dir
22 build_dir = ENV['BUILD_DIR'] || "#{ENV['HOME']}/build"
23 FileUtils.mkdir_p(build_dir)
24
25 # warning - the '--force' option will blow away any existing settings
26 force = ARGV[0] == '--force' ? true : false
27
3176d7ae » thewoolleyman 2009-09-05 gentoo support 28 # Install important packages
db8f3b0f » thewoolleyman 2009-09-16 removing gentoo support fro... 29 run "sudo aptitude install -y subversion" if !((run "dpkg -l subversion", false) =~ /ii subversion/) || force
30 run "sudo aptitude install -y git-core" if !((run "dpkg -l git-core", false) =~ /ii git-core/) || force
31 run "sudo aptitude install -y git-svn" if !((run "dpkg -l git-svn", false) =~ /ii git-svn/) || force
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 32
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 33 # Install cruisecontrol.rb via git and dependencies
a03786c5 » thewoolleyman 2009-08-18 use CRUISE_HOME and CRUISE_... 34 if !File.exist?(cruise_home) || force
35 run "rm -rf #{cruise_home}"
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 36 run "git clone #{cruise_branch} #{cruise_home}"
37 run "cd #{cruise_home} && git checkout -b #{cruise_tag} refs/tags/#{cruise_tag}" if cruise_tag
5edcbbfb » thewoolleyman 2009-08-30 do not attempt to install m... 38 run "sudo gem install --bindir /usr/bin rake rack thin"
39 unless RUBY_VERSION =~ /^1.9/
40 run "sudo gem install --bindir /usr/bin mongrel mongrel_cluster"
41 end
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 42 end
1603ffad » thewoolleyman 2008-07-18 update git 43
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 44 # Always update cruisecontrol.rb
22b902a3 » thewoolleyman 2009-07-22 add support for specifying ... 45 # TODO: disabled for now, it will break if we are on a tag
a03786c5 » thewoolleyman 2009-08-18 use CRUISE_HOME and CRUISE_... 46 # run "cd #{cruise_home} && git pull"
1f322147 » thewoolleyman 2008-07-18 cc -> ccrb 47
4a28e965 » thewoolleyman 2008-08-09 change git url, delete old ... 48 # Write out init script daemon based on template
841c21db » thewoolleyman 2008-07-26 update daemon 49 if !File.exist?('/etc/init.d/cruise') || force
33967f74 » thewoolleyman 2009-08-18 delete init script if it al... 50 run "sudo rm -f /etc/init.d/cruise"
276e3321 » thewoolleyman 2008-08-09 changing daemon handling ba... 51 run "sudo touch /etc/init.d/cruise"
a03786c5 » thewoolleyman 2009-08-18 use CRUISE_HOME and CRUISE_... 52 run "sudo chown #{cruise_user} /etc/init.d/cruise"
f533839a » thewoolleyman 2008-08-09 fix daemon perms 53 run "chmod a+x /etc/init.d/cruise"
4e6c5ab1 » thewoolleyman 2009-08-18 change remaining CCRB_ vars... 54 File.open(cruise_daemon_template, "r") do |input|
276e3321 » thewoolleyman 2008-08-09 changing daemon handling ba... 55 File.open("/etc/init.d/cruise", "w") do |output|
56 input.each_line do |line|
a03786c5 » thewoolleyman 2009-08-18 use CRUISE_HOME and CRUISE_... 57 line = "CRUISE_USER = '#{cruise_user}'\n" if line =~ /CRUISE_USER =/
58 line = "CRUISE_HOME = '#{cruise_home}'\n" if line =~ /CRUISE_HOME =/
276e3321 » thewoolleyman 2008-08-09 changing daemon handling ba... 59 output.print(line)
60 end
61 end
62 end
29a201cb » thewoolleyman 2008-07-18 more granular repeatability 63 end
64
0f4d8356 » thewoolleyman 2008-07-19 comments 65 # Enable on system reboot
2b9ab6ed » thewoolleyman 2008-07-21 fix logic error with force ... 66 if !File.exist?('/etc/rc3.d/S20cruise') || force
db8f3b0f » thewoolleyman 2009-09-16 removing gentoo support fro... 67 run "sudo update-rc.d -f cruise defaults"
60f612ac » thewoolleyman 2008-07-18 more cleanup, add daemon st... 68 end
0f4d8356 » thewoolleyman 2008-07-19 comments 69
2cf6ccb3 » thewoolleyman 2008-07-19 postfix 70 # Install and configure postfix
db8f3b0f » thewoolleyman 2009-09-16 removing gentoo support fro... 71 if !((run "dpkg -l postfix", false) =~ /ii postfix/) || force
72 run "sudo aptitude install debconf-utils -y"
73 run "echo 'postfix\tpostfix/mailname\tstring\t#{Socket.gethostbyname(Socket.gethostname)[0]}' > #{build_dir}/postfix-selections"
74 run "echo 'postfix\tpostfix/main_mailer_type\tselect\tInternet Site' >> #{build_dir}/postfix-selections"
75 run "sudo debconf-set-selections #{build_dir}/postfix-selections"
76 run "sudo aptitude install postfix -y"
2cf6ccb3 » thewoolleyman 2008-07-19 postfix 77 end
55526000 » thewoolleyman 2009-06-25 start cruise daemon after s... 78
43d2e12a » thewoolleyman 2009-09-05 use proper command to searc... 79 # TODO: when run via 'su -l ci' from another user, this doesn't always drop a pid file, even though it starts
415a32c5 » thewoolleyman 2009-08-27 can't fix bug with pid file... 80 run "/etc/init.d/cruise start" unless ENV['NO_DAEMON_START']
61416eef » thewoolleyman 2008-07-21 better failure and success ... 81
2b9ab6ed » thewoolleyman 2008-07-21 fix logic error with force ... 82 print "\n\nSetup script completed.\n"
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 83 end
32096535 » thewoolleyman 2008-07-19 adding command output 84
4053dced » thewoolleyman 2008-07-21 fix logic 85 def self.run(cmd, fail_on_error = true)
32096535 » thewoolleyman 2008-07-19 adding command output 86 puts "Running command: #{cmd}"
2113de5c » thewoolleyman 2008-07-19 adding command output 87 output = `#{cmd}`
88 puts output
61416eef » thewoolleyman 2008-07-21 better failure and success ... 89 if !$?.success? and fail_on_error
2b9ab6ed » thewoolleyman 2008-07-21 fix logic error with force ... 90 print "\n\nCommand failed: #{cmd}\n"
61416eef » thewoolleyman 2008-07-21 better failure and success ... 91 exit $?.to_i
92 end
2113de5c » thewoolleyman 2008-07-19 adding command output 93 output
32096535 » thewoolleyman 2008-07-19 adding command output 94 end
15dee89f » thewoolleyman 2008-06-22 initial ccrb checkin 95 end
96
97 Cinabox.setup