r10k 0.0.9 → 1.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/bin/r10k +1 -1
  2. data/lib/r10k.rb +0 -4
  3. data/lib/r10k/cli.rb +9 -5
  4. data/lib/r10k/cli/deploy.rb +108 -0
  5. data/lib/r10k/cli/environment.rb +5 -1
  6. data/lib/r10k/cli/environment/deploy.rb +6 -28
  7. data/lib/r10k/cli/environment/list.rb +6 -10
  8. data/lib/r10k/cli/environment/stale.rb +6 -16
  9. data/lib/r10k/cli/module.rb +5 -1
  10. data/lib/r10k/cli/module/deploy.rb +5 -32
  11. data/lib/r10k/cli/module/list.rb +6 -27
  12. data/lib/r10k/cli/puppetfile.rb +76 -0
  13. data/lib/r10k/cli/synchronize.rb +8 -24
  14. data/lib/r10k/cli/version.rb +22 -0
  15. data/lib/r10k/deployment.rb +55 -26
  16. data/lib/r10k/deployment/config.rb +69 -0
  17. data/lib/r10k/{config → deployment/config}/loader.rb +9 -5
  18. data/lib/r10k/deployment/environment.rb +88 -0
  19. data/lib/r10k/deployment/source.rb +79 -0
  20. data/lib/r10k/errors.rb +3 -5
  21. data/lib/r10k/execution.rb +43 -0
  22. data/lib/r10k/git/cache.rb +131 -0
  23. data/lib/r10k/git/errors.rb +34 -0
  24. data/lib/r10k/git/repository.rb +74 -0
  25. data/lib/r10k/git/working_dir.rb +142 -0
  26. data/lib/r10k/logging.rb +6 -2
  27. data/lib/r10k/module.rb +10 -13
  28. data/lib/r10k/module/forge.rb +35 -22
  29. data/lib/r10k/module/git.rb +18 -8
  30. data/lib/r10k/puppetfile.rb +107 -0
  31. data/lib/r10k/task.rb +13 -0
  32. data/lib/r10k/task/deployment.rb +151 -0
  33. data/lib/r10k/task/environment.rb +29 -0
  34. data/lib/r10k/task/module.rb +18 -0
  35. data/lib/r10k/task/puppetfile.rb +99 -0
  36. data/lib/r10k/task_runner.rb +72 -0
  37. data/lib/r10k/util/purgeable.rb +50 -0
  38. data/lib/r10k/version.rb +1 -1
  39. data/spec/unit/deployment/environment_spec.rb +19 -0
  40. data/spec/unit/git/cache_spec.rb +37 -0
  41. data/spec/unit/git/working_dir_spec.rb +15 -0
  42. data/spec/unit/module/forge_spec.rb +95 -0
  43. data/spec/unit/module_spec.rb +29 -0
  44. metadata +79 -44
  45. data/lib/r10k/action.rb +0 -7
  46. data/lib/r10k/action/environment.rb +0 -74
  47. data/lib/r10k/action/module.rb +0 -36
  48. data/lib/r10k/cli/cache.rb +0 -32
  49. data/lib/r10k/config.rb +0 -46
  50. data/lib/r10k/deployment/environment_collection.rb +0 -75
  51. data/lib/r10k/librarian.rb +0 -31
  52. data/lib/r10k/librarian/dsl.rb +0 -20
  53. data/lib/r10k/root.rb +0 -98
  54. data/lib/r10k/synchro/git.rb +0 -226
data/bin/r10k CHANGED
@@ -11,7 +11,7 @@ rescue Interrupt
11
11
  rescue SystemExit => e
12
12
  exit(e.status)
13
13
  rescue Exception => e
14
- $stderr.puts "\nRuntime error: #{e.inspect}".red
14
+ $stderr.puts "\nError while running: #{e.inspect}".red
15
15
  $stderr.puts e.backtrace.join("\n").red if ARGV.include? '--trace'
16
16
  exit(1)
17
17
  end
data/lib/r10k.rb CHANGED
@@ -1,7 +1,3 @@
1
1
  module R10K; end
2
2
 
