omnibus 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE +201 -0
  8. data/NOTICE +9 -0
  9. data/README.md +186 -0
  10. data/Rakefile +7 -0
  11. data/bin/makeself-header.sh +401 -0
  12. data/bin/makeself.sh +407 -0
  13. data/bin/omnibus +11 -0
  14. data/lib/omnibus.rb +280 -0
  15. data/lib/omnibus/build_version.rb +281 -0
  16. data/lib/omnibus/builder.rb +323 -0
  17. data/lib/omnibus/clean_tasks.rb +30 -0
  18. data/lib/omnibus/cli.rb +35 -0
  19. data/lib/omnibus/cli/application.rb +136 -0
  20. data/lib/omnibus/cli/base.rb +112 -0
  21. data/lib/omnibus/cli/build.rb +66 -0
  22. data/lib/omnibus/cli/cache.rb +60 -0
  23. data/lib/omnibus/config.rb +186 -0
  24. data/lib/omnibus/exceptions.rb +54 -0
  25. data/lib/omnibus/fetcher.rb +184 -0
  26. data/lib/omnibus/fetchers.rb +22 -0
  27. data/lib/omnibus/fetchers/git_fetcher.rb +212 -0
  28. data/lib/omnibus/fetchers/net_fetcher.rb +191 -0
  29. data/lib/omnibus/fetchers/path_fetcher.rb +65 -0
  30. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +42 -0
  31. data/lib/omnibus/health_check.rb +260 -0
  32. data/lib/omnibus/library.rb +70 -0
  33. data/lib/omnibus/overrides.rb +69 -0
  34. data/lib/omnibus/project.rb +566 -0
  35. data/lib/omnibus/reports.rb +99 -0
  36. data/lib/omnibus/s3_cacher.rb +136 -0
  37. data/lib/omnibus/software.rb +430 -0
  38. data/lib/omnibus/templates/Berksfile.erb +3 -0
  39. data/lib/omnibus/templates/Gemfile.erb +4 -0
  40. data/lib/omnibus/templates/README.md.erb +102 -0
  41. data/lib/omnibus/templates/Vagrantfile.erb +95 -0
  42. data/lib/omnibus/templates/gitignore.erb +8 -0
  43. data/lib/omnibus/templates/omnibus.rb.example.erb +5 -0
  44. data/lib/omnibus/templates/package_scripts/makeselfinst.erb +27 -0
  45. data/lib/omnibus/templates/package_scripts/postinst.erb +17 -0
  46. data/lib/omnibus/templates/package_scripts/postrm.erb +9 -0
  47. data/lib/omnibus/templates/project.rb.erb +21 -0
  48. data/lib/omnibus/templates/software/c-example.rb.erb +42 -0
  49. data/lib/omnibus/templates/software/erlang-example.rb.erb +38 -0
  50. data/lib/omnibus/templates/software/ruby-example.rb.erb +24 -0
  51. data/lib/omnibus/util.rb +61 -0
  52. data/lib/omnibus/version.rb +20 -0
  53. data/omnibus.gemspec +34 -0
  54. data/spec/build_version_spec.rb +228 -0
  55. data/spec/data/overrides/bad_line.overrides +3 -0
  56. data/spec/data/overrides/good.overrides +5 -0
  57. data/spec/data/overrides/with_dupes.overrides +4 -0
  58. data/spec/data/software/erchef.rb +40 -0
  59. data/spec/overrides_spec.rb +114 -0
  60. data/spec/software_spec.rb +71 -0
  61. data/spec/spec_helper.rb +28 -0
  62. metadata +239 -0
