tiller 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05a79593ff72893e226851e957c3f49af44e5fda
4
- data.tar.gz: 7f728d0a3c74c8cebb04d6019bba64a558a7667e
3
+ metadata.gz: 2d1e95b4ed6d8c7c7e65adbf5787aaff5d30fe8b
4
+ data.tar.gz: 28ab01c02e3c27788fcf6e5b66f4e108cc446abe
5
5
  SHA512:
6
- metadata.gz: e7358cf1ee71f5053670d80ef9d7e79c26a3ec1e15cae529a84e3b7a2e1c022b7953758e6e933b3abf20d5f03f2237c849336b3bdca9b915146d562569942ff6
7
- data.tar.gz: 772dd50066fe32b171cf9b1ee60acc83907b86a0d483f866d4742f9afbd362e374724ab82f7060d2610a07ee54bcc20a04e40dcc7e7c6d5c327ace429bf10a9f
6
+ metadata.gz: c2425f1fc476a59129657a3e14e91b1d25550f3c78444f05e7a3bea813c3c01fd7f990f3a54238ac0b9c47f702ca6761626b9e2de53764d04fbf8cf76a186e0b
7
+ data.tar.gz: 6ed9f45e89fcb49380d1e1889d91caf238a59d2241b9359185f81f6e424b3885dacf9a28a65ffb453f479a429febf20669417c8eb68dfeafe0f686f2b5a2de2f
data/bin/tiller CHANGED
@@ -4,7 +4,7 @@
4
4
  # didn't have an existing gem named after it!
5
5
  # Mark Dastmalchi-Round <github@markround.com>
6
6
 
7
- VERSION = '0.5.2'
7
+ VERSION = '0.6.0'
8
8
 
9
9
  require 'erb'
10
10
  require 'ostruct'
@@ -53,17 +53,6 @@ module Tiller
53
53
  puts 'Data sources loaded ' + data_classes.to_s
54
54
  end
55
55
 
56
- # Get all Templates for the given environment
57
- templates = {}
58
- template_classes.each do |template_class|
59
- ts = template_class.new(config)
60
- ts.templates.each do |t|
61
- templates[t] = ts.template(t)
62
- end
63
- end
64
-
65
- puts "Templates to build #{templates.keys}" if config[:verbose]
66
-
67
56
  # Now go through all our data sources and start to assemble our global_values
68
57
  # hash. As hashes are getting merged, new values will take precedence over
69
58
  # older ones, and a warning will be displayed.
@@ -71,17 +60,30 @@ module Tiller
71
60
  # templates.
72
61
  global_values = { 'environment' => config[:environment] }
73
62
  data_classes.each do |data_class|
63
+ # Now need to see if any of the common.yaml values have been over-ridden by a datasource
64
+ # e.g. environment-specific execs and so on. We do this first so that connection strings
65
+ # to datasources (e.g. zookeeper) can be included in the config before we obtain any
66
+ # values.
67
+ config.merge!(data_class.new(config).common) do |key, old, new|
68
+ warn_merge(key, old, new, 'common', data_class.to_s)
69
+ end
70
+
74
71
  global_values.merge!(data_class.new(config).global_values) do |key, old, new|
75
72
  warn_merge(key, old, new, 'global', data_class.to_s)
76
73
  end
74
+ end
77
75
 
78
- # Now need to see if any of the common.yaml values have been over-ridden by a datasource
79
- # e.g. environment-specific execs and so on.
80
- config.merge!(data_class.new(config).common) do |key, old, new|
81
- warn_merge(key, old, new, 'common', data_class.to_s)
76
+ # Get all Templates for the given environment
77
+ templates = {}
78
+ template_classes.each do |template_class|
79
+ ts = template_class.new(config)
80
+ ts.templates.each do |t|
81
+ templates[t] = ts.template(t)
82
82
  end
83
83
  end
84
84
 
85
+ puts "Templates to build #{templates.keys}" if config[:verbose]
86
+
85
87
  # Now we go through each template we've identified, and get the
86
88
  # values for each one.
87
89
  all_templates = {}
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+ require 'zk'
3
+ require 'pp'
4
+ require 'timeout'
5
+
6
+ class ZookeeperDataSource < Tiller::DataSource
7
+
8
+ def setup
9
+ # Set our defaults if not specified
10
+ @zk_config = Tiller::Zookeeper::Defaults
11
+
12
+ raise 'No zookeeper configuration block' unless @config.has_key?('zookeeper')
13
+ @zk_config.merge!(@config['zookeeper'])
14
+
15
+ # Sanity check
16
+ ['uri'].each {|c| raise "Missing Zookeeper configuration #{c}" unless @zk_config.has_key?(c)}
17
+
18
+ uri = @zk_config['uri']
19
+ timeout = @zk_config['timeout']
20
+
21
+ begin
22
+ @zk = Timeout::timeout(timeout) { ZK.new(uri) }
23
+ rescue
24
+ raise "Could not connect to Zookeeper cluster : #{uri}"
25
+ end
26
+
27
+ end
28
+
29
+ def values(template_name)
30
+ path = @zk_config['values']['template']
31
+ .gsub('%e',@config[:environment])
32
+ .gsub('%t',template_name)
33
+
34
+ get_values(path)
35
+ end
36
+
37
+ def global_values
38
+ path = @zk_config['values']['global'].gsub('%e',@config[:environment])
39
+ puts "Fetching Zookeeper globals from #{path}" if @config[:verbose]
40
+ get_values(path)
41
+ end
42
+
43
+ def target_values(template_name)
44
+ path = @zk_config['values']['target']
45
+ .gsub('%e',@config[:environment])
46
+ .gsub('%t',template_name)
47
+ get_values(path)
48
+ end
49
+
50
+ # Helper method, not used by DataSource API
51
+ def get_values(path)
52
+ values = {}
53
+ if @zk.exists?(path)
54
+ keys = @zk.children(path)
55
+ keys.each do |key|
56
+ value = @zk.get("#{path}/#{key}")
57
+ values[key] = value[0]
58
+ end
59
+ end
60
+ values
61
+ end
62
+
63
+ end
@@ -4,9 +4,9 @@ module Tiller
4
4
  # template) and target_values (meta data about a template, e.g. target