3
- require 'r10k/root'
4
- require 'r10k/synchro/git'
5
- require 'r10k/librarian'
6
3
  require 'r10k/version'
7
- require 'r10k/logging'
data/lib/r10k/cli.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'r10k'
2
2
  require 'r10k/logging'
3
+ require 'r10k/version'
3
4
  require 'r10k/cli/ext/logging'
5
+
4
6
  require 'cri'
5
7
 
6
8
  module R10K::CLI
@@ -19,16 +21,16 @@ module R10K::CLI
19
21
  exit 0
20
22
  end
21
23
 
22
- required :c, :config, 'Specify a configuration file' do |value, cmd|
23
- R10K::Deployment.config.configfile = value
24
- end
25
-
26
24
  required :v, :verbose, 'Set verbosity level' do |value, cmd|
27
25
  R10K::Logging.level = Integer(value)
28
26
  end
29
27
 
30
28
  flag :t, :trace, 'Display stack traces on application crash'
31
29
 
30
+ required :c, :config, 'Specify a configuration file' do |value, cmd|
31
+ logger.warn "Calling `r10k --config <action>` as a global option is deprecated; use r10k <action> --config"
32
+ end
33
+
32
34
  run do |opts, args, cmd|
33
35
  puts cmd.help
34
36
  exit 0
@@ -37,7 +39,9 @@ module R10K::CLI
37
39
  end
38
40
  end
39
41
 
42
+ require 'r10k/cli/deploy'
40
43
  require 'r10k/cli/environment'
41
44
  require 'r10k/cli/module'
42
- require 'r10k/cli/cache'
43
45
  require 'r10k/cli/synchronize'
46
+ require 'r10k/cli/puppetfile'
47
+ require 'r10k/cli/version'
@@ -0,0 +1,108 @@
1
+ require 'r10k/cli'
2
+ require 'r10k/deployment'
3
+ require 'r10k/deployment/config'
4
+
5
+ require 'r10k/task_runner'
6
+ require 'r10k/task/deployment'
7
+
8
+ require 'cri'
9
+
10
+ module R10K::CLI
11
+ module Deploy
12
+ def self.command
13
+ @cmd ||= Cri::Command.define do
14
+ name 'deploy'
15
+ usage 'deploy <subcommand>'
16
+ summary 'Puppet dynamic environment deployment'
17
+
18
+ required :c, :config, 'Specify a configuration file'
19
+
20
+ run do |opts, args, cmd|
21
+ puts cmd.help
22
+ exit 0
23
+ end
24
+ end
25
+ end
26
+
27
+ module Environment
28
+ def self.command
29
+ @cmd ||= Cri::Command.define do
30
+ name 'environment'
31
+ usage 'environment <options> <environment> <...>'
32
+ summary 'deploy environments and their dependent modules'
33
+
34
+ flag :p, :puppetfile, 'Deploy modules from a puppetfile'
35
+
36
+ run do |opts, args, cmd|
37
+ deploy = R10K::Deployment.load_config(opts[:config])
38
+
39
+ task = R10K::Task::Deployment::DeployEnvironments.new(deploy)
40
+ task.update_puppetfile = opts[:puppetfile]
41
+ task.environment_names = args
42
+
43
+ purge = R10K::Task::Deployment::PurgeEnvironments.new(deploy)
44
+
45
+ runner = R10K::TaskRunner.new(:trace => opts[:trace])
46
+ runner.append_task task
47
+ runner.append_task purge
48
+ runner.run
49
+
50
+ exit runner.exit_value
51
+ end
52
+ end
53
+ end
54
+ end
55
+ self.command.add_command(Environment.command)
56
+
57
+ module Module
58
+ def self.command
59
+ @cmd ||= Cri::Command.define do
60
+ name 'module'
61
+ usage 'module [module] <module ...>'
62
+ summary 'deploy modules in all environments'
63
+
64
+ run do |opts, args, cmd|
65
+ deploy = R10K::Deployment.load_config(opts[:config])
66
+
67
+ task = R10K::Task::Deployment::DeployModules.new(deploy)
68
+ task.module_names = args
69
+
70
+ runner = R10K::TaskRunner.new(:trace => opts[:trace])
71
+ runner.append_task task
72
+ runner.run
73
+
74
+ exit runner.exit_value
75
+ end
76
+ end
77
+ end
78
+ end
79
+ self.command.add_command(Module.command)
80
+
81
+ module Display
82
+ def self.command
83
+ @cmd ||= Cri::Command.define do
84
+ name 'display'
85
+ usage 'display'
86
+ summary 'Display environments and modules in the deployment'
87
+
88
+ flag :p, :puppetfile, 'Display Puppetfile modules'
89
+
90
+ run do |opts, args, cmd|
91
+ deploy = R10K::Deployment.load_config(opts[:config])
92
+
93
+ task = R10K::Task::Deployment::Display.new(deploy)
94
+ task.puppetfile = opts[:puppetfile]
95
+
96
+ runner = R10K::TaskRunner.new(:trace => opts[:trace])
97
+ runner.prepend_task task
98
+ runner.run
99
+
100
+ exit runner.exit_value
101
+ end
102
+ end
103
+ end
104
+ end
105
+ self.command.add_command(Display.command)
106
+ end
107
+ self.command.add_command(Deploy.command)
108
+ end
@@ -7,7 +7,11 @@ module R10K::CLI
7
7
  @cmd ||= Cri::Command.define do
