tiller 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d370d0cfa95a4115b8a5f6daec7789d5352ec86
4
- data.tar.gz: aa1ea4c0bb09ae319f97be6d71026bfd0b9797cb
3
+ metadata.gz: d8dc77227116ed298ac33995aa6b389192d6917b
4
+ data.tar.gz: 50e4cc6c12c7f1ba0844ea776f180136b75640fa
5
5
  SHA512:
6
- metadata.gz: 8749c166f4d4581b7423ba444be330ab8ddbf2981a59197e1c0b75fa14a6204bf31f6085f16bb642eb13414f26d31d75ccfd27b8e336fcff78c6fb930ce26cb5
7
- data.tar.gz: 98edc1de13a2bc03ae34786258598af6cc0279044d5e57c1f5630248296df607d79047588795c21226c5f9608bc9fcf2227cc29d2fdfc4c77f4a2218c8932024
6
+ metadata.gz: 721d43464aaec3feab28f9647005cc50dbfeba1f5e816d03982e35f1bce8287e3cda45d898bc3ec163513a59f371e913456efcabc1e06d1bec102cf6337f9294
7
+ data.tar.gz: 5802b4722771fa28f172383516ece84de346f1b6b54132c5d79d9317788d0d95604a559efa8a59e79931a655ef38c0672d683393d05f035954a54630f2fc2a12
data/bin/tiller CHANGED
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Mark Dastmalchi-Round <github@markround.com>
10
10
 
11
- VERSION = '0.7.7'
11
+ VERSION = '0.7.8'
12
12
 
13
13
  require 'erb'
14
14
  require 'ostruct'
@@ -0,0 +1,35 @@
1
+ require 'diplomat'
2
+ require 'pp'
3
+ require 'tiller/defaults'
4
+ require 'tiller/util'
5
+
6
+ module Tiller::ConsulCommon
7
+ def setup
8
+ # Set our defaults if not specified
9
+ @consul_config = Tiller::Consul.defaults
10
+ raise 'No Consul configuration block' unless @config.has_key?('consul')
11
+ @consul_config.deep_merge!(@config['consul'])
12
+
13
+ # Sanity check
14
+ ['url'].each {|c| raise "Consul: Missing Consul configuration #{c}" unless @consul_config.has_key?(c)}
15
+
16
+ # Now we connect to Consul
17
+ Diplomat.configure do |config|
18
+ @log.debug("#{self} : Connecting to Consul at #{@consul_config['url']}")
19
+ config.url = @consul_config['url']
20
+
21
+ if @consul_config['acl_token']
22
+ @log.debug("#{self} : Using Consul ACL token")
23
+ config.acl_token = @consul_config['acl_token']
24
+ end
25
+ end
26
+ end
27
+
28
+ # Interpolate configuration placeholders with values
29
+ def interpolate(path, template_name = nil)
30
+ path.gsub!('%e', @config[:environment])
31
+ path.gsub!('%t', template_name) if template_name
32
+ path
33
+ end
34
+
35
+ end
@@ -0,0 +1,71 @@
1
+ require 'pp'
2
+ require 'diplomat'
3
+ require 'tiller/consul.rb'
4
+
5
+ class ConsulDataSource < Tiller::DataSource
6
+
7
+ include Tiller::ConsulCommon
8
+
9
+ def global_values
10
+ # Fetch globals
11
+ path = interpolate("#{@consul_config['values']['global']}")
12
+ @log.debug("#{self} : Fetching globals from #{path}")
13
+ globals = fetch_all_keys(path)
14
+
15
+ # Do we have per-env globals ? If so, merge them
16
+ path = interpolate("#{@consul_config['values']['per_env']}")
17
+ @log.debug("#{self} : Fetching per-environment globals from #{path}")
18
+ globals.deep_merge!(fetch_all_keys(path))
19
+
20
+ # Do we want to register services in consul_services hash ?
21
+ if @consul_config['register_services']
22
+ @log.debug("#{self} : Registering Consul services")
23
+ globals['consul_services'] = {}
24
+ services = Diplomat::Service.get_all({ :dc => @consul_config['dc'] })
25
+ services.marshal_dump.each do |service, _data|
26
+ @log.debug("#{self} : Fetching Consul service information for #{service}")
27
+ service_data = Diplomat::Service.get(service, :all, { :dc => @consul_config['dc']})
28
+ globals['consul_services'].merge!( { "#{service}" => service_data })
29
+ end
30
+ end
31
+
32
+ # Do we want to register nodes in consul_nodes hash ?
33
+ if @consul_config['register_nodes']
34
+ @log.debug("#{self} : Registering Consul nodes")
35
+ globals['consul_nodes'] = {}
36
+ nodes = Diplomat::Node.get_all
37
+ nodes.each do |n|
38
+ globals['consul_nodes'].merge!({ n.Node => n.Address })
39
+ end
40
+ end
41
+ globals
42
+ end
43
+
44
+ def values(template_name)
45
+ path = interpolate("#{@consul_config['values']['template']}", template_name)
46
+ @log.debug("#{self} : Fetching template values from #{path}")
47
+ fetch_all_keys(path)
48
+ end
49
+
50
+ def target_values(template_name)
51
+ path = interpolate("#{@consul_config['values']['target']}", template_name)
52
+ @log.debug("#{self} : Fetching template target values from #{path}")
53
+ fetch_all_keys(path)
54
+ end
55
+
56
+
57
+ def fetch_all_keys(path)
58
+ keys = Diplomat::Kv.get(path, { keys: true, :dc => @consul_config['dc'] }, :return)
59
+ all_keys = {}
60
+ if keys.is_a? Array
61
+ keys.each do |k|
62
+ @log.debug("#{self} : Fetching key #{k}")
63
+ all_keys[File.basename(k)] = Diplomat::Kv.get(k, { nil_values: true, :dc => @consul_config['dc'] })
64
+ end
65
+ all_keys
66
+ else
67
+ {}
68
+ end
69
+ end
70
+
71
+ end
@@ -1,14 +1,7 @@
1
1
  require 'yaml'