5
5
  # location, permissions, owner and so on)
6
6
  class DataSource
7
- # All subclasses get this, which is a hash containing tiller_base,
8
- # tiller_lib and environment.
9
- @config = Array.new
7
+
8
+ # Every plugin gets this hash, which is the full parsed config
9
+ @config ={}
10
10
 
11
11
  def initialize(config)
12
12
  @config = config
@@ -19,7 +19,8 @@ module Tiller
19
19
  end
20
20
 
21
21
  # This is where we override any of the common.yaml settings per environment.
22
- # EG, the exec: parameter and so on.
22
+ # EG, the exec: parameter and so on. Also can be used for things like
23
+ # network service connection strings (e.g. Zookeeper) and so on.
23
24
  def common
24
25
  {}
25
26
  end
@@ -16,3 +16,19 @@ module Tiller
16
16
 
17
17
  end
18
18
 
19
+ # Defaults for the Zookeeper data and template sources
20
+ module Tiller::Zookeeper
21
+
22
+ Defaults = {
23
+ 'timeout' => 5,
24
+ 'templates' => '/tiller/%e',
25
+
26
+ 'values' => {
27
+ 'global' => '/tiller/globals',
28
+ 'template' => '/tiller/%e/%t/values',
29
+ 'target' => '/tiller/%e/%t/target_values'
30
+ }
31
+ }
32
+
33
+ end
34
+
@@ -0,0 +1,41 @@
1
+ class ZookeeperTemplateSource < Tiller::TemplateSource
2
+
3
+ def setup
4
+ # Set our defaults if not specified
5
+ @zk_config = Tiller::Zookeeper::Defaults
6
+
7
+ raise 'No zookeeper configuration block' unless @config.has_key?('zookeeper')
8
+ @zk_config.merge!(@config['zookeeper'])
9
+
10
+ # Sanity check
11
+ ['uri'].each {|c| raise "Missing Zookeeper configuration #{c}" unless @zk_config.has_key?(c)}
12
+
13
+ uri = @zk_config['uri']
14
+ timeout = @zk_config['timeout']
15
+
16
+ begin
17
+ @zk = Timeout::timeout(timeout) { ZK.new(uri) }
18
+ rescue
19
+ raise "Could not connect to Zookeeper cluster : #{uri}"
20
+ end
21
+
22
+ end
23
+
24
+ def templates
25
+ path = @zk_config['templates'].gsub('%e',@config[:environment])
26
+ puts "Fetching Zookeeper templates from #{path}" if @config[:verbose]
27
+ templates = []
28
+ if @zk.exists?(path)
29
+ templates = @zk.children(path)
30
+ end
31
+
32
+ templates
33
+ end
34
+
35
+ def template(template_name)
36
+ path = @zk_config['templates'].gsub('%e',@config[:environment]) + "/#{template_name}"
37
+ @zk.get(path)[0]
38
+ end
39
+
40
+
41
+ end
@@ -3,12 +3,13 @@ module Tiller
3
3
  # Subclasses provide templates (an array), and individual template contents
4
4
  # (a string containing ERB data)
5
5
  class TemplateSource
6
- # All subclasses get this, which is a hash containing tiller_base,
7
- # tiller_lib and environment.
8
- @config = Array.new
6
+
7
+ # Every plugin gets this hash, which is the full parsed config
8
+ @config = {}
9
9
 
10
10
  def initialize(config)
11
11
  @config = config
12
+ setup
12
13
  end
13
14
 
14
15
  # This is where any post-initialisation logic happens
@@ -17,11 +18,11 @@ module Tiller
17
18
  end
18
19
 
19
20
  def templates
20
- Hash.new
21
+ {}
21
22
  end
22
23
 
23
24
  def template
24
- String.new
25
+ ""
25
26
  end
26
27
 
27
28
  def ping
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Dastmalchi-Round
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tool to create configuration files from a variety of sources, particularly
14
14
  useful for Docker containers. See https://github.com/markround/tiller for examples
@@ -56,12 +56,14 @@ files:
56
56
  - lib/tiller/data/environment_json.rb
57
57
  - lib/tiller/data/file.rb
58
58
  - lib/tiller/data/random.rb
59
+ - lib/tiller/data/zookeeper.rb
59
60
  - lib/tiller/datasource.rb
60
61
  - lib/tiller/defaults.rb
61
62
  - lib/tiller/json.rb
62
63
  - lib/tiller/loader.rb
63
64
  - lib/tiller/options.rb
64
65
  - lib/tiller/template/file.rb
66
+ - lib/tiller/template/zookeeper.rb
65
67
  - lib/tiller/templatesource.rb
66
68
  - lib/tiller/util.rb
67
69
  homepage: http://www.markround.com