boxen 3.0.0.beta1 → 3.1.0

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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/README.md +1 -1
  4. data/boxen.gemspec +13 -13
  5. data/lib/boxen/check.rb +39 -8
  6. data/lib/boxen/cli.rb +45 -19
  7. data/lib/boxen/config.rb +61 -43
  8. data/lib/boxen/flags.rb +282 -0
  9. data/lib/boxen/hook.rb +8 -15
  10. data/lib/boxen/hook/github_issue.rb +120 -0
  11. data/lib/boxen/hook/web.rb +56 -0
  12. data/lib/boxen/keychain.rb +1 -1
  13. data/lib/boxen/postflight/env.rb +1 -1
  14. data/lib/boxen/preflight.rb +7 -4
  15. data/lib/boxen/preflight/creds.rb +47 -8
  16. data/lib/boxen/preflight/identity.rb +0 -2
  17. data/lib/boxen/preflight/os.rb +6 -2
  18. data/lib/boxen/puppeteer.rb +121 -0
  19. data/lib/boxen/runner.rb +149 -0
  20. data/script/bootstrap +1 -1
  21. data/script/tests +0 -1
  22. data/test/boxen/test.rb +1 -1
  23. data/test/boxen_check_test.rb +55 -0
  24. data/test/boxen_cli_test.rb +31 -8
  25. data/test/boxen_config_test.rb +31 -1
  26. data/test/boxen_directories_test.rb +4 -4
  27. data/test/boxen_flags_test.rb +217 -0
  28. data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb} +82 -72
  29. data/test/{postflight/boxen_postflight_web_hook_test.rb → boxen_hook_web_test.rb} +11 -12
  30. data/test/{postflight/boxen_postflight_active_test.rb → boxen_postflight_active_test.rb} +3 -3
  31. data/test/{postflight/boxen_postflight_env_test.rb → boxen_postflight_env_test.rb} +0 -0
  32. data/test/boxen_preflight_creds_test.rb +177 -0
  33. data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb} +1 -1
  34. data/test/{preflight/boxen_preflight_rvm_test.rb → boxen_preflight_rvm_test.rb} +1 -1
  35. data/test/boxen_puppeteer_test.rb +101 -0
  36. data/test/boxen_runner_test.rb +171 -0
  37. metadata +172 -251
  38. data/lib/boxen/command.rb +0 -142
  39. data/lib/boxen/command/help.rb +0 -40
  40. data/lib/boxen/command/preflight.rb +0 -38
  41. data/lib/boxen/command/project.rb +0 -49
  42. data/lib/boxen/command/project/install.rb +0 -33
  43. data/lib/boxen/command/run.rb +0 -199
  44. data/lib/boxen/command/service.rb +0 -61
  45. data/lib/boxen/command/service/disable.rb +0 -15
  46. data/lib/boxen/command/service/enable.rb +0 -15
  47. data/lib/boxen/command/service/restart.rb +0 -24
  48. data/lib/boxen/command/version.rb +0 -29
  49. data/lib/boxen/command_status.rb +0 -15
  50. data/lib/boxen/postflight/github_issue.rb +0 -124
  51. data/lib/boxen/postflight/hooks.rb +0 -16
  52. data/lib/boxen/postflight/web_hook.rb +0 -63
  53. data/lib/boxen/preflight/facts.rb +0 -36
  54. data/lib/boxen/preflight/homebrew.rb +0 -13
  55. data/lib/boxen/preflight/offline.rb +0 -33
  56. data/lib/boxen/preflight/update.rb +0 -109
  57. data/lib/boxen/util/logging.rb +0 -59
  58. data/lib/boxen/version.rb +0 -3
  59. data/lib/system_timer.rb +0 -13
  60. data/test/boxen_command_test.rb +0 -93
  61. data/test/boxen_hook_test.rb +0 -25
  62. data/test/command/help_test.rb +0 -49
  63. data/test/command/project/install_test.rb +0 -34
  64. data/test/command/project_test.rb +0 -32
  65. data/test/command/run_test.rb +0 -21
  66. data/test/command/service/disable_test.rb +0 -49
  67. data/test/command/service/enable_test.rb +0 -49
  68. data/test/command/service/restart_test.rb +0 -53
  69. data/test/command/service_test.rb +0 -55
  70. data/test/command/version_test.rb +0 -15
  71. data/test/preflight/boxen_preflight_creds_test.rb +0 -82
  72. data/test/preflight/boxen_preflight_homebrew_test.rb +0 -10
  73. data/test/system_timer.rb +0 -10
