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
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'r10k/module'
3
+
4
+ describe R10K::Module do
5
+ describe 'delegating to R10K::Module::Git' do
6
+ it "accepts args {:git => 'git url}" do
7
+ obj = R10K::Module.new('foo', '/modulepath', :git => 'git url')
8
+ obj.should be_a_kind_of R10K::Module::Git
9
+ end
10
+ end
11
+
12
+ describe 'delegating to R10K::Module::Git' do
13
+ it "accepts name matching 'username/modulename' and no args" do
14
+ obj = R10K::Module.new('bar/quux', '/modulepath', [])
15
+ obj.should be_a_kind_of R10K::Module::Forge
16
+ end
17
+
18
+ it "accepts name matching 'username/modulename' and a semver argument" do
19
+ obj = R10K::Module.new('bar/quux', '/modulepath', '10.0.0')
20
+ obj.should be_a_kind_of R10K::Module::Forge
21
+ end
22
+ end
23
+
24
+ it "raises an error if delegation fails" do
25
+ expect {
26
+ R10K::Module.new('bar-quux', '/modulepath', ["NOPE NOPE NOPE NOPE!"])
27
+ }.to raise_error RuntimeError, /doesn't have an implementation/
28
+ end
29
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
5
- prerelease:
4
+ version: 1.0.0rc1
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adrien Thebo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -60,53 +60,69 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.5.2
62
62
  - !ruby/object:Gem::Dependency
63
- name: middleware
63
+ name: log4r
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.1.0
69
+ version: 1.1.10
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.1.0
77
+ version: 1.1.10
78
78
  - !ruby/object:Gem::Dependency
79
- name: json
79
+ name: json_pure
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ~>
83
+ - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: 1.7.6
85
+ version: '0'
86
86
  type: :runtime
87
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: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.10.0
102
+ type: :development
103
+ prerelease: false
88
104
  version_requirements: !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
107
  - - ~>
92
108
  - !ruby/object:Gem::Version
93
- version: 1.7.6
109
+ version: 2.10.0
94
110
  - !ruby/object:Gem::Dependency
95
- name: log4r
111
+ name: mocha
96
112
  requirement: !ruby/object:Gem::Requirement
97
113
  none: false
98
114
  requirements:
99
- - - ! '>='
115
+ - - ~>
100
116
  - !ruby/object:Gem::Version
101
- version: 1.1.10
102
- type: :runtime
117
+ version: 0.10.5
118
+ type: :development
103
119
  prerelease: false
104
120
  version_requirements: !ruby/object:Gem::Requirement
105
121
  none: false
106
122
  requirements:
107
- - - ! '>='
123
+ - - ~>
108
124
  - !ruby/object:Gem::Version
109
- version: 1.1.10
125
+ version: 0.10.5
110
126
  description: ! " R10K is an implementation of the Dynamic Puppet environments based
111
127
  on git repositories\n as described in http://puppetlabs.com/blog/git-workflow-and-puppet-environments/.
112
128
  It\n aggressively caches and tries to minimize network activity to ensure that
@@ -118,37 +134,51 @@ extensions: []
118
134
  extra_rdoc_files: []
119
135
  files:
120
136
  - bin/r10k
121
- - lib/r10k/action/environment.rb
122
- - lib/r10k/action/module.rb
123
- - lib/r10k/action.rb
124
- - lib/r10k/cli/cache.rb
125
- - lib/r10k/cli/environment/deploy.rb
137
+ - lib/r10k.rb
138
+ - lib/r10k/errors.rb
139
+ - lib/r10k/logging.rb
140
+ - lib/r10k/deployment.rb
141
+ - lib/r10k/git/errors.rb
142
+ - lib/r10k/git/cache.rb
143
+ - lib/r10k/git/working_dir.rb
144
+ - lib/r10k/git/repository.rb
145
+ - lib/r10k/cli.rb
146
+ - lib/r10k/module.rb
147
+ - lib/r10k/task_runner.rb
148
+ - lib/r10k/execution.rb
149
+ - lib/r10k/puppetfile.rb
150
+ - lib/r10k/deployment/environment.rb
151
+ - lib/r10k/deployment/config/loader.rb
152
+ - lib/r10k/deployment/config.rb
153
+ - lib/r10k/deployment/source.rb
154
+ - lib/r10k/util/purgeable.rb
155
+ - lib/r10k/util/interp.rb
156
+ - lib/r10k/cli/environment.rb
126
157
  - lib/r10k/cli/environment/list.rb