2
- # Defaults datasource for Tiller.
3
-
4
- # Thanks, StackOverflow ;)
5
- class ::Hash
6
- def deep_merge!(second)
7
- merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
8
- self.merge!(second, &merger)
9
- end
10
- end
2
+ require 'tiller/util'
11
3
 
4
+ # Defaults datasource for Tiller.
12
5
 
13
6
  class DefaultsDataSource < Tiller::DataSource
14
7
  def setup
@@ -1,10 +1,6 @@
1
1
  require 'yaml'
2
- # File datasource for Tiller. This works the same way as the default behaviour
3
- # in Runner.rb - it loads your <environment>.yaml file and pulls data from it.
4
- # See examples/etc/tiller/environments/production.yaml to see what this file
5
- # looks like.
6
- #
7
- # We also don't provide any global values, just ones specific to a template.
2
+ # File datasource for Tiller.
3
+
8
4
  class FileDataSource < Tiller::DataSource
9
5
  # Open and parse the environment file. Tries from v2 format common.yaml first, if that
10
6
  # failes, then it looks for separate environment files.
@@ -1,5 +1,4 @@
1
1
  module Tiller
2
-
3
2
  Defaults = {
4
3
  :tiller_base => (ENV['tiller_base'].nil?) ? '/etc/tiller' : ENV['tiller_base'],
5
4
  :tiller_lib => (ENV['tiller_lib'].nil?) ? '/usr/local/lib' : ENV['tiller_lib'],
@@ -13,12 +12,10 @@ module Tiller
13
12
  'api_enable' => false,
14
13
  'api_port' => 6275
15
14
  }
16
-
17
15
  end
18
16
 
19
17
  # Defaults for the Zookeeper data and template sources
20
18
  module Tiller::Zookeeper
21
-
22
19
  Defaults = {
23
20
  'timeout' => 5,
24
21
  'templates' => '/tiller/%e',
@@ -29,14 +26,13 @@ module Tiller::Zookeeper
29
26
  'target' => '/tiller/%e/%t/target_values'
30
27
  }
31
28
  }
32
-
33
29
  end
34
30
 
35
31
 
36
32
  # Defaults for the HTTP data and template sources
37
33
  module Tiller::Http
