mofa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,140 @@
1
+ class SourceCookbook < Cookbook
2
+ attr_accessor :pkg_dir
3
+ attr_accessor :pkg_name
4
+
5
+ COOKBOOK_IGNORE=%w(.mofa .idea .kitchen .vagrant .bundle test)
6
+
7
+ def initialize(cookbook_name_or_path)
8
+ super()
9
+ path = Pathname.new(cookbook_name_or_path)
10
+
11
+ say "Looking for Cookbook Sources in Path #{path}..."
12
+ @source_uri = "file://#{path.realpath}"
13
+
14
+ say "source_dir=#{source_dir}"
15
+ autodetect_name
16
+ autodetect_version
17
+ end
18
+
19
+ # ------------- Interface Methods
20
+
21
+ def prepare
22
+ fail "Source URI is not a file:// URI!" unless source_uri =~ /^file:\/\/.*/
23
+ fail "Folder #{source_dir} is not a Cookbook Folder!" unless cookbook_folder?(source_dir)
24
+ @pkg_name = "#{name}-#{token}-SNAPSHOT.tar.gz"
25
+ @pkg_dir = "#{source_dir}/.mofa/#{token}"
26
+ end
27
+
28
+ def execute
29
+ package
30
+ stage
31
+ end
32
+
33
+ def cleanup
34
+ say "Removing folder #{pkg_dir}...#{nl}"
35
+ run "rm -r #{pkg_dir}"
36
+ ok
37
+ end
38
+
39
+ # ------------- /Interface Methods
40
+ def source_dir
41
+ source_uri.gsub(/^file:\/\//, '')
42
+ end
43
+
44
+ def autodetect_name
45
+ say "Autodetecting Cookbook Name... "
46
+ @name = open("#{source_dir}/metadata.rb").grep(/^name/)[0].gsub(/^name[^a-zA-Z0-9_-]*/, '').gsub(/.$/, '').chomp
47
+ say "#{name}"
48
+ end
49
+
50
+ def autodetect_version
51
+ say "Autodetecting Cookbook Version... "
52
+ @version = open("#{source_dir}/metadata.rb").grep(/^version/)[0].gsub(/^version[^0-9\.]*/, '').gsub(/.$/, '').chomp
53
+ say "#{version}"
54
+ end
55
+
56
+ def recipes
57
+ recipes = Dir.entries("#{source_dir}/recipes").select {|f| f.match(/.rb$/)}
58
+ recipes.map! {|f| f.gsub(/\.rb/, '')}
59
+ end
60
+
61
+ def cleanup!
62
+ unless (Dir.entries("#{source_dir}/.mofa") - %w{ . .. }).empty?
63
+ say "Removing content of folder #{source_dir}/.mofa"
64
+ run "rm -r #{source_dir}/.mofa/*"
65
+ else
66
+ say "Folder #{source_dir}/.mofa is (already) clean."
67
+ end
68
+ end
69
+
70
+ def stage
71
+ if mofahub_available?
72
+ say 'Staging (uploading to mofa-hub) Cookbook Snapshot: '
73
+ @cookbooks_url = upload_to_mofahub
74
+ else
75
+ say 'Using local URI as cookbooks_url: '
76
+ @cookbooks_url = "file://#{pkg_dir}/#{pkg_name}"
77
+ end
78
+ say "#{@cookbooks_url}"
79
+ end
80
+
81
+ def cookbook_folder?(source_dir)
82
+ File.exist?(source_dir) && File.exists?("#{source_dir}/metadata.rb") && File.exists?("#{source_dir}/recipes")
83
+ end
84
+
85
+ def mofahub_available?
86
+ false
87
+ end
88
+
89
+ def package
90
+ berks_install_package
91
+ cleanup_and_repackage
92
+ end
93
+
94
+ def berks_install_package
95
+ say "Running \"berks install\" and \”berks package\" on Cookbook in #{source_dir}...#{nl}"
96
+
97
+ redirect_stdout = (Mofa::CLI::option_verbose) ? '' : '> /dev/null'
98
+ Bundler.with_clean_env do
99
+ inside source_dir do
100
+ mkdir_p pkg_dir
101
+ run "berks install #{redirect_stdout}"
102
+ run "berks package #{pkg_dir}/#{pkg_name} #{redirect_stdout}"
103
+ end
104
+ end
105
+
106
+ ok
107
+ end
108
+
109
+ def cleanup_and_repackage
110
+ say "Shrinking Cookbook Snapshot #{pkg_name}...#{nl}"
111
+
112
+ tar_verbose = (Mofa::CLI::option_debug) ? 'v' : ''
113
+
114
+ inside source_dir do
115
+
116
+ mkdir_p "#{pkg_dir}/tmp"
117
+ run "tar x#{tar_verbose}fz #{pkg_dir}/#{pkg_name} -C #{pkg_dir}/tmp/"
118
+
119
+ COOKBOOK_IGNORE.each do |remove_this|
120
+ if File.exists?("#{pkg_dir}/tmp/cookbooks/#{name}/#{remove_this}")
121
+ run "rm -r #{pkg_dir}/tmp/cookbooks/#{name}/#{remove_this}"
122
+ end
123
+ end
124
+
125
+ run "cd #{pkg_dir}/tmp/;tar c#{tar_verbose}fz #{pkg_dir}/#{pkg_name}.new ."
126
+ run "rm #{pkg_dir}/#{pkg_name}"
127
+ run "mv #{pkg_dir}/#{pkg_name}.new #{pkg_dir}/#{pkg_name}"
128
+ run "rm -r #{pkg_dir}/tmp/"
129
+
130
+ end
131
+
132
+ ok
133
+ end
134
+
135
+ private
136
+
137
+ def nl
138
+ return (Mofa::CLI::option_verbose) ? '' : ' '
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ module Mofa
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mofa/version"
4
+ Gem::Specification.new do |s|
5
+ s.name = "mofa"
6
+ s.version = Mofa::VERSION
7
+ s.authors = ["Alexander Birk"]
8
+ s.email = ["birk@pingworks.de"]
9
+ s.homepage = "https://github.com/birka/mofa"
10
+ s.summary = %q{a lightweight remote chef-solo runner}
11
+ s.description = %q{a lightweight remote chef-solo runner}
12
+ s.rubyforge_project = "mofa"
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.add_development_dependency "rspec"
18
+ s.add_development_dependency "fakefs"
19
+ s.add_development_dependency "guard-minitest"
20
+ s.add_development_dependency "rake"
21
+ s.add_runtime_dependency "thor"
22
+ s.add_runtime_dependency "json"
23
+ s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "net-ssh"
25
+ s.add_runtime_dependency "net-sftp"
26
+ s.add_runtime_dependency "net-ping"
27
+ s.add_runtime_dependency "user_config"
28
+ s.add_runtime_dependency "chronic"
29
+ end
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mofa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Birk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakefs
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: thor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: json
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rest-client
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: net-ssh
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: net-sftp
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: net-ping
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: user_config
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: chronic
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :runtime
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ description: a lightweight remote chef-solo runner
207
+ email:
208
+ - birk@pingworks.de
209
+ executables:
210
+ - mofa
211
+ extensions: []
212
+ extra_rdoc_files: []
213
+ files:
214
+ - .gitignore
215
+ - .travis.yml
216
+ - Gemfile
217
+ - Guardfile
218
+ - LICENSE
219
+ - README.md
220
+ - Rakefile
221
+ - bin/mofa
222
+ - config.yml.erb
223
+ - lib/mofa.rb
224
+ - lib/mofa/cli.rb
225
+ - lib/mofa/config.rb
226
+ - lib/mofa/cookbook.rb
227
+ - lib/mofa/hostlist.rb
228
+ - lib/mofa/mofa_cmd.rb
229
+ - lib/mofa/released_cookbook.rb
230
+ - lib/mofa/runlist_map.rb
231
+ - lib/mofa/source_cookbook.rb
232
+ - lib/mofa/version.rb
233
+ - mofa.gemspec
234
+ homepage: https://github.com/birka/mofa
235
+ licenses: []
236
+ post_install_message:
237
+ rdoc_options: []
238
+ require_paths:
239
+ - lib
240
+ required_ruby_version: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ none: false
248
+ requirements:
249
+ - - ! '>='
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
+ requirements: []
253
+ rubyforge_project: mofa
254
+ rubygems_version: 1.8.23
255
+ signing_key:
256
+ specification_version: 3
257
+ summary: a lightweight remote chef-solo runner
258
+ test_files: []