158
+ - lib/r10k/cli/environment/deploy.rb
127
159
  - lib/r10k/cli/environment/stale.rb
128
- - lib/r10k/cli/environment.rb
129
- - lib/r10k/cli/ext/logging.rb
130
- - lib/r10k/cli/module/deploy.rb
131
- - lib/r10k/cli/module/list.rb
132
160
  - lib/r10k/cli/module.rb
133
161
  - lib/r10k/cli/synchronize.rb
134
- - lib/r10k/cli.rb
135
- - lib/r10k/config/loader.rb
136
- - lib/r10k/config.rb
137
- - lib/r10k/deployment/environment_collection.rb
138
- - lib/r10k/deployment.rb
139
- - lib/r10k/errors.rb
140
- - lib/r10k/librarian/dsl.rb
141
- - lib/r10k/librarian.rb
142
- - lib/r10k/logging.rb
162
+ - lib/r10k/cli/puppetfile.rb
163
+ - lib/r10k/cli/deploy.rb
164
+ - lib/r10k/cli/ext/logging.rb
165
+ - lib/r10k/cli/module/list.rb
166
+ - lib/r10k/cli/module/deploy.rb
167
+ - lib/r10k/cli/version.rb
168
+ - lib/r10k/task/environment.rb
169
+ - lib/r10k/task/deployment.rb
170
+ - lib/r10k/task/module.rb
171
+ - lib/r10k/task/puppetfile.rb
172
+ - lib/r10k/task.rb
143
173
  - lib/r10k/module/forge.rb
144
174
  - lib/r10k/module/git.rb
145
- - lib/r10k/module.rb
146
- - lib/r10k/root.rb
147
- - lib/r10k/synchro/git.rb
148
- - lib/r10k/util/interp.rb
149
175
  - lib/r10k/version.rb
150
- - lib/r10k.rb
151
176
  - lib/semver.rb
177
+ - spec/unit/module_spec.rb
178
+ - spec/unit/git/working_dir_spec.rb
179
+ - spec/unit/git/cache_spec.rb
180
+ - spec/unit/deployment/environment_spec.rb
181
+ - spec/unit/module/forge_spec.rb
152
182
  homepage: http://github.com/adrienthebo/r10k
153
183
  licenses: []
154
184
  post_install_message:
@@ -164,13 +194,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
194
  required_rubygems_version: !ruby/object:Gem::Requirement
165
195
  none: false
166
196
  requirements:
167
- - - ! '>='
197
+ - - ! '>'
168
198
  - !ruby/object:Gem::Version
169
- version: '0'
199
+ version: 1.3.1
170
200
  requirements: []
171
201
  rubyforge_project:
172
202
  rubygems_version: 1.8.23
173
203
  signing_key:
174
204
  specification_version: 3
175
205
  summary: Dynamic Puppet environments with Git
