boxen23 3.1.3a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +20 -0
  6. data/README.md +50 -0
  7. data/boxen.gemspec +29 -0
  8. data/lib/boxen/check.rb +72 -0
  9. data/lib/boxen/checkout.rb +25 -0
  10. data/lib/boxen/cli.rb +61 -0
  11. data/lib/boxen/config.rb +345 -0
  12. data/lib/boxen/error.rb +4 -0
  13. data/lib/boxen/flags.rb +291 -0
  14. data/lib/boxen/hook.rb +47 -0
  15. data/lib/boxen/hook/github_issue.rb +120 -0
  16. data/lib/boxen/hook/web.rb +56 -0
  17. data/lib/boxen/keychain.rb +61 -0
  18. data/lib/boxen/postflight.rb +13 -0
  19. data/lib/boxen/postflight/active.rb +16 -0
  20. data/lib/boxen/postflight/env.rb +29 -0
  21. data/lib/boxen/preflight.rb +13 -0
  22. data/lib/boxen/preflight/creds.rb +149 -0
  23. data/lib/boxen/preflight/directories.rb +32 -0
  24. data/lib/boxen/preflight/etc_my_cnf.rb +12 -0
  25. data/lib/boxen/preflight/identity.rb +16 -0
  26. data/lib/boxen/preflight/os.rb +33 -0
  27. data/lib/boxen/preflight/rbenv.rb +12 -0
  28. data/lib/boxen/preflight/rvm.rb +12 -0
  29. data/lib/boxen/project.rb +20 -0
  30. data/lib/boxen/puppeteer.rb +122 -0
  31. data/lib/boxen/runner.rb +149 -0
  32. data/lib/boxen/service.rb +58 -0
  33. data/lib/boxen/util.rb +19 -0
  34. data/lib/facter/boxen.rb +34 -0
  35. data/script/Boxen +0 -0
  36. data/script/bootstrap +7 -0
  37. data/script/build-keychain-helper +6 -0
  38. data/script/release +38 -0
  39. data/script/tests +10 -0
  40. data/src/keychain-helper.c +85 -0
  41. data/test/boxen/test.rb +7 -0
  42. data/test/boxen_check_test.rb +55 -0
  43. data/test/boxen_checkout_test.rb +42 -0
  44. data/test/boxen_cli_test.rb +39 -0
  45. data/test/boxen_config_test.rb +400 -0
  46. data/test/boxen_directories_test.rb +40 -0
  47. data/test/boxen_flags_test.rb +223 -0
  48. data/test/boxen_hook_github_issue_test.rb +294 -0
  49. data/test/boxen_hook_web_test.rb +58 -0
  50. data/test/boxen_keychain_test.rb +21 -0
  51. data/test/boxen_postflight_active_test.rb +29 -0
  52. data/test/boxen_postflight_env_test.rb +6 -0
  53. data/test/boxen_preflight_creds_test.rb +177 -0
  54. data/test/boxen_preflight_etc_my_cnf_test.rb +10 -0
  55. data/test/boxen_preflight_rvm_test.rb +10 -0
  56. data/test/boxen_project_test.rb +14 -0
  57. data/test/boxen_puppeteer_test.rb +101 -0
  58. data/test/boxen_runner_test.rb +171 -0
  59. data/test/boxen_service_test.rb +39 -0
  60. data/test/boxen_util_test.rb +21 -0
  61. data/test/fixtures/repo/modules/projects/manifests/first-project.pp +0 -0
  62. data/test/fixtures/repo/modules/projects/manifests/second-project.pp +0 -0
  63. metadata +257 -0