@@ -0,0 +1,112 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'omnibus/util'
19
+ require 'thor'
20
+
21
+ module Omnibus
22
+ module CLI
23
+ class Base < Thor
24
+ include Thor::Actions
25
+
26
+ class_option :config,
27
+ :aliases => [:c],
28
+ :type => :string,
29
+ :default => File.join(Dir.pwd, Omnibus::DEFAULT_CONFIG_FILENAME),
30
+ :desc => "Path to the Omnibus configuration file to use."
31
+
32
+ def initialize(args, options, config)
33
+ super(args, options, config)
34
+ $stdout.sync = true
35
+
36
+ # Don't try to initialize the Omnibus project for help commands
37
+ return if config[:current_command].name == "help"
38
+
39
+ if path = @options[:path]
40
+ if (config = @options[:config]) && File.exist?(@options[:config])
41
+ say("Using Omnibus configuration file #{config}", :green)
42
+ Omnibus.load_configuration(config)
43
+ end
44
+
45
+ # TODO: merge in all relevant CLI options here, as they should
46
+ # override anything from a configuration file.
47
+ Omnibus::Config.project_root(path)
48
+
49
+ unless Omnibus.project_files.any?
50
+ raise Omnibus::CLI::Error, "Given path '#{path}' does not appear to be a valid Omnibus project root."
51
+ end
52
+
53
+ begin
54
+ Omnibus.process_configuration
55
+ rescue => e
56
+ error_msg = "Could not load the Omnibus projects."
57
+ raise Omnibus::CLI::Error.new(error_msg, e)
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ ##################################################################
64
+ # Thor Overrides/Tweaks
65
+ ##################################################################
66
+
67
+ # Used by {Thor::Actions#template} to locate ERB templates
68
+ # @return [String]
69
+ def self.source_root
70
+ File.expand_path(File.join(File.dirname(__FILE__), '..', 'templates'))
71
+ end
72
+
73
+ # Forces command to exit with a 1 on any failure...so raise away.
74
+ def self.exit_on_failure?
75
+ true
76
+ end
77
+
78
+ # For some strange reason the +subcommand+ argument is disregarded when
79
+ # +Thor.banner+ is called by +Thor.command_help+:
80
+ #
81
+ # https://github.com/wycats/thor/blob/master/lib/thor.rb#L163-L164
82
+ #
83
+ # We'll override +Thor.banner+ and ensure subcommand is true when called
84
+ # for subcommands.
85
+ def self.banner(command, namespace = nil, subcommand = false)
86
+ # Main commands have an effective namespace of 'application' OR
87
+ # contain subcommands
88
+ if (self.namespace.split(':').last != 'application') || self.subcommands.empty?
89
+ subcommand = true
90
+ end
91
+ "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
92
+ end
93
+
94
+ protected
95
+
96
+ ##################################################################
97
+ # Omnibus Helpers (should these be in Omnibus::Util?)
98
+ ##################################################################
99
+
100
+ def load_project!(project_name)
101
+ project = Omnibus.project(project_name)
102
+ unless project
103
+ error_msg = "I don't know anythinga about project '#{project_name}'."
104
+ error_msg << " Valid project names include: #{Omnibus.project_names.join(', ')}"
105
+ raise Omnibus::CLI::Error, error_msg
106
+ end
107
+ project
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'omnibus/cli/base'
19
+
20
+ module Omnibus
21
+ module CLI
22
+ class Build < Base
23
+
24
+ namespace :build
25
+
26
+ class_option :path,
27
+ :aliases => [:p],
28
+ :type => :string,
29
+ :default => Dir.pwd,
30
+ :desc => "Path to the Omnibus project root."
31
+
32
+ method_option :timestamp,
33
+ :aliases => [:t],
34
+ :type => :boolean,
35
+ :default => true,
36
+ :desc => "Append timestamp information to the version identifier? Add a timestamp for build versions; leave it off for release and pre-release versions"
37
+ desc "project PROJECT", "Build the given Omnibus project"
38
+ def project(project_name)
39
+ project = load_project!(project_name)
40
+ project_task_name = "projects:#{project.name}"
41
+
42
+ say("Building #{project.name}", :green)
43
+ unless options[:timestamp]
44
+ say("I won't append a timestamp to the version identifier.", :yellow)
45
+ end
46
+
47
+ # Until we have time to integrate the CLI deeply into the Omnibus codebase
48
+ # this will have to suffice! (sadpanda)
49
+ ENV['OMNIBUS_APPEND_TIMESTAMP'] = options[:timestamp].to_s
50
+
51
+ Rake::Task[project_task_name].invoke
52
+ end
53
+
54
+ desc "software PROJECT SOFTWARE", "Build the given software component"
55
+ def software(project_name, software_name)
56
+ project = load_project!(project_name)
57
+ software_task_name = "projects:#{project.name}:software:#{software_name}"
58
+
59
+ say("Building #{software_name} for #{project.name} project", :green)
60
+
61
+ Rake::Task[software_task_name].invoke
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'omnibus/cli/base'
19
+ require 'omnibus/s3_cacher'
20
+
21
+ module Omnibus
22
+ module CLI
23
+ class Cache < Base
24
+
25
+ class_option :path,
26
+ :aliases => [:p],
27
+ :type => :string,
28
+ :default => Dir.pwd,
29
+ :desc => "Path to the Omnibus project root."
30
+
31
+ namespace :cache
32
+
33
+ desc "existing", "List source packages which exist in the cache"
34
+ def existing
35
+ S3Cache.new.list.each {|s| puts s.name}
36
+ end
37
+
38
+ desc "list", "List all cached files (by S3 key)"
39
+ def list
40
+ S3Cache.new.list_by_key.each {|k| puts k}
41
+ end
42
+
43
+ desc "missing", "Lists source packages that are required but not yet cached"
44
+ def missing
45
+ S3Cache.new.missing.each {|s| puts s.name}
46
+ end
47
+
48
+ desc "fetch", "Fetches missing source packages to local tmp dir"
49
+ def fetch
50
+ S3Cache.new.fetch_missing
51
+ end
52
+
53
+ desc "populate", "Populate the S3 Cache"
54
+ def populate
55
+ S3Cache.new.populate
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,186 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'mixlib/config'
19
+ require 'omnibus/exceptions'
20
+
21
+ module Omnibus
22
+
23
+ # Global configuration object for Omnibus runs.
24
+ #
25
+ # @todo Write a {http://yardoc.org/guides/extending-yard/writing-handlers.html
26
+ # Yard handler} for Mixlib::Config-style DSL methods. I'd like
27
+ # the default value to show up in the docs without having to type
28
+ # it out twice, which I'm doing now for benefit of viewers of the Yard docs.
29
+ class Config
30
+ extend Mixlib::Config
31
+
32
+ # @!group Directory Configuration Parameters
33
+
34
+ # @!attribute [rw] cache_dir
35
+ # The absolute path to the directory on the virtual machine where
36
+ # code will be cached.
37
+ #
38
+ # Defaults to `"/var/cache/omnibus/cache"`.
39
+ #
40
+ # @return [String]
41
+ cache_dir "/var/cache/omnibus/cache"
42
+
43
+ # @!attribute [rw] source_dir
44
+ # The absolute path to the directory on the virtual machine where
45
+ # source code will be downloaded.
46
+ #
47
+ # Defaults to `"/var/cache/omnibus/src"`.
48
+ #
49
+ # @return [String]
50
+ source_dir "/var/cache/omnibus/src"
51
+
52
+ # @!attribute [rw] build_dir
53
+ # The absolute path to the directory on the virtual machine where
54
+ # software will be built.
55
+ #
56
+ # Defaults to `"/var/cache/omnibus/build"`.
57
+ #
58
+ # @return [String]
59
+ build_dir "/var/cache/omnibus/build"
60
+
61
+ # @!attribute [rw] package_dir
62
+ # The absolute path to the directory on the virtual machine where
63
+ # packages will be constructed.
64
+ #
65
+ # Defaults to `"/var/cache/omnibus/pkg"`.
66
+ #
67
+ # @return [String]
68
+ package_dir "/var/cache/omnibus/pkg"
69
+
70
+ # @!attribute [rw] project_dir
71
+ # The relative path of the directory containing {Omnibus::Project}
72
+ # DSL files. This is relative to {#project_root}.
73
+ #
74
+ # Defaults to `"config/projects"`.
75
+ #
76
+ # @return [String]
77
+ project_dir "config/projects"
78
+
79
+ # @!attribute [rw] software_dir
80
+ # The relative path of the directory containing {Omnibus::Software}
81
+ # DSL files. This is relative {#project_root}.
82
+ #
83
+ # Defaults to `"config/software"`.
84
+ #
85
+ # @return [String]
86
+ software_dir "config/software"
87
+
88
+ # @!attribute [rw] project_root
89
+ # The root directory in which to look for {Omnibus::Project} and
90
+ # {Omnibus::Software} DSL files.
91
+ #
92
+ # Defaults to the current working directory.
93
+ #
94
+ # @return [String]
95
+ project_root Dir.pwd
96
+
97
+ # @!attribute [rw] install_dir
98
+ # Installation directory
99
+ #
100
+ # Defaults to `"/opt/chef"`.
101
+ #
102
+ # @todo This appears to be unused, and actually conflated with
103
+ # {Omnibus::Project#install_path}
104
+ #
105
+ # @return [String]
106
+ install_dir "/opt/chef"
107
+
108
+ # @!endgroup
109
+
110
+ # @!group S3 Caching Configuration Parameters
111
+
112
+ # @!attribute [rw] use_s3_caching
113
+ # Indicate if you wish to cache software artifacts in S3 for
114
+ # quicker build times. Requires {#s3_bucket}, {#s3_access_key},
115
+ # and {#s3_secret_key} to be set if this is set to `true`.
116
+ #
117
+ # Defaults to `false`.
118
+ #
119
+ # @return [Boolean]
120
+ use_s3_caching false
121
+
122
+ # @!attribute [rw] s3_bucket
123
+ # The name of the S3 bucket you want to cache software artifacts in.
124
+ #
125
+ # Defaults to `nil`. Must be set if {#use_s3_caching} is `true`.
126
+ #
127
+ # @return [String, nil]
128
+ s3_bucket nil
129
+
130
+ # @!attribute [rw] s3_access_key
131
+ # The S3 access key to use with S3 caching.
132
+ #
133
+ # Defaults to `nil`. Must be set if {#use_s3_caching} is `true`.
134
+ #
135
+ # @return [String, nil]
136
+ s3_access_key nil
137
+
138
+ # @!attribute [rw] s3_secret_key
139
+ # The S3 secret key to use with S3 caching.
140
+ #
141
+ # Defaults to `nil`. Must be set if {#use_s3_caching} is `true.`
142
+ #
143
+ # @return [String, nil]
144
+ s3_secret_key nil
145
+
146
+ # @!endgroup
147
+
148
+ # @!group Miscellaneous Configuration Parameters
149
+
150
+ # @!attribute [rw] override_file
151
+ #
152
+ # @return [Boolean]
153
+ override_file nil
154
+
155
+ # @!attribute [rw] solaris_compiler
156
+ #
157
+ # @return [String, nil]
158
+ solaris_compiler nil
159
+
160
+ # @!endgroup
161
+
162
+ # @!group Validation Methods
163
+
164
+ # Asserts that the Config object is in a valid state. If invalid
165
+ # for any reason, an exception will be thrown.
166
+ #
167
+ # @raise [RuntimeError]
168
+ # @return [void]
169
+ def self.validate
170
+ valid_s3_config?
171
+ # add other validation methods as needed
172
+ end
173
+
174
+ # @raise [InvalidS3Configuration]
175
+ def self.valid_s3_config?
176
+ if use_s3_caching
177
+ unless s3_bucket
178
+ raise InvalidS3Configuration.new(s3_bucket, s3_access_key, s3_secret_key)
179
+ end
180
+ end
181
+ end
182
+
183
+ # @!endgroup
184
+
185
+ end # Config
186
+ end # Omnibus
@@ -0,0 +1,54 @@
1
+ module Omnibus
2
+
3
+ class InvalidS3Configuration < RuntimeError
4
+ def initialize(s3_bucket, s3_access_key, s3_secret_key)
5
+ @s3_bucket, @s3_access_key, @s3_secret_key = s3_bucket, s3_access_key, s3_secret_key
6
+ end
7
+
8
+ def to_s
9
+ """
10
+ One or more required S3 configuration values is missing.
11
+
12
+ Your effective configuration was the following:
13
+
14
+ s3_bucket => #{@s3_bucket.inspect}
15
+ s3_access_key => #{@s3_access_key.inspect}
16
+ s3_secret_key => #{@s3_secret_key.inspect}
17
+
18
+ If you truly do want S3 caching, you should add values similar
19
+ to the following in your Omnibus config file:
20
+
21
+ s3_bucket ENV['S3_BUCKET_NAME']
22
+ s3_access_key ENV['S3_ACCESS_KEY']
23
+ s3_secret_key ENV['S3_SECRET_KEY']
24
+
25
+ Note that you are not required to use environment variables as
26
+ illustrated (and the ones listed have no special significance in
27
+ Omnibus), but it is encouraged to prevent spread of sensitive
28
+ information and inadvertent check-in of same to version control
29
+ systems.
30
+
31
+ """
32
+ end
33
+ end
34
+
35
+ # Raise this error if a needed Project configuration value has not
36
+ # been set.
37
+ class MissingProjectConfiguration < RuntimeError
38
+ def initialize(parameter_name, sample_value)
39
+ @parameter_name, @sample_value = parameter_name, sample_value
40
+ end
41
+
42
+ def to_s
43
+ """
44
+ You are attempting to build a project, but have not specified
45
+ a value for '#{@parameter_name}'!
46
+
47
+ Please add code similar to the following to your project DSL file:
48
+
49
+ #{@parameter_name} '#{@sample_value}'
50
+
51
+ """
52
+ end
53
+ end
54
+ end