176
- test_files: []
206
+ test_files:
207
+ - spec/unit/module_spec.rb
208
+ - spec/unit/git/working_dir_spec.rb
209
+ - spec/unit/git/cache_spec.rb
210
+ - spec/unit/deployment/environment_spec.rb
211
+ - spec/unit/module/forge_spec.rb
data/lib/r10k/action.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'r10k'
2
-
3
- module R10K::Action
4
- end
5
-
6
- require 'r10k/action/module'
7
- require 'r10k/action/environment'
@@ -1,74 +0,0 @@
1
- require 'r10k/action'
2
- require 'r10k/errors'
3
- require 'r10k/action/module'
4
- require 'r10k/deployment'
5
- require 'r10k/logging'
6
-
7
- require 'middleware'
8
-
9
- module R10K::Action::Environment
10
-
11
- class Deploy
12
- # Middleware action to deploy an environment
13
-
14
- include R10K::Logging
15
-
16
- # @param [Object] app The next application in the middlware stack
17
- # @param [R10K::Module] mod The module to deploy
18
- def initialize(app, root)
19
- @app, @root = app, root
20
- end
21
-
22
- # @param [Hash] env
23
- #
24
- # @option env [true, false] :update_cache
25
- # @option env [true, false] :recurse
26
- # @option env [true, false] :trace
27
- def call(env)
28
- @env = env
29
-
30
- logger.info "Deploying environment #{@root.name}"
31
- FileUtils.mkdir_p @root.full_path
32
- @root.sync! :update_cache => @env[:update_cache]
33
-
34
- if @env[:recurse]
35
- # Build a new middleware chain and run it
36
- stack = Middleware::Builder.new
37
- @root.modules.each { |mod| stack.use R10K::Action::Module::Deploy, mod }
38
- stack.call(@env)
39
- end
40
-
41
- @app.call(@env)
42
- rescue R10K::ExecutionFailure => e
43
- logger.error "Could not synchronize #{@root.full_path}: #{e}".red
44
- $stderr.puts e.backtrace.join("\n").red if @env[:trace]
45
- @app.call(@env)
46
- end
47
- end
48
-
49
- class Purge
50
- # Middleware action to purge stale environments from a directory
51
-
52
- include R10K::Logging
53
-
54
- # @param [Object] app The next application in the middlware stack
55
- # @param [String] path The directory path to purge
56
- def initialize(app, path)
57
- @app, @path = app, path
58
- end
59
-
60
- # @param [Hash] env
61
- def call(env)
62
- @env = env
63
-
64
- stale_directories = R10K::Deployment.collection.stale(@path)
65
-
66
- stale_directories.each do |dir|
67
- logger.info "Purging stale environment #{dir.inspect}"
68
- FileUtils.rm_rf(dir, :secure => true)
69
- end
70
-
71
- @app.call(@env)
72
- end
73
- end
74
- end
@@ -1,36 +0,0 @@
1
- require 'r10k/action'
2
- require 'r10k/errors'
3
- require 'r10k/logging'
4
-
5
- require 'middleware'
6
-
7
- module R10K::Action::Module
8
-
9
- class R10K::Action::Module::Deploy
10
- # Middleware to deploy a module
11
-
12
- include R10K::Logging
13
-
14
- # @param [Object] app The next application in the middlware stack
15
- # @param [R10K::Module] mod The module to deploy
16
- def initialize(app, mod)
17
- @app, @mod = app, mod
18
- end
19
-
20
- # @param [Hash] env
21
- #
22
- # @option env [true, false] :update_cache
23
- def call(env)
24
- @env = env
25
-
26
- logger.info "Deploying module #{@mod.name}"
27
- @mod.sync! :update_cache => @env[:update_cache]
28
-
29
- @app.call(@env)
30
- rescue R10K::ExecutionFailure => e
31
- logger.error "Could not synchronize #{@mod.full_path}: #{e}".red
32
- $stderr.puts e.backtrace.join("\n").red if @env[:trace]
33
- @app.call(@env)
34
- end
35
- end
36
- end
@@ -1,32 +0,0 @@
1
- require 'r10k/cli'
2
- require 'r10k/synchro/git'
3
- require 'cri'
4
- require 'r10k/logging'
5
-
6
- module R10K::CLI
7
- module Cache
8
- def self.command
9
- @cmd ||= Cri::Command.define do
10
- name 'cache'
11
- usage 'cache'
12
- summary 'Update cache for all sources'
13
-
14
- run do |opts, args, cmd|
15
- sources = R10K::Deployment.config[:sources]
16
- remotes = Set.new
17
-
18
- sources.each_pair do |name, hash|
19
- remotes << hash['remote']
20
- end
21
-
22
- remotes.each do |remote|
23
- logger.info "Updating cache for #{remote.inspect}"
24
- synchro = R10K::Synchro::Git.new(remote)
25
- synchro.cache
26
- end
27
- end
28
- end
29
- end
30
- end
31
- self.command.add_command(Cache.command)
32
- end
data/lib/r10k/config.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'r10k/deployment'
2
- require 'r10k/config/loader'
3
-
4
- class R10K::Config
5
-
6
- attr_accessor :configfile
7
-
8
- def loaded?
9
- !(@config.nil?)
10
- end
11
-
12
- # Serve up the loaded config if it's already been loaded, otherwise try to
13
- # load a config in the current wd.
14
- def dump
15
- load_config unless @config
16
- @config
17
- end
18
-
19
- def setting(key)
20
- self.dump[key]
21
- end
22
- alias_method :[], :setting
23
-
24
- # Load and store a config file, and set relevant options
25
- #
26
- # @param [String] configfile The path to the YAML config file
27
- def load_config
28
- unless @configfile
29
- loader = R10K::Config::Loader.new
30
- @configfile = loader.search
31
- end
32
- File.open(@configfile) { |fh| @config = YAML.load(fh.read) }
33
- apply_config_settings
34
- @config
35
- end
36
-
37
- private
38
-
39
- # Apply config settings to the relevant classes after a config has been loaded.
40
- def apply_config_settings
41
- if @config[:cachedir]
42
- R10K::Synchro::Git.cache_root = @config[:cachedir]
43
- end
44
- @collection = R10K::Deployment::EnvironmentCollection.new(@config)
45
- end
46
- end
@@ -1,75 +0,0 @@
1
- require 'r10k'
2
- require 'r10k/logging'
3
-
4
- class R10K::Deployment::EnvironmentCollection
5
-
6
- include R10K::Logging
7
-
8
- attr_reader :update_cache
9
-
10
- def initialize(config, options = {:update_cache => true})
11
- @config = config
12
- @environments = []
13
-
14
- @update_cache = options.delete(:update_cache)
15
- load_all
16
- end
17
-
18
- def current(basedir)
19
- basedir = File.expand_path(basedir)
20
- tracked_envs = @environments.select do |env|
21
- envdir = File.expand_path(env.basedir)
22
- envdir == basedir
23
- end
24
- end
25
-
26
- # List subdirectories that aren't associated with an env
27
- #
28
- # If a branch associated with an environment is deleted then the associated
29
- # branch ceases to be tracked. This method will scan a directory for
30
- # subdirectories and return any subdirectories that don't have an active
31
- # branch associated.
32
- #
33
- # @param [String] basedir The directory to scan
34
- #
35
- # @return [Array<String>] A list of filenames
36
- def stale(basedir)
37
- basedir = File.expand_path(basedir)
38
-
39
- all_dirs = Dir.glob("#{basedir}/*").map do |file|
40
- File.basename(file) if File.directory?(file)
41
- end.compact
42
- current_dirs = current(basedir).map(&:name)
43
-
44
- stale_dirs = all_dirs - current_dirs
45
-
46
- stale_dirs.map {|dir| File.join(basedir, dir)}
47
- end
48
-
49
- # @return [Array<R10K::Root>]
50
- def to_a
51
- @environments
52
- end
53
-
54
- private
55
-
56
- def load_all
57
- @config[:sources].each_pair do |repo_name, repo_config|
58
- synchro = R10K::Synchro::Git.new(repo_config['remote'])
59
- if @update_cache
60
- logger.info "Updating git cache for #{repo_config['remote']}"
61
- synchro.cache
62
- end
63
-
64
- if repo_config['ref']
65
- @environments << R10K::Root.new(repo_config)
66
- else
67
- synchro.branches.each do |branch|
68
- @environments << R10K::Root.new(repo_config.merge({'ref' => branch}))
69
- end
70
- end
71
- end
72
-
73
- @environments
74
- end
75
- end