@@ -1,142 +0,0 @@
1
- require "boxen/command_status"
2
-
3
- # Pulled in so the others don't have to
4
- require "boxen/preflight"
5
- require "boxen/postflight"
6
- require "boxen/util/logging"
7
-
8
- class Boxen::Command
9
- include Boxen::Util::Logging
10
-
11
- class UnknownCommandError < StandardError; end
12
- class CommandNotRunError < StandardError; end
13
-
14
- attr_reader :config
15
-
16
- def self.help
17
- raise "You should define this"
18
- end
19
-
20
- def self.detailed_help
21
- raise "You should definitely define this"
22
- end
23
-
24
- def self.preflight(*klasses)
25
- preflights.replace preflights | klasses.flatten
26
- end
27
-
28
- def self.preflights
29
- @preflights ||= []
30
- end
31
-
32
- def self.postflight(*klasses)
33
- postflights.replace postflights | klasses.flatten
34
- end
35
-
36
- def self.postflights
37
- @postflights ||= []
38
- end
39
-
40
- def self.all
41
- @commands
42
- end
43
-
44
- def self.register(name, klass, *aliases)
45
- unless defined?(@commands)
46
- @commands = {}
47
- end
48
- unless defined?(@aliases)
49
- @aliases = {}
50
- end
51
-
52
- @commands[name] = klass
53
- aliases.each { |a| @aliases[a] = name }
54
- end
55
-
56
- def self.reset!
57
- @commands = {}
58
- end
59
-
60
- def self.invoke(name, *args)
61
- if @commands && name && @commands.has_key?(name.to_sym)
62
- @commands[name.to_sym].new(*args).invoke
63
- elsif @aliases && name && @aliases.has_key?(name.to_sym)
64
- invoke(@aliases[name.to_sym], *args)
65
- else
66
- raise UnknownCommandError,
67
- "could not find `#{name.inspect.to_s}` in the list of registered commands"
68
- end
69
- end
70
-
71
- def initialize(config, *args)
72
- @config = config
73
- @args = args
74
- end
75
-
76
- def invoke
77
- if preflights?
78
- @cmd_status = self.run
79
-
80
- postflights
81
-
82
- @cmd_status
83
- end
84
- end
85
-
86
- def run
87
- raise "So your command #{self.class.name} hasn't defined a run method, so we dunno what to do. Sorry."
88
- end
89
-
90
- def preflights?
91
- if self.class.preflights.any?
92
- info "Performing preflight checks"
93
- end
94
-
95
- self.class.preflights.all? do |p|
96
-
97
- debug "Performing preflight check: #{p.name}"
98
-
99
- p = p.new(@config, self)
100
- status = p.ok?
101
-
102
- if status
103
- debug "Passed preflight check: #{p.class.name}"
104
- else
105
- p.run
106
- end
107
-
108
- status
109
- end
110
- end
111
-
112
- def postflights
113
- if self.class.postflights.any?
114
- info "Performing postflight checks"
115
- end
116
-
117
- self.class.postflights.each do |p|
118
- p = p.new(@config, self)
119
- p.run unless p.ok?
120
- end
121
- end
122
-
123
- def debug?
124
- @config.debug?
125
- end
126
-
127
- def success?
128
- if @cmd_status
129
- @cmd_status.success?
130
- else
131
- raise CommandNotRunError,
132
- "the command hasn't been run, so we can't know if it was successful"
133
- end
134
- end
135
- end
136
-
137
- require "boxen/command/help"
138
- require "boxen/command/version"
139
- require "boxen/command/run"
140
- require "boxen/command/preflight"
141
- require "boxen/command/project"
142
- require "boxen/command/service"
@@ -1,40 +0,0 @@
1
- require "boxen/command"
2
-
3
- class Boxen::Command::Help < Boxen::Command
4
- def self.help
5
- "Displays help, obviously"
6
- end
7
-
8
- def self.detailed_help
9
- <<-EOS
10
-
11
- boxen help [<command>]
12
-
13
- With no arguments, displays short help information for all commands.
14
-
15
- Given a command name as an argument, displays detailed help about that command.
16
-
17
- EOS
18
- end
19
-
20
- def run
21
- if @args.any?
22
- puts Boxen::Command.all[@args.first.to_sym].detailed_help
23
- else
24
- Boxen::Command.all.each do |name, _|
25
- display_help_for_command name
26
- end
27
- end
28
-
29
- Boxen::CommandStatus.new(0)
30
- end
31
-
32
- def display_help_for_command(name)
33
- # only shows top-level commands, not subcommands
34
- unless name =~ /:/
35
- puts " #{name.to_s.ljust(16)} #{Boxen::Command.all[name.to_sym].help}"
36
- end
37
- end
38
- end
39
-
40
- Boxen::Command.register :help, Boxen::Command::Help, :"--help"
@@ -1,38 +0,0 @@
1
- require "boxen/command"
2
-
3
- class Boxen::Command::Preflight < Boxen::Command
4
- def self.help
5
- "Run a single preflight and return whether or not it's ok."
6
- end
7
-
8
- def self.detailed_help
9
- <<-EOS
10
-
11
- boxen preflight <check>
12
-
13
- Run preflight named <check> and return whether or not it's ok.
14
-
15
- EOS
16
- end
17
-
18
- def run
19
- if defined?(preflight)
20
- info "#{preflight.name}: #{preflight.new(@config).ok?.inspect}"
21
- return Boxen::CommandStatus.new(0)
22
- else
23
- fail("Could not find a preflight named: #{preflight_name}")
24
- end
25
- rescue => e
26
- fail("Command failed: #{e.message} #{e.backtrace}")
27
- end
28
-
29
- def preflight
30
- Object.const_get(preflight_name)
31
- end
32
-
33
- def preflight_name
34
- "Boxen::Preflight::#{ARGV[1].capitalize}"
35
- end
36
- end
37
-
38
- Boxen::Command.register :preflight, Boxen::Command::Preflight
@@ -1,49 +0,0 @@
1
- require "boxen/command"
2
- #require "boxen/service"
3
-
4
- class Boxen::Command::Project < Boxen::Command
5
- def self.detailed_help
6
- <<-EOS
7
-
8
- boxen project
9
-
10
- Display all projects Boxen knows about.
11
-
12
- boxen project:install <project1> [<project2> ...]
13
-
14
- Install a Boxen-managed project.
15
-
16
- NOTE: 'boxen project' is aliased to 'projects' for convenience
17
-
18
- EOS
19
- end
20
-
21
- def self.help
22
- "Show and install Boxen-managed projects"
23
- end
24
-
25
- def run
26
- @args = [] # we don't care about args here
27
-
28
- puts "Boxen knows about the following projects:"
29
- puts
30
-
31
- projects.each do |project|
32
- puts " #{project.name}"
33
- end
34
-
35
- puts
36
- puts "You can install any of them by running \"boxen project:install <project>\""
37
- puts
38
-
39
- Boxen::CommandStatus.new(0)
40
- end
41
-
42
- def projects
43
- @projects ||= @config.projects
44
- end
45
- end
46
-
47
- require "boxen/command/project/install"
48
-
49
- Boxen::Command.register :project, Boxen::Command::Project, :projects
@@ -1,33 +0,0 @@
1
- require "boxen/command/project"
2
-
3
- class Boxen::Command::Project::Install < Boxen::Command::Project
4
- def self.detailed_help
5
- <<-EOS
6
-
7
- boxen project:install <project1> [<project2> ...]
8
-
9
- Install one or more Boxen-managed projects.
10
-
11
- EOS
12
- end
13
-
14
- def self.help
15
- "Install one or more projects"
16
- end
17
-
18
- def run
19
- File.open("#{config.repodir}/.projects", "w+") do |f|
20
- f.truncate 0
21
- f.write projects
22
- end
23
-
24
- Boxen::Command.invoke 'run', config
25
- end
26
-
27
- def projects
28
- @args.join ','
29
- end
30
- end
31
-
32
- Boxen::Command.register :"project:install", Boxen::Command::Project::Install
33
- Boxen::Command.register :"projects:install", Boxen::Command::Project::Install
@@ -1,199 +0,0 @@
1
- require "boxen/command"
2
-
3
- class Boxen::Command::Run < Boxen::Command
4
- preflight \
5
- Boxen::Preflight::OS,
6
- Boxen::Preflight::Directories,
7
- Boxen::Preflight::EtcMyCnf,
8
- Boxen::Preflight::Homebrew,
9
- Boxen::Preflight::Rbenv,
10
- Boxen::Preflight::RVM,
11
- Boxen::Preflight::Offline,
12
- Boxen::Preflight::Creds,
13
- Boxen::Preflight::Identity,
14
- Boxen::Preflight::Update,
15
- Boxen::Preflight::Facts
16
-
17
- postflight \
18
- Boxen::Postflight::Active,
19
- Boxen::Postflight::Hooks,
20
- Boxen::Postflight::GithubIssue,
21
- Boxen::Postflight::Env
22
-
23
- def self.help
24
- "run Boxen's managed puppet environment"
25
- end
26
-
27
- def self.detailed_help
28
- <<-EOS
29
-
30
- boxen run [options]
31
-
32
- Runs Puppet via Boxen's environment.
33
-
34
- Some options you may find useful:
35
-
36
- --debug Be really, really verbose. Like incredibly verbose.
37
- --no-issue Don't file an issue if the Boxen run fails.
38
- --no-color Don't output any colored text to the tty.
39
- --report Generate graphs and catalog data from Puppet.
40
- --profile Display very high-level performance details from the Puppet run.
41
- --future-parser Use Puppet's upcoming future parser
42
- --graph Enable puppet dependency graph output
43
-
44
- boxen run:noop [options]
45
-
46
- The same thing as run, but acts as a dry run where no changes are made.
47
-
48
- EOS
49
- end
50
-
51
- def run
52
- info "Updating librarian-puppet modules"
53
- create_clean_working_environment
54
- run_librarian_puppet
55
-
56
- warn command.join(" ") if debug?
57
-
58
- info "Running puppet"
59
- Boxen::Util.sudo(*command)
60
-
61
- Boxen::CommandStatus.new($?.exitstatus, [0, 2])
62
- end
63
-
64
- def noop
65
- false
66
- end
67
-
68
- def report?
69
- @args.include? "--report"
70
- end
71
-
72
- def profile?
73
- @args.include? "--profile"
74
- end
75
-
76
- def future_parser?
77
- @args.include? "--future-parser"
78
- end
79
-
80
- def graph?
81
- @args.include? "--graph"
82
- end
83
-
84
- def debug?
85
- @args.include? "--debug"
86
- end
87
-
88
- def no_color?
89
- @args.include? "--no-color"
90
- end
91
-
92
- private
93
- def command
94
- [
95
- "#{config.repodir}/bin/puppet",
96
- "apply",
97
- puppet_flags,
98
- "#{config.repodir}/manifests/site.pp"
99
- ].flatten
100
- end
101
-
102
- def run_librarian_puppet
103
- if File.file? "#{config.repodir}/Puppetfile"
104
- librarian = "#{config.repodir}/bin/librarian-puppet"
105
-
106
- unless config.enterprise?
107
- ENV["GITHUB_API_TOKEN"] = config.token
108
- end
109
-
110
- librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
111
- librarian_command << "--verbose" if debug?
112
-
113
- warn librarian_command.join(" ") if debug?
114
- unless system(*librarian_command)
115
- abort "Can't run Puppet, fetching dependencies with librarian failed."
116
- end
117
- end
118
- end
119
-
120
- def create_clean_working_environment
121
- FileUtils.mkdir_p config.puppetdir
122
-
123
- FileUtils.rm_f config.logfile
124
-
125
- FileUtils.rm_rf "#{config.puppetdir}/var/reports" if report?
126
-
127
- FileUtils.mkdir_p File.dirname config.logfile
128
- FileUtils.touch config.logfile
129
- end
130
-
131
- def hiera_config
132
- hiera_yaml = "#{config.repodir}/config/hiera.yaml"
133
-
134
- File.exists?(hiera_yaml) ? hiera_yaml : "/dev/null"
135
- end
136
-
137
- def puppet_flags
138
- _flags = []
139
- root = File.expand_path "../../..", __FILE__
140
-
141
- _flags << ["--group", "admin"]
142
- _flags << ["--confdir", "#{config.puppetdir}/conf"]
143
- _flags << ["--vardir", "#{config.puppetdir}/var"]
144
- _flags << ["--libdir", "#{config.repodir}/lib"]#:#{root}/lib"]
145
- _flags << ["--libdir", "#{root}/lib"]
146
- _flags << ["--manifestdir", "#{config.repodir}/manifests"]
147
- _flags << ["--modulepath", "#{config.repodir}/modules:#{config.repodir}/shared"]
148
- _flags << ["--hiera_config", hiera_config]
149
- _flags << ["--logdest", "#{config.repodir}/log/puppet.log"]
150
- _flags << ["--logdest", "console"]
151
- _flags << ["--pluginfactdest", "#{config.homedir}/facts.d"]
152
-
153
- _flags << "--no-report" unless report?
154
- _flags << "--detailed-exitcodes"
155
-
156
- _flags << "--show_diff"
157
-
158
- if profile?
159
- _flags << "--evaltrace"
160
- _flags << "--summarize"
161
- end
162
-
163
- _flags << "--parser=future" if future_parser?
164
- _flags << "--graph" if graph?
165
-
166
- _flags << "--debug" if debug?
167
- _flags << "--noop" if noop
168
-
169
- _flags << "--color=false" if no_color?
170
-
171
- _flags.flatten
172
- end
173
- end
174
-
175
- class Boxen::Command::Run::Noop < Boxen::Command::Run
176
- preflight \
177
- Boxen::Preflight::OS,
178
- Boxen::Preflight::Directories,
179
- Boxen::Preflight::EtcMyCnf,
180
- Boxen::Preflight::Homebrew,
181
- Boxen::Preflight::Rbenv,
182
- Boxen::Preflight::RVM,
183
- Boxen::Preflight::Offline,
184
- Boxen::Preflight::Creds,
185
- Boxen::Preflight::Identity,
186
- Boxen::Preflight::Update,
187
- Boxen::Preflight::Facts
188
-
189
- postflight \
190
- Boxen::Postflight::Active,
191
- Boxen::Postflight::Env
192
-
193
- def noop
194
- true
195
- end
196
- end
197
-
198
- Boxen::Command.register :run, Boxen::Command::Run
199
- Boxen::Command.register :"run:noop", Boxen::Command::Run::Noop