bunchr 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Bunchr::Software.new do |t|
2
+ t.name = 'sensu'
3
+
4
+ install_prefix = "#{Bunchr.install_dir}"
5
+
6
+ # use the gem installed by the ruby.rake recipe in <Bunchr.install_dir>/embedded/bin
7
+ gem_bin = "#{install_prefix}/embedded/bin/gem"
8
+
9
+ t.download_commands << "git clone git://github.com/sensu/sensu.git"
10
+
11
+ t.build_commands << "rm -f sensu-*.gem"
12
+ t.build_commands << "#{gem_bin} build sensu.gemspec"
13
+
14
+ t.install_commands << "#{gem_bin} install --no-ri --no-rdoc \
15
+ sensu-*.gem"
16
+
17
+ CLEAN << install_prefix
18
+ end
@@ -0,0 +1,17 @@
1
+ Bunchr::Software.new do |t|
2
+ t.name = 'sensu_bin_stubs'
3
+
4
+ bin_dir = "#{Bunchr.install_dir}/bin"
5
+
6
+ # build and install commands run from t.work_dir. In this case, our
7
+ # files are located in the same dir as the Rakefile.
8
+ t.work_dir = Dir.pwd
9
+
10
+ t.install_commands << "rm -rf #{bin_dir}"
11
+ t.install_commands << "mkdir -p #{bin_dir}"
12
+
13
+ t.install_commands << "ln -s ../embedded/bin/sensu-api #{bin_dir}/sensu-api"
14
+ t.install_commands << "ln -s ../embedded/bin/sensu-client #{bin_dir}/sensu-client"
15
+ t.install_commands << "ln -s ../embedded/bin/sensu-server #{bin_dir}/sensu-server"
16
+ t.install_commands << "ln -s ../embedded/bin/sensu-dashboard #{bin_dir}/sensu-dashboard"
17
+ end
@@ -0,0 +1,30 @@
1
+ Bunchr::Software.new do |t|
2
+ t.name = 'sensu_configs'
3
+
4
+ # build and install commands run from t.work_dir. In this case, our
5
+ # files are located in the same dir as the Rakefile.
6
+ t.work_dir = Dir.pwd
7
+
8
+ t.install_commands << "rm -rf /etc/sensu"
9
+ t.install_commands << "rm -rf /etc/init.d/sensu-*"
10
+ t.install_commands << "rm -rf /usr/share/sensu"
11
+ t.install_commands << "rm -rf /var/log/sensu"
12
+
13
+ t.install_commands << "cp -rf ./sensu_configs/sensu /etc/sensu"
14
+ t.install_commands << "cp -f ./sensu_configs/logrotate.d/sensu /etc/logrotate.d/sensu"
15
+
16
+ t.install_commands << "cp -f ./sensu_configs/init.d/sensu-api /etc/init.d/sensu-api"
17
+ t.install_commands << "cp -f ./sensu_configs/init.d/sensu-server /etc/init.d/sensu-server"
18
+ t.install_commands << "cp -f ./sensu_configs/init.d/sensu-client /etc/init.d/sensu-client"
19
+ t.install_commands << "cp -f ./sensu_configs/init.d/sensu-dashboard /etc/init.d/sensu-dashboard"
20
+
21
+ t.install_commands << "mkdir -p /usr/share/sensu/upstart"
22
+ t.install_commands << "cp -f ./sensu_configs/init/*.conf /usr/share/sensu/upstart/"
23
+
24
+ t.install_commands << "mkdir /var/log/sensu"
25
+
26
+ CLEAN << "/var/log/sensu"
27
+ CLEAN << "/etc/sensu"
28
+ CLEAN << "/etc/init.d/sensu-*"
29
+ CLEAN << "/usr/share/sensu"
30
+ end
@@ -0,0 +1,17 @@
1
+ Bunchr::Software.new do |t|
2
+ t.name = 'sensu_dashboard'
3
+
4
+ install_prefix = "#{Bunchr.install_dir}"
5
+ # use the gem installed by the ruby.rake recipe in <Bunchr.install_dir>/embedded/bin
6
+ gem_bin = "#{install_prefix}/embedded/bin/gem"
7
+
8
+ t.download_commands << "git clone git://github.com/sensu/sensu-dashboard.git"
9
+
10
+ t.work_dir = 'sensu-dashboard'
11
+
12
+ t.build_commands << "rm -f sensu-dashboard-*.gem"
13
+ t.build_commands << "#{gem_bin} build sensu-dashboard.gemspec"
14
+
15
+ t.install_commands << "#{gem_bin} install --no-ri --no-rdoc \
16
+ sensu-dashboard-*.gem"
17
+ end
@@ -0,0 +1,32 @@
1
+ Bunchr::Software.new do |t|
2
+ t.name = 'zlib'
3
+ t.version = '1.2.6'
4
+
5
+ install_prefix = "#{Bunchr.install_dir}/embedded"
6
+
7
+ t.download_commands << "curl -O http://zlib.net/zlib-1.2.6.tar.gz"
8
+ t.download_commands << "tar xfvz zlib-1.2.6.tar.gz"
9
+
10
+ os = t.ohai['os']
11
+ arch = t.ohai['kernel']['machine']
12
+
13
+ if os == 'darwin' && arch == 'x86_64'
14
+ t.build_environment['LDFLAGS'] = "-R#{install_prefix}/lib -L#{install_prefix}/lib -I#{install_prefix}/include"
15
+ t.build_environment['CFLAGS'] = "-I#{install_prefix}/include -L#{install_prefix}/lib"
16
+ elsif os == 'linux'
17
+ t.build_environment['LDFLAGS'] = "-Wl,-rpath #{install_prefix}/lib -L#{install_prefix}/lib -I#{install_prefix}/include"
18
+ t.build_environment['CFLAGS'] = "-I#{install_prefix}/include -L#{install_prefix}/lib"
19
+ end
20
+
21
+ # gcc will error if the lib dir doesn't exist, at least on some linux platforms
22
+ unless File.directory?("#{install_prefix}/lib")
23
+ t.build_commands << "mkdir #{install_prefix}/lib"
24
+ end
25
+
26
+ t.build_commands << "./configure --prefix=#{install_prefix}"
27
+ t.build_commands << "make"
28
+
29
+ t.install_commands << "make install"
30
+
31
+ CLEAN << install_prefix
32
+ end
@@ -0,0 +1,18 @@
1
+ require 'logger'
2
+
3
+ module Bunchr
4
+ class Logger
5
+
6
+ @@log = nil
7
+
8
+ def self.logger()
9
+ if @@log.nil?
10
+ @@log ||= ::Logger.new(STDOUT)
11
+ @@log.level = ENV['BUNCHR_DEBUG'] ? ::Logger::DEBUG : ::Logger::INFO
12
+ # @@log.level = ::Logger::DEBUG
13
+ end
14
+ @@log
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'ohai'
2
+
3
+ module Bunchr
4
+ class Ohai
5
+
6
+ @@ohai = nil
7
+
8
+ def self.ohai
9
+ if @@ohai.nil?
10
+ @@ohai ||= ::Ohai::System.new
11
+ @@ohai.require_plugin('os')
12
+ @@ohai.require_plugin('platform')
13
+ end
14
+ @@ohai
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,176 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/clean'
4
+ require 'bunchr/utils'
5
+
6
+ module Bunchr
7
+
8
+ class Packages < ::Rake::TaskLib
9
+ include ::Bunchr::Utils
10
+
11
+ # only attempt to build .rpm's on these platforms (as reported by
12
+ # ohai.platform)
13
+ RPM_PLATFORMS = %w[centos redhat fedora scientific]
14
+
15
+ # only attempt to build .deb's on these platforms (as reported by
16
+ # ohai.platform)
17
+ DEB_PLATFORMS = %w[debian ubuntu]
18
+
19
+ attr_accessor :name, :version, :iteration, :license, :vendor, :url, :category
20
+ attr_accessor :description
21
+ attr_accessor :files, :config_files, :scripts
22
+
23
+ def initialize
24
+ @name = nil
25
+ @version = nil
26
+ @iteration = nil
27
+ @arch = ohai['kernel']['machine']
28
+ @license = nil
29
+ @vendor = nil
30
+ @category = nil
31
+ @url = nil
32
+ @description = nil
33
+ @files = []
34
+ @config_files = []
35
+ @scripts = {}
36
+ yield self if block_given?
37
+ define unless name.nil? or version.nil?
38
+ end
39
+
40
+ #
41
+ # returns the current architecture. Convert some architectures for the
42
+ # underlying packaging systems, such as i686 to i386.
43
+ def arch
44
+ case @arch
45
+ when 'i686', 'i386'
46
+ 'i386'
47
+ else
48
+ @arch
49
+ end
50
+ end
51
+
52
+ # explicitly set @arch to `a`
53
+ def arch=(a)
54
+ @arch = a
55
+ end
56
+
57
+ def define
58
+ logger.debug "Defining tasks for package:#{name} #{version}"
59
+
60
+ namespace 'packages' do
61
+ namespace name do
62
+ define_build_tarball
63
+ define_build_rpm
64
+ define_build_deb
65
+ # TODO-future: build solaris pkgs, windows too?!
66
+
67
+ define_build_all
68
+
69
+ task :done => "#{name}:build"
70
+ task :default => "#{name}:done"
71
+ end
72
+ desc "Create bunchr packages for #{name} #{version}-#{iteration}"
73
+ task name => "#{name}:default"
74
+ end
75
+ end
76
+
77
+ def define_build_tarball
78
+ tarball_name = "#{name}-#{version}-#{iteration}-#{arch}.tar.gz"
79
+
80
+ desc "Build tarball: #{tarball_name}"
81
+ task :build_tarball do
82
+
83
+ logger.info "Building tarball '#{tarball_name}'"
84
+
85
+ files_str = files.join(' ') + ' ' + config_files.join(' ')
86
+ sh "tar czf #{tarball_name} #{files_str}"
87
+ end
88
+ end
89
+
90
+ def define_build_rpm
91
+ desc "Build RPM: #{name}-#{version}-#{iteration}-#{arch}"
92
+ task :build_rpm do
93
+
94
+ if RPM_PLATFORMS.include? ohai.platform
95
+ logger.info "Building RPM '#{name}-#{version}-#{iteration}-#{arch}'"
96
+
97
+ sh "fpm -s dir -t rpm -a #{arch} -n #{name} -v #{version} \
98
+ --iteration #{iteration} \
99
+ --url '#{url}' \
100
+ --description '#{description}' \
101
+ --license '#{license}' \
102
+ --vendor '#{vendor}' \
103
+ --category '#{category}' \
104
+ #{fpm_scripts_args} \
105
+ #{fpm_config_files_args} \
106
+ #{config_files.join(' ')} \
107
+ #{files.join(' ')}"
108
+
109
+ logger.info "RPM built."
110
+ else
111
+ logger.info "Not building RPM, platform [#{ohai.platform}] does not support it."
112
+ end
113
+
114
+ end
115
+ end
116
+
117
+ def define_build_deb
118
+ desc "Build deb: #{name}-#{version}-#{iteration}-#{arch}"
119
+ task :build_deb do
120
+
121
+ if DEB_PLATFORMS.include? ohai.platform
122
+ logger.info "Building DEB '#{name}-#{version}-#{iteration}-#{arch}'"
123
+
124
+ sh "fpm -s dir -t deb -a #{arch} -n #{name} -v #{version} \
125
+ --iteration #{iteration} \
126
+ --url '#{url}' \
127
+ --description '#{description}' \
128
+ --license '#{license}' \
129
+ --vendor '#{vendor}' \
130
+ --category '#{category}' \
131
+ #{fpm_scripts_args} \
132
+ #{fpm_config_files_args} \
133
+ #{config_files.join(' ')} \
134
+ #{files.join(' ')}"
135
+
136
+ logger.info "DEB built."
137
+ else
138
+ logger.info "Not building DEB, platform [#{ohai.platform}] does not support it."
139
+ end
140
+
141
+ end
142
+ end
143
+
144
+ def define_build_all
145
+ desc "Build all packages: #{name}-#{version}-#{iteration}-#{arch}"
146
+ task :build => [:build_tarball, :build_rpm, :build_deb]
147
+ end
148
+
149
+ # depend on a {Bunchr::Software} object to be built and installed
150
+ def include_software(other_dependency)
151
+ namespace 'packages' do
152
+ namespace name do
153
+ task :build => "software:#{other_dependency}:done"
154
+ end
155
+ end
156
+ end
157
+
158
+ # return an argument string for fpm with '--config-files' prefixed to
159
+ # every file in the config_files array.
160
+ # eg: '--config-files /etc/file1 --config-files /etc/file2'
161
+ def fpm_config_files_args
162
+ config_files.map { |f| '--config-files ' + f }.join(' ')
163
+ end
164
+
165
+ # returns an argument string for fpm with files from the scripts hash, eg:
166
+ # scripts[:after_install] = 'file1'
167
+ # scripts[:before_remove] = 'file2'
168
+ # fpm_scripts_args() # => '--after-install file1 --before-remove file2'
169
+ def fpm_scripts_args
170
+ scripts.map do |k,v|
171
+ "--#{k.to_s.tr('_','-')} #{v}" << ' '
172
+ end.join(' ')
173
+ end
174
+
175
+ end
176
+ end
@@ -0,0 +1,164 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/clean'
4
+ require 'yaml'
5
+ require 'bunchr/utils'
6
+
7
+ module Bunchr
8
+
9
+ class Software < ::Rake::TaskLib
10
+ include ::Bunchr::Utils
11
+
12
+ attr_accessor :name, :version
13
+ attr_accessor :download_commands, :build_commands, :install_commands
14
+ attr_accessor :download_environment, :build_environment, :install_environment
15
+
16
+ def initialize()
17
+ @name = nil
18
+ @version = nil
19
+ @install_commands = []
20
+ @build_commands = []
21
+ @download_commands = []
22
+ @install_environment = {}
23
+ @build_environment = {}
24
+ @download_environment = {}
25
+ yield self if block_given?
26
+ define unless name.nil?
27
+ end
28
+
29
+ def download_dir
30
+ File.join(Bunchr.build_dir, name)
31
+ end
32
+
33
+ # The directory this task unpacks into
34
+ def work_dir
35
+ @work_dir ||= File.join(download_dir, "#{name + (version ? "-#{version}" : "") }")
36
+ end
37
+
38
+ # override the directory that the local source unpacks into if it is not
39
+ # +name-version+. If pd is an absolute path, use it. Otherwise, prepend with
40
+ # @download_dir.
41
+ def work_dir=(pd)
42
+ if pd =~ /^\//
43
+ @work_dir = pd
44
+ else
45
+ @work_dir = File.join(download_dir, pd)
46
+ end
47
+ end
48
+
49
+ # Define all the tasks in the namespace of the +name+ of this task.
50
+ #
51
+ # The dependency chain is:
52
+ #
53
+ # :install => :build => :download
54
+ def define
55
+ logger.debug "Defining tasks for software:#{name} #{version}"
56
+
57
+ namespace 'software' do
58
+ namespace name do
59
+ define_download
60
+ define_build
61
+ define_install
62
+
63
+ task :done => "software:#{name}:install"
64
+ task :default => "software:#{name}:done"
65
+ end
66
+
67
+ desc "Download, build, and install #{name} #{version}"
68
+ task name => "#{name}:default"
69
+ end
70
+
71
+ end
72
+
73
+ def define_download
74
+ directory download_dir
75
+
76
+ desc "Download #{name} #{version}"
77
+ task :download => dotfile('download') do
78
+ logger.info "#{name} #{version} downloaded"
79
+ end
80
+
81
+ file dotfile('download') => download_dir do
82
+ logger.info "Downloading #{name} #{version}"
83
+ Dir.chdir(download_dir) do
84
+ download
85
+ end
86
+ dotfile!('download')
87
+ end
88
+ ::CLEAN << dotfile('download')
89
+ ::CLEAN << download_dir
90
+ end
91
+
92
+ def define_build
93
+ desc "Build #{name} #{version}"
94
+ task :build => dotfile('build') do
95
+ logger.info "#{name} #{version} built"
96
+ end
97
+
98
+ file dotfile('build') => "software:#{name}:download" do
99
+ logger.info "Bulding #{name} #{version}"
100
+ Dir.chdir(work_dir) do
101
+ build
102
+ end
103
+ dotfile!('build')
104
+ end
105
+ ::CLEAN << dotfile('build')
106
+ end
107
+
108
+ def define_install
109
+ desc "Install #{name} #{version}"
110
+ task :install => dotfile('install') do
111
+ logger.info "#{name} #{version} is installed"
112
+ end
113
+
114
+ file dotfile('install') => "software:#{name}:build" do
115
+ logger.info "Installing #{name} #{version}"
116
+ Dir.chdir(work_dir) do
117
+ install
118
+ end
119
+ dotfile!('install')
120
+ end
121
+ ::CLEAN << dotfile('install')
122
+
123
+ end
124
+
125
+ # Execute all the build commands
126
+ def download
127
+ download_commands.each do |cmd|
128
+ sh(cmd, download_environment, download_dir)
129
+ end
130
+ end
131
+
132
+ # Execute all the build commands
133
+ def build
134
+ build_commands.each do |cmd|
135
+ sh(cmd, build_environment, work_dir)
136
+ end
137
+ end
138
+
139
+ # Execute all the install commands
140
+ def install
141
+ install_commands.each do |cmd|
142
+ sh(cmd, install_environment, work_dir)
143
+ end
144
+ end
145
+
146
+ # depend on a {Bunchr::Software} object to be built and installed
147
+ def depends_on(dependency)
148
+ namespace 'software' do
149
+ namespace name do
150
+ task :build => "software:#{dependency}:done"
151
+ end
152
+ end
153
+ end
154
+
155
+ def dotfile(name)
156
+ File.join(download_dir, ".#{name}")
157
+ end
158
+
159
+ def dotfile!(name)
160
+ File.open(dotfile(name), "w") { |f| puts Time.now }
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,36 @@
1
+ require 'systemu'
2
+ require 'bunchr/logger'
3
+ require 'bunchr/ohai'
4
+
5
+ module Bunchr
6
+ module Utils
7
+
8
+ # Execute a shell command, with optional environment. stdout and stderr
9
+ # will be sent to the logger if the command exits with non-zero status.
10
+ def sh(cmd, env={}, dir=nil)
11
+ logger.info("Executing: [#{cmd.gsub(/\s{2,}/, ' ')}]")
12
+
13
+ output = ''
14
+ status = systemu("#{cmd}",
15
+ :stdout => output,
16
+ :stderr => output,
17
+ :env => env,
18
+ :cwd => dir)
19
+ if status.exitstatus > 0
20
+ logger << output
21
+ fail "Command failed with status (#{status.exitstatus}): [#{cmd.gsub(/\s{2,}/, ' ')}]."
22
+ end
23
+ end
24
+
25
+ # handle to the top level logger
26
+ def logger
27
+ Bunchr::Logger.logger
28
+ end
29
+
30
+ # handle to the top level ohai for generic system information
31
+ def ohai
32
+ Bunchr::Ohai.ohai
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Bunchr
2
+ VERSION = '0.1.1'
3
+ end
data/lib/bunchr.rb ADDED
@@ -0,0 +1,42 @@
1
+ module Bunchr
2
+ require 'bunchr/software'
3
+ require 'bunchr/packages'
4
+ require 'bunchr/logger'
5
+ require 'bunchr/utils'
6
+ require 'bunchr/ohai'
7
+
8
+ # global module variables that must be set ay a Bunchr project and will
9
+ # be used by Bunchr::Software and ::Packages tasks.
10
+ @@build_dir = nil
11
+ @@install_dir = nil
12
+
13
+ class << self
14
+ def install_dir
15
+ if @@install_dir.nil?
16
+ raise "You must set `Bunchr.install_dir = '/path'` in your Rakefile."
17
+ end
18
+ @@install_dir
19
+ end
20
+
21
+ def install_dir=(dir)
22
+ @@install_dir = dir
23
+ end
24
+
25
+ def build_dir
26
+ if @@build_dir.nil?
27
+ raise "You must set `Bunchr.build_dir = '/path'` in your Rakefile."
28
+ end
29
+ @@build_dir
30
+ end
31
+
32
+ def build_dir=(dir)
33
+ @@build_dir = dir
34
+ end
35
+
36
+ # simple wrapper around Rake's import() method for loading .rake files
37
+ def load_recipes(*files)
38
+ files.flatten.each { |f| import f }
39
+ end
40
+ end
41
+
42
+ end