8
8
  name 'environment'
9
9
  usage 'environment <subcommand>'
10
- summary 'Operate on a specific environment'
10
+ summary 'DEPRECATED: Operate on a specific environment'
11
+
12
+ required :c, :config, 'Specify a configuration file'
13
+
14
+ be_hidden
11
15
 
12
16
  run do |opts, args, cmd|
13
17
  puts cmd.help
@@ -1,9 +1,6 @@
1
1
  require 'r10k/cli/environment'
2
- require 'r10k/deployment'
3
- require 'r10k/action'
4
-
2
+ require 'r10k/cli/deploy'
5
3
  require 'cri'
6
- require 'middleware'
7
4
 
8
5
  module R10K::CLI::Environment
9
6
  module Deploy
@@ -11,35 +8,16 @@ module R10K::CLI::Environment
11
8
  @cmd ||= Cri::Command.define do
12
9
  name 'deploy'
13
10
  usage 'deploy <environment> <...>'
14
- summary 'Deploy an environment'
11
+ summary 'DEPRECATED: Deploy an environment'
15
12
 
16
13
  flag :r, :recurse, 'Recursively update submodules'
17
14
  flag :u, :update, "Enable or disable cache updating"
18
15
 
19
- run do |opts, args, cmd|
20
- deployment = R10K::Deployment.instance
21
- env_list = deployment.environments
22
-
23
- if not args.empty?
24
- environments = env_list.select {|env| args.include? env.name }
25
- else
26
- environments = env_list
27
- end
16
+ be_hidden
28
17
 
29
- stack = Middleware::Builder.new do
30
- environments.each do |env|
31
- use R10K::Action::Environment::Deploy, env
32
- end
33
- end
34
-
35
- # Prepare middleware environment
36
- stack_env = {
37
- :update_cache => opts[:update],
38
- :recurse => opts[:recurse],
39
- :trace => opts[:trace],
40
- }
41
-
42
- stack.call(stack_env)
18
+ run do |opts, args, cmd|
19
+ logger.warn "This command is deprecated; please use `r10k deploy environment`"
20
+ R10K::CLI::Deploy::Environment.command.block.call(opts,args,cmd)
43
21
  end
44
22
  end
45
23
  end
@@ -1,5 +1,5 @@
1
1
  require 'r10k/cli/environment'
2
- require 'r10k/deployment'
2
+ require 'r10k/cli/deploy'
3
3
  require 'cri'
4
4
 
5
5
  module R10K::CLI::Environment
@@ -8,17 +8,13 @@ module R10K::CLI::Environment
8
8
  @cmd ||= Cri::Command.define do
9
9
  name 'list'
10
10
  usage 'list'
11
- summary 'List all available environments'
11
+ summary 'DEPRECATED: List all available environments'
12
12
 
