r10k 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ module R10K::Action::Environment
27
27
  def call(env)
28
28
  @env = env
29
29
 
30
- logger.notice "Deploying environment #{@root.name}"
30
+ logger.info "Deploying environment #{@root.name}"
31
31
  FileUtils.mkdir_p @root.full_path
32
32
  @root.sync! :update_cache => @env[:update_cache]
33
33
 
@@ -61,10 +61,10 @@ module R10K::Action::Environment
61
61
  def call(env)
62
62
  @env = env
63
63
 
64
- stale_directories = R10K::Deployment.instance.collection.stale(@path)
64
+ stale_directories = R10K::Deployment.collection.stale(@path)
65
65
 
66
66
  stale_directories.each do |dir|
67
- logger.notice "Purging stale environment #{dir.inspect}"
67
+ logger.info "Purging stale environment #{dir.inspect}"
68
68
  FileUtils.rm_rf(dir, :secure => true)
69
69
  end
70
70
 
@@ -23,7 +23,7 @@ module R10K::Action::Module
23
23
  def call(env)
24
24
  @env = env
25
25
 
26
- logger.notice "Deploying module #{@mod.name}"
26
+ logger.info "Deploying module #{@mod.name}"
27
27
  @mod.sync! :update_cache => @env[:update_cache]
28
28
 
29
29
  @app.call(@env)
@@ -19,7 +19,7 @@ module R10K::CLI
19
19
  end
20
20
 
21
21
  required :c, :config, 'Specify a configuration file' do |value, cmd|
22
- R10K::Deployment.instance.configfile = value
22
+ R10K::Deployment.config.configfile = value
23
23
  end
24
24
 
25
25
  required :v, :verbose, 'Set verbosity level' do |value, cmd|
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,39 @@
1
+ require 'r10k'
2
+
3
+ class R10K::Config
4
+ end
5
+
6
+ class R10K::Config::Loader
7
+
8
+ def initialize
9
+ @loadpath = []
10
+
11
+ populate_loadpath
12
+ end
13
+
14
+ # @return [String] The path to the first valid configfile
15
+ def search
16
+ first = @loadpath.find {|filename| File.file? filename}
17
+ end
18
+
19
+ private
20
+
21
+ def populate_loadpath
22
+
23
+ # Scan all parent directories for r10k
24
+ dir_components = Dir.getwd.split(File::SEPARATOR)
25
+
26
+ dir_components.each_with_index do |dirname, index|
27
+ full_path = [''] # Shim case for root directory
28
+ full_path << dir_components[0...index]
29
+ full_path << dirname << 'r10k.yaml'
30
+
31
+ @loadpath << File.join(full_path)
32
+ end
33
+
34
+ # Always check /etc/r10k.yaml
35
+ @loadpath << '/etc/r10k.yaml'
36
+
37
+ @loadpath
38
+ end
39
+ end
@@ -1,21 +1,37 @@
1
1
  require 'r10k'
2
+ require 'r10k/config'
2
3
  require 'r10k/synchro/git'
3
- require 'r10k/deployment/environment_collection'
4
4
  require 'yaml'
5
5
 
6
6
  class R10K::Deployment
7
7
  # Model a full installation of module directories and modules.
8
8
 
9
- def self.instance
10
- @myself ||= self.new
9
+ class << self
10
+ def instance
11
+ @myself ||= self.new
12
+ end
13
+
14
+ def config
15
+ instance.config
16
+ end
17
+
18
+ def collection
19
+ instance.collection
20
+ end
11
21
  end
12
22
 
23
+ extend Forwardable
24
+
25
+ def_delegators :@config, :configfile, :configfile=
26
+ def_delegators :@config, :setting, :[]
27
+
13
28
  def initialize
14
- @configfile = File.join(Dir.getwd, "config.yaml")
15
- @update_cache = true
29
+ @config = R10K::Config.new
16
30
  end
17
31
 
18
- attr_accessor :configfile
32
+ def config
33
+ @config
34
+ end
19
35
 
20
36
  # Load up all module roots
21
37
  #
@@ -25,39 +41,10 @@ class R10K::Deployment
25
41
  end
26
42
 
27
43
  def collection
28
- load_config unless @config
44
+ @config.load_config unless @config.loaded?
45
+ @collection ||= R10K::Deployment::EnvironmentCollection.new(@config)
29
46
  @collection
30
47
  end
31
-
32
- # Serve up the loaded config if it's already been loaded, otherwise try to
33
- # load a config in the current wd.
34
- def config
35
- load_config unless @config
36
- @config
37
- end
38
-
39
- # @return [Object] A top level key from the config hash
40
- def setting(key)
41
- self.config[key]
42
- end
43
- alias_method :[], :setting
44
-
45
- private
46
-
47
- # Load and store a config file, and set relevant options
48
- #
49
- # @param [String] configfile The path to the YAML config file
50
- def load_config
51
- File.open(@configfile) { |fh| @config = YAML.load(fh.read) }
52
- apply_config_settings
53
- @config
54
- end
55
-
56
- # Apply config settings to the relevant classes after a config has been loaded.
57
- def apply_config_settings
58
- if @config[:cachedir]
59
- R10K::Synchro::Git.cache_root = @config[:cachedir]
60
- end
61
- @collection = R10K::EnvironmentCollection.new(@config)
62
- end
63
48
  end
49
+
50
+ require 'r10k/deployment/environment_collection'
@@ -1,6 +1,6 @@
1
1
  require 'r10k'
2
2
 
3
- class R10K::EnvironmentCollection
3
+ class R10K::Deployment::EnvironmentCollection
4
4
 
5
5
  attr_reader :update_cache
6
6
 
@@ -70,8 +70,14 @@ class R10K::Module::Forge < R10K::Module
70
70
 
71
71
  def pmt(args)
72
72
  cmd = "puppet module --modulepath '#{@path}' #{args.join(' ')}"
73
+ log_event = "puppet module #{args.join(' ')}, modulepath: #{@path.inspect}"
73
74
  logger.debug1 "Execute: #{cmd}"
75
+
74
76
  status, stdout, stderr = systemu(cmd)
77
+
78
+ logger.debug2 "[#{log_event}] STDOUT: #{stdout.chomp}" unless stdout.empty?
79
+ logger.debug2 "[#{log_event}] STDERR: #{stderr.chomp}" unless stderr.empty?
80
+
75
81
  unless status == 0
76
82
  e = R10K::ExecutionFailure.new("#{cmd.inspect} returned with non-zero exit value #{status.inspect}")
77
83
  e.exit_code = status
@@ -1,3 +1,3 @@
1
1
  module R10K
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-04 00:00:00.000000000 Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored
@@ -131,6 +131,8 @@ files:
131
131
  - lib/r10k/cli/module.rb
132
132
  - lib/r10k/cli/synchronize.rb
133
133
  - lib/r10k/cli.rb
134
+ - lib/r10k/config/loader.rb
135
+ - lib/r10k/config.rb
134
136
  - lib/r10k/deployment/environment_collection.rb
135
137
  - lib/r10k/deployment.rb
136
138
  - lib/r10k/errors.rb