@@ -0,0 +1,12 @@
1
+ require "boxen/preflight"
2
+
3
+ class Boxen::Preflight::Rbenv < Boxen::Preflight
4
+ def run
5
+ warn "You have an existing rbenv installed in ~/.rbenv.",
6
+ "Boxen provides its own rbenv, so consider deleting yours."
7
+ end
8
+
9
+ def ok?
10
+ !File.exist? "#{ENV['HOME']}/.rbenv"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "boxen/preflight"
2
+
3
+ class Boxen::Preflight::RVM < Boxen::Preflight
4
+ def run
5
+ abort "You have an rvm installed in ~/.rvm.",
6
+ "Boxen uses rbenv to install ruby, so please `rvm implode`"
7
+ end
8
+
9
+ def ok?
10
+ !File.exist? "#{ENV['HOME']}/.rvm"
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Boxen
2
+
3
+ # A project managed by Boxen.
4
+
5
+ class Project
6
+
7
+ # The directory where this project's repo should live.
8
+
9
+ attr_reader :dir
10
+
11
+ # The name of this project.
12
+
13
+ attr_reader :name
14
+
15
+ def initialize(dir)
16
+ @dir = dir
17
+ @name = File.basename @dir
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,122 @@
1
+ require "fileutils"
2
+ require "boxen/util"
3
+
4
+ module Boxen
5
+
6
+ # Manages an invocation of puppet.
7
+
8
+ class Puppeteer
9
+
10
+ class Status < Struct.new(:code)
11
+ # Puppet's detailed exit codes reserves 2 for a successful run with changes
12
+ def success?
13
+ [0,2].include?(code)
14
+ end
15
+ end
16
+
17
+ attr_reader :config
18
+
19
+ def initialize(config)
20
+ @config = config
21
+ end
22
+
23
+ def command
24
+ manifestdir = "#{config.repodir}/manifests"
25
+ puppet = "#{config.repodir}/bin/puppet"
26
+
27
+ [puppet, "apply", flags, manifestdir].flatten
28
+ end
29
+
30
+ def hiera_config
31
+ if File.exist? "#{config.repodir}/config/hiera.yaml"
32
+ "#{config.repodir}/config/hiera.yaml"
33
+ else
34
+ "/dev/null"
35
+ end
36
+ end
37
+
38
+ def flags
39
+ flags = []
40
+ root = File.expand_path "../../..", __FILE__
41
+
42
+ flags << ["--group", "admin"]
43
+ flags << ["--confdir", "#{config.puppetdir}/conf"]
44
+ flags << ["--vardir", "#{config.puppetdir}/var"]
45
+ flags << ["--libdir", "#{config.repodir}/lib"]#:#{root}/lib"]
46
+ flags << ["--libdir", "#{root}/lib"]
47
+ flags << ["--modulepath", "#{config.repodir}/modules:#{config.repodir}/shared"]
48
+
49
+ # Don't ever complain about Hiera to me
50
+ flags << ["--hiera_config", hiera_config]
51
+
52
+ # Log to both the console and a file.
53
+
54
+ flags << ["--logdest", config.logfile]
55
+ flags << ["--logdest", "console"]
56
+
57
+ # For some reason Puppet tries to set up a bunch of rrd stuff
58
+ # (user, group) unless reports are completely disabled.
59
+
60
+ flags << "--no-report" unless config.report?
61
+ flags << "--detailed-exitcodes"
62
+
63
+ flags << "--graph" if config.graph?
64
+
65
+ flags << "--show_diff"
66
+
67
+ if config.profile?
68
+ flags << "--evaltrace"
69
+ flags << "--summarize"
70
+ end
71
+
72
+ if config.future_parser?
73
+ flags << "--parser=future"
74
+ end
75
+
76
+ flags << "--debug" if config.debug?
77
+ flags << "--noop" if config.pretend?
78
+
79
+ flags << "--color=false" unless config.color?
80
+
81
+ flags.flatten
82
+ end
83
+
84
+ def run
85
+ FileUtils.mkdir_p config.puppetdir
86
+
87
+ FileUtils.rm_f config.logfile
88
+
89
+ FileUtils.rm_rf "#{config.puppetdir}/var/reports" if config.report?
90
+
91
+ FileUtils.rm_rf "#{config.puppetdir}/var/state/graphs" if config.graph?
92
+
93
+ FileUtils.mkdir_p File.dirname config.logfile
94
+ FileUtils.touch config.logfile
95
+
96
+ if File.file? "Puppetfile" and !config.skip_puppetfile?
97
+
98
+ librarian = "#{config.repodir}/bin/librarian-puppet"
99
+
100
+ unless config.enterprise?
101
+ # Set an environment variable for librarian-puppet's
102
+ # github_tarball source strategy.
103
+ ENV["GITHUB_API_TOKEN"] = config.token
104
+ end
105
+
106
+ librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
107
+ librarian_command << "--verbose" if config.debug?
108
+
109
+ warn librarian_command.join(" ") if config.debug?
110
+ unless system *librarian_command
111
+ abort "Can't run Puppet, fetching dependencies with librarian failed."
112
+ end
113
+ end
114
+
115
+ warn command.join(" ") if config.debug?
116
+
117
+ Boxen::Util.sudo *command
118
+
119
+ Status.new($?.exitstatus)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,149 @@
1
+ require "boxen/checkout"
2
+ require "boxen/config"
3
+ require "boxen/hook"
4
+ require "boxen/flags"
5
+ require "boxen/puppeteer"
6
+ require "boxen/service"
7
+ require "boxen/util"
8
+ require "facter"
9
+
10
+ module Boxen
11
+ class Runner
12
+ attr_reader :config
13
+ attr_reader :flags
14
+ attr_reader :puppet
15
+ attr_reader :checkout
16
+ attr_reader :hooks
17
+
18
+ def initialize(config, flags)
19
+ @config = config
20
+ @flags = flags
21
+ @puppet = Boxen::Puppeteer.new(@config)
22
+ @checkout = Boxen::Checkout.new(@config)
23
+ @hooks = Boxen::Hook.all
24
+ end
25
+
26
+ def process
27
+ # --env prints out the current BOXEN_ env vars.
28
+
29
+ exec "env | grep ^BOXEN_ | sort" if flags.env?
30
+
31
+ process_flags
32
+
33
+ process_args
34
+
35
+ # Actually run Puppet and return its result
36
+
37
+ puppet.run
38
+ end
39
+
40
+ def run
41
+ report(process)
42
+ end
43
+
44
+ def report(result)
45
+ hooks.each { |hook| hook.new(config, checkout, puppet, result).run }
46
+
47
+ result
48
+ end
49
+
50
+ def process_flags
51
+
52
+ # --projects prints a list of available projects and exits.
53
+
54
+ if flags.projects?
55
+ puts "You can install any of these projects with `#{$0} <project-name>`:\n"
56
+
57
+ config.projects.each do |project|
58
+ puts " #{project.name}"
59
+ end
60
+
61
+ exit
62
+ end
63
+
64
+ # --disable-services stops all services
65
+
66
+ if flags.disable_services?
67
+ Boxen::Service.list.each do |service|
68
+ puts "Disabling #{service}..."
69
+ service.disable
70
+ end
71
+
72
+ exit
73
+ end
74
+
75
+ # --enable-services starts all services
76
+
77
+ if flags.enable_services?
78
+ Boxen::Service.list.each do |service|
79
+ puts "Enabling #{service}..."
80
+ service.enable
81
+ end
82
+
83
+ exit
84
+ end
85
+
86
+ # --disable-service [name] stops a service
87
+
88
+ if flags.disable_service?
89
+ service = Boxen::Service.new(flags.disable_service)
90
+ puts "Disabling #{service}..."
91
+ service.disable
92
+
93
+ exit
94
+ end
95
+
96
+ # --enable-service [name] starts a service
97
+
98
+ if flags.enable_service?
99
+ service = Boxen::Service.new(flags.enable_service)
100
+ puts "Enabling #{service}..."
101
+ service.enable
102
+
103
+ exit
104
+ end
105
+
106
+ # --restart-service [name] starts a service
107
+
108
+ if flags.restart_service?
109
+ service = Boxen::Service.new(flags.restart_service)
110
+ puts "Restarting #{service}..."
111
+ service.disable
112
+ service.enable
113
+
114
+ exit
115
+ end
116
+
117
+ # --list-services lists all services
118
+
119
+ if flags.list_services?
120
+ Boxen::Service.list.each do |service|
121
+ puts service
122
+ end
123
+
124
+ exit
125
+ end
126
+
127
+ # --restart-services restarts all services
128
+
129
+ if flags.restart_services?
130
+ Boxen::Service.list_enabled.each do |service|
131
+ puts "Restarting #{service}..."
132
+ service.disable
133
+ service.enable
134
+ end
135
+
136
+ exit
137
+ end
138
+
139
+ end
140
+
141
+ def process_args
142
+ projects = flags.args.join(',')
143
+ File.open("#{config.repodir}/.projects", "w+") do |f|
144
+ f.truncate 0
145
+ f.write projects
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,58 @@
1
+ require "boxen/util"
2
+
3
+ module Boxen
4
+ class Service
5
+ attr_reader :name
6
+
7
+ def self.list
8
+ files.collect do |service|
9
+ new(human_name(service))
10
+ end
11
+ end
12
+
13
+ def self.list_enabled
14
+ prefix = /^dev\./
15
+ enabled = capture_output("sudo /bin/launchctl list").split("\n").map { |l| l.split(/\s/) }.map(&:last)
16
+ names = enabled.grep(prefix).map { |name| name.sub(prefix, "") }.compact
17
+ names.map { |name| new(name) }
18
+ end
19
+
20
+ def initialize(name)
21
+ @name = name
22
+ end
23
+
24
+ def to_s
25
+ name
26
+ end
27
+
28
+ def enable
29
+ Boxen::Util.sudo('/bin/launchctl', 'load', '-w', location)
30
+ end
31
+
32
+ def disable
33
+ Boxen::Util.sudo('/bin/launchctl', 'unload', '-w', location)
34
+ end
35
+
36
+ private
37
+
38
+ def self.capture_output(command)
39
+ `#{command}`
40
+ end
41
+
42
+ def location
43
+ "#{self.class.location}/dev.#{name}.plist"
44
+ end
45
+
46
+ def self.location
47
+ "/Library/LaunchDaemons"
48
+ end
49
+
50
+ def self.files
51
+ Dir["#{location}/dev.*.plist"]
52
+ end
53
+
54
+ def self.human_name(service)
55
+ service.match(/dev\.(.+)\.plist$/)[1]
56
+ end
57
+ end
58
+ end
data/lib/boxen/util.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Boxen
2
+ module Util
3
+
4
+ # Is Boxen active?
5
+ def self.active?
6
+ ENV.include? "BOXEN_HOME"
7
+ end
8
+
9
+ # Run `args` as a system command with sudo if necessary.
10
+ def self.sudo *args
11
+ system "sudo", "-p", "Password for sudo: ", *args
12
+ end
13
+
14
+ # Run on macos?
15
+ def self.osx?
16
+ RUBY_PLATFORM.downcase.include?('darwin')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require "json"
2
+ require "boxen/config"
3
+
4
+ config = Boxen::Config.load
5
+ facts = {}
6
+ factsdir = "#{config.homedir}/config/facts"
7
+ dot_boxen = "#{ENV['HOME']}/.boxen"
8
+ user_config = "#{dot_boxen}/config.json"
9
+
10
+ facts["github_login"] = config.login
11
+ facts["github_email"] = config.email
12
+ facts["github_name"] = config.name
13
+ facts["github_token"] = config.token
14
+
15
+ facts["boxen_home"] = config.homedir
16
+ facts["boxen_srcdir"] = config.srcdir
17
+ facts["boxen_repodir"] = config.repodir
18
+ facts["boxen_user"] = config.user
19
+ facts["luser"] = config.user # this is goin' away
20
+
21
+ Dir["#{config.homedir}/config/facts/*.json"].each do |file|
22
+ facts.merge! JSON.parse File.read file
23
+ end
24
+
25
+ if File.directory?(dot_boxen) && File.file?(user_config)
26
+ facts.merge! JSON.parse(File.read(user_config))
27
+ end
28
+
29
+ if File.file?(dot_boxen)
30
+ warn "DEPRECATION: ~/.boxen is deprecated and will be removed in 2.0; use ~/.boxen/config.json instead!"
31
+ facts.merge! JSON.parse(File.read(dot_boxen))
32
+ end
33
+
34
+ facts.each { |k, v| Facter.add(k) { setcode { v } } }
data/script/Boxen ADDED
Binary file
data/script/bootstrap ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Make sure local dependencies are satisfied.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ rm -f .bundle/config
7
+ bundle install --binstubs bin --path .bundle --quiet