13
- run do |opts, args, cmd|
14
- deployment = R10K::Deployment.instance
15
- output = deployment.environments.inject('') do |str, root|
16
- str << " - "
17
- str << "#{root.name}: #{root.full_path}"
18
- str << "\n"
19
- end
13
+ be_hidden
20
14
 
21
- puts output
15
+ run do |opts, args, cmd|
16
+ logger.warn "This command is deprecated; please use `r10k deploy display`"
17
+ R10K::CLI::Deploy::Display.command.block.call(opts,args,cmd)
22
18
  end
23
19
  end
24
20
  end
@@ -8,24 +8,14 @@ module R10K::CLI::Environment
8
8
  @cmd ||= Cri::Command.define do
9
9
  name 'stale'
10
10
  usage 'stale <directory> [directory ...]'
11
- summary 'List all stale environments'
11
+ summary 'REMOVED: List all stale environments'
12
12
 
13
- run do |opts, args, cmd|
14
- deployment = R10K::Deployment.instance
15
-
16
- if args.empty?
17
- $stderr.print "ERROR: ".red
18
- $stderr.puts "#{cmd.name} requires one or more directories"
19
- $stderr.puts cmd.help
20
- exit(1)
21
- end
13
+ description "This command has been removed in 1.0.0"
14
+ be_hidden
22
15
 
23
- args.each do |dir|
24
- puts "Stale environments in #{dir}:"
25
- output = deployment.collection.stale(dir).each do |stale_dir|
26
- puts " - #{stale_dir}"
27
- end
28
- end
16
+ run do |opts, args, cmd|
17
+ $stderr.puts "#{cmd.name} has been removed in 1.0.0"
18
+ exit 1
29
19
  end
30
20
  end
31
21
  end
@@ -7,7 +7,11 @@ module R10K::CLI
7
7
  @cmd ||= Cri::Command.define do
8
8
  name 'module'
9
9
  usage 'module <subcommand>'
10
- summary 'Operate on a specific puppet module'
10
+ summary 'DEPRECATED: Operate on a specific puppet module'
11
+
12
+ be_hidden
13
+
14
+ required :c, :config, 'Specify a configuration file'
11
15
 
12
16
  required :e, :environment, 'Specify a particular environment'
13
17
 
@@ -11,42 +11,15 @@ module R10K::CLI::Module
11
11
  @cmd ||= Cri::Command.define do
12
12
  name 'deploy'
13
13
  usage 'deploy [module name] <module name> ...'
14
- summary 'Deploy a module'
14
+ summary 'DEPRECATED: Deploy a module'
15
+
16
+ be_hidden
15
17
 
16
18
  flag :u, :update, "Update module cache"
17
19
 
18
20
  run do |opts, args, cmd|
19
-
20
- unless (module_name = args[0])
21
- puts cmd.help
22
- exit 1
23
- end
24
-
25
- env_list = R10K::Deployment.instance.environments
26
-
27
- if opts[:environment]
28
- environments = env_list.select {|env| env.name == opts[:environment]}
29
- else
30
- environments = env_list
31
- end
32
-
33
- environments.each do |env|
34
- mods = env.modules.select { |mod| mod.name == module_name }
35
-
36
- if mods.empty?
37
- logger.warn "No modules with name #{module_name} matched in environment #{env.name.inspect}".red
38
- end
39
-
40
- stack = Middleware::Builder.new
41
- mods.each { |mod| stack.use R10K::Action::Module::Deploy, mod }
42
-
43
- stack_env = {
44
- :update_cache => opts[:update],
45
- :trace => opts[:trace],
46
- }
47
-
48
- stack.call(stack_env)
49
- end
21
+ logger.warn "This command is deprecated; please use `r10k deploy module`"
22
+ R10K::CLI::Deploy::Module.command.block.call(opts,args,cmd)
50
23
  end
51
24
  end
52
25
  end
@@ -1,5 +1,5 @@
1
1
  require 'r10k/cli/module'
2
- require 'r10k/deployment'
2
+ require 'r10k/cli/deploy'
3
3
  require 'cri'