38
-
39
- Defaults = {
34
+ def self.defaults
35
+ {
40
36
  'timeout' => 5,
41
37
  'proxy' => '',
42
38
  'templates' => '/tiller/environments/%e/templates',
@@ -48,7 +44,27 @@ module Tiller::Http
48
44
  'template' => '/tiller/templates/%t/values/%e',
49
45
  'target' => '/tiller/templates/%t/target_values/%e'
50
46
  }
51
- }
47
+ }
48
+ end
49
+ end
50
+
51
+ module Tiller::Consul
52
+ def self.defaults
53
+ {
54
+ 'dc' => 'dc1',
55
+ 'acl_token' => nil,
56
+ 'register_services' => false,
57
+ 'register_nodes' => false,
58
+
59
+ 'templates' => '/tiller/templates',
52
60
 
61
+ 'values' => {
62
+ 'global' => '/tiller/globals/all',
63
+ 'per_env' => '/tiller/globals/%e',
64
+ 'template' => '/tiller/values/%e/%t',
65
+ 'target' => '/tiller/target_values/%t/%e'
66
+ }
67
+ }
68
+ end
53
69
  end
54
70
 
data/lib/tiller/http.rb CHANGED
@@ -10,7 +10,7 @@ module Tiller::HttpCommon
10
10
 
11
11
  def setup
12
12
  # Set our defaults if not specified
13
- @http_config = Tiller::Http::Defaults
13
+ @http_config = Tiller::Http.defaults
14
14
 
15
15
  raise 'No HTTP configuration block' unless @config.has_key?('http')
16
16
  @http_config.merge!(@config['http'])
@@ -61,4 +61,4 @@ module Tiller::HttpCommon
61
61
  end
62
62
 
63
63
 
64
- end
64
+ end
@@ -0,0 +1,27 @@
1
+ require 'pp'
2
+ require 'diplomat'
3
+ require 'tiller/consul.rb'
4
+
5
+ class ConsulTemplateSource < Tiller::TemplateSource
6
+
7
+ include Tiller::ConsulCommon
8
+
9
+ def templates
10
+ path = interpolate("#{@consul_config['templates']}")
11
+ @log.debug("#{self} : Fetching templates from #{path}")
12
+ templates = Diplomat::Kv.get(path, {:keys => true, :dc => @consul_config['dc']}, :return)
13
+
14
+ if templates.is_a? Array
15
+ templates.map{|t| File.basename(t)}
16
+ else
17
+ @log.warn("Consul : No templates could be fetched from #{path}")
18
+ []
19
+ end
20
+ end
21
+
22
+ def template(template_name)
23
+ path = interpolate("#{@consul_config['templates']}")
24
+ Diplomat::Kv.get("#{path}/#{template_name}", {:dc => @consul_config['dc']})
25
+ end
26
+
27
+ end
@@ -1,5 +1,4 @@
1
- # File template datasource for Tiller. This works the same way that Runner.rb
2
- # used to - it returns templates files present under /etc/tiller/templates
1
+ # File template datasource for Tiller. It returns templates files present under /etc/tiller/templates
3
2
  # (or wherever the tiller_base environment is set).
4
3
  class FileTemplateSource < Tiller::TemplateSource
5
4
  def initialize(config)
@@ -21,10 +21,10 @@ module Tiller
21
21
  end
22
22
 
23
23
  def templates
24
- {}
24
+ []
25
25
  end
26
26
 
27
- def template
27
+ def template(_template_name)
28
28
  ""
29
29
  end
30
30
 
data/lib/tiller/util.rb CHANGED
@@ -1,3 +1,11 @@
1
+ # Thanks, StackOverflow ;)
2
+ class ::Hash
3
+ def deep_merge!(second)
4
+ merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
5
+ self.merge!(second, &merger)
6
+ end
7
+ end
8
+
1
9
  # This is needed so we can enumerate all the loaded plugins later
2
10
  class Class
3
11
  def subclasses
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.7.7
4
+ version: 0.7.8
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: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-13 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
@@ -27,6 +27,8 @@ files:
27
27
  - lib/tiller/api/handlers/ping.rb
28
28
  - lib/tiller/api/handlers/template.rb
29
29
  - lib/tiller/api/handlers/templates.rb
30
+ - lib/tiller/consul.rb
31
+ - lib/tiller/data/consul.rb
30
32
  - lib/tiller/data/defaults.rb
31
33
  - lib/tiller/data/environment.rb
32
34
  - lib/tiller/data/environment_json.rb
@@ -42,6 +44,7 @@ files:
42
44
  - lib/tiller/loader.rb
43
45
  - lib/tiller/logger.rb
44
46
  - lib/tiller/options.rb
47
+ - lib/tiller/template/consul.rb
45
48
  - lib/tiller/template/file.rb
46
49
  - lib/tiller/template/http.rb
47
50
  - lib/tiller/template/zookeeper.rb