4
4
 
5
5
  module R10K::CLI::Module
@@ -8,34 +8,13 @@ module R10K::CLI::Module
8
8
  @cmd ||= Cri::Command.define do
9
9
  name 'list'
10
10
  usage 'list'
11
- summary 'List modules that are instantiated in environments'
11
+ summary 'DEPRECATED: List modules that are instantiated in environments'
12
12
 
13
- run do |opts, args, cmd|
14
- deployment = R10K::Deployment.instance
15
- env_list = deployment.environments
16
-
17
- update_cache = (defined? opts[:update]) ? (opts[:update] == 'true') : false
18
-
19
- if opts[:environment]
20
- environments = env_list.select {|env| env.name == opts[:environment]}
21
- else
22
- environments = env_list
23
- end
24
-
25
- printree = {}
13
+ be_hidden
26
14
 
27
- environments.each do |env|
28
- module_names = env.modules.map(&:name)
29
-
30
- printree[env.name] = module_names
31
- end
32
-
33
- printree.each_pair do |env_name, mod_list|
34
- puts " - #{env_name}"
35
- mod_list.each do |mod|
36
- puts " #{mod}"
37
- end
38
- end
15
+ run do |opts, args, cmd|
16
+ logger.warn "This command is deprecated; please use `r10k deploy display`"
17
+ R10K::CLI::Deploy::Display.command.block.call(opts,args,cmd)
39
18
  end
40
19
  end
41
20
  end
@@ -0,0 +1,76 @@
1
+ require 'r10k/cli'
2
+ require 'r10k/puppetfile'
3
+
4
+ require 'cri'
5
+
6
+ module R10K::CLI
7
+ module Puppetfile
8
+ def self.command
9
+ @cmd ||= Cri::Command.define do
10
+ name 'puppetfile'
11
+ usage 'puppetfile <subcommand>'
12
+ summary 'Perform operations on a Puppetfile'
13
+
14
+ run do |opts, args, cmd|
15
+ puts cmd.help
16
+ exit 0
17
+ end
18
+ end
19
+ end
20
+
21
+ module Install
22
+ def self.command
23
+ @cmd ||= Cri::Command.define do
24
+ name 'install'
25
+ usage 'install'
26
+ summary 'Install all modules from a Puppetfile'
27
+
28
+ run do |opts, args, cmd|
29
+ puppetfile_root = Dir.getwd
30
+ puppetfile_path = ENV['PUPPETFILE_DIR']
31
+ puppetfile = ENV['PUPPETFILE']
32
+
33
+ puppetfile = R10K::Puppetfile.new(puppetfile_root, puppetfile_path, puppetfile)
34
+
35
+ runner = R10K::TaskRunner.new(opts)
36
+ task = R10K::Task::Puppetfile::Sync.new(puppetfile)
37
+ runner.append_task task
38
+
39
+ runner.run
40
+
41
+ exit runner.exit_value
42
+ end
43
+ end
44
+ end
45
+ end
46
+ self.command.add_command(Install.command)
47
+
48
+ module Purge
49
+ def self.command
50
+ @cmd ||= Cri::Command.define do
51
+ name 'purge'
52
+ usage 'purge'
53
+ summary 'Purge unmanaged modules from a Puppetfile managed directory'
54
+
55
+ run do |opts, args, cmd|
56
+ puppetfile_root = Dir.getwd
57
+ puppetfile_path = ENV['PUPPETFILE_DIR']
58
+ puppetfile = ENV['PUPPETFILE']
59
+
60
+ puppetfile = R10K::Puppetfile.new(puppetfile_root, puppetfile_path, puppetfile)
61
+
62
+ runner = R10K::TaskRunner.new(opts)
63
+ task = R10K::Task::Puppetfile::Purge.new(puppetfile)
64
+ runner.append_task task
65
+
66
+ runner.run
67
+
68
+ exit runner.exit_value
69
+ end
70
+ end
71
+ end
72
+ end
73
+ self.command.add_command(Purge.command)
74
+ end
75
+ self.command.add_command(Puppetfile.command)
76
+ end