tiller 0.2.5 → 0.3.0

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: e94f34b60987dff612b49a337676c7498f0fa2c2
4
- data.tar.gz: 070f1cb472cebb7e4c52806dad6e0b521ffeafc7
3
+ metadata.gz: 6aa333d19e0893f11f9eb96e2b676beb5e5cc453
4
+ data.tar.gz: 99928301c66ea05edaa4ad90da59cb56d550008c
5
5
  SHA512:
6
- metadata.gz: 13427f9196656d8cf30f5c45c64bdd457c157201ef2e45be85603526834e8c77280135f5e1dfe26c50b18d6919970d3008c39d4ec875c447c3468164589e8201
7
- data.tar.gz: 1756029ede9afbe58b1474dcfb152ec96b05ba215b66d91f77b2f241ec5e0445c163fc3bcc5100d7ef0d0a2034c1d0eed89ea20cfa5eb71df06e9f30fb6e87a6
6
+ metadata.gz: 3b2c666d5b7ca26051c2cbb1fa22da3eae3d47e6a44772d938284f145bc71b4b31da3e25d4586496a5ff6f77a08ae8f56f6b808c6689fff5b30a383afc8c3e08
7
+ data.tar.gz: 6e2f2f1a075669c1918ae2005bef7b8a33654a8af8e0c27a693aeebc205d5346bb6e26eab672049229cf5a6e0994bda106e5bb5b7c07e32a63b3530f77061c39
data/bin/tiller CHANGED
@@ -4,7 +4,7 @@
4
4
  # didn't have an existing gem named after it!
5
5
  # Mark Round <github@markround.com>
6
6
 
7
- VERSION = '0.2.5'
7
+ VERSION = '0.3.0'
8
8
 
9
9
  require 'erb'
10
10
  require 'ostruct'
@@ -105,17 +105,36 @@ module Tiller
105
105
  data_sources = Array.new
106
106
  template_sources |= config['template_sources']
107
107
  data_sources |= config['data_sources']
108
- template_sources.each { |t| require "tiller/template/#{t}.rb" }
109
- data_sources.each { |t| require "tiller/data/#{t}.rb" }
108
+
109
+ # This looks a little counter-intuitive, but it's for a reason.
110
+ # We load things this way so that we get an array (data_sources, for example)
111
+ # That contains all the classes loaded, *in the order specified in common.yaml*
112
+ # This is very important, as it means we can specify the defaults DataSource
113
+ # first, for example and then let later DataSources override values from it.
114
+ # Otherwise, iterating through the available classes results in them being
115
+ # returned in no particular useful order.
116
+ template_classes = Array.new
117
+ template_sources.each do |t|
118
+ require "tiller/template/#{t}.rb"
119
+ template_classes |= TemplateSource.subclasses
120
+ end
121
+
122
+ data_classes = Array.new
123
+ data_sources.each do |d|
124
+ require "tiller/data/#{d}.rb"
125
+ data_classes |= DataSource.subclasses
126
+ end
127
+
110
128
 
111
129
  if config[:verbose]
112
- puts 'Template sources loaded ' + TemplateSource.subclasses.to_s
113
- puts 'Data sources loaded ' + DataSource.subclasses.to_s
130
+ puts 'Template sources loaded ' + template_classes.to_s
131
+ puts 'Data sources loaded ' + data_classes.to_s
114
132
  end
115
133
 
134
+
116
135
  # Get all Templates for the given environment
117
136
  templates = Hash.new
118
- TemplateSource.subclasses.each do |template_class|
137
+ template_classes.each do |template_class|
119
138
  ts = template_class.new(config)
120
139
  ts.templates.each do |t|
121
140
  templates[t] = ts.template(t)
@@ -130,7 +149,7 @@ module Tiller
130
149
  # We also add in 'environment' to start with as it's very useful for all
131
150
  # templates.
132
151
  global_values = { 'environment' => config[:environment] }
133
- DataSource.subclasses.each do |data_class|
152
+ data_classes.each do |data_class|
134
153
  global_values.merge!(data_class.new(config).global_values) do |key, old, new|
135
154
  warn_merge(key, old, new, 'global', data_class.to_s)
136
155
  end
@@ -145,7 +164,7 @@ module Tiller
145
164
 
146
165
  # Now we populate the hash with values from each DataSource, warning if we
147
166
  # get duplicate values.
148
- DataSource.subclasses.each do |data_class|
167
+ data_classes.each do |data_class|
149
168
  dc = data_class.new(config)
150
169
  if dc.values(template) != nil
151
170
  values.merge!(dc.values(template)) do |key, old, new|
@@ -0,0 +1,9 @@
1
+ exec: date
2
+
3
+ data_sources:
4
+ - defaults
5
+ - file
6
+ - environment
7
+
8
+ template_sources:
9
+ - file
@@ -0,0 +1,2 @@
1
+ app.conf.erb:
2
+ port: '8080'
@@ -0,0 +1,2 @@
1
+ global:
2
+ domain_name: 'example.com'
@@ -0,0 +1,5 @@
1
+ global:
2
+ domain_name: 'example.com'
3
+
4
+ app.conf.erb:
5
+ port: '8080'
@@ -0,0 +1,4 @@
1
+ app.conf.erb:
2
+ target: /tmp/app.conf
3
+ config:
4
+ database: 'prd-db-1.example.com'
@@ -0,0 +1,5 @@
1
+ app.conf.erb:
2
+ target: /tmp/app.conf
3
+ config:
4
+ port: '8081'
5
+ database: 'stg-db-1.dev.example.com'
@@ -0,0 +1,9 @@
1
+ [http]
2
+ http.port=<%= port %>
3
+ http.hostname=<%= environment %>.<%= domain_name %>
4
+
5
+ [smtp]
6
+ mail_domain_name=<%= domain_name %>
7
+
8
+ [db]
9
+ db.host=<%= database %>
@@ -0,0 +1,9 @@
1
+ exec: date
2
+
3
+ data_sources:
4
+ - defaults
5
+ - file
6
+ - environment
7
+
8
+ template_sources:
9
+ - file
@@ -0,0 +1,5 @@
1
+ global:
2
+ domain_name: 'example.com'
3
+
4
+ app.conf.erb:
5
+ port: '8080'
@@ -0,0 +1,4 @@
1
+ app.conf.erb:
2
+ target: /tmp/app.conf
3
+ config:
4
+ database: 'prd-db-1.example.com'
@@ -0,0 +1,5 @@
1
+ app.conf.erb:
2
+ target: /tmp/app.conf
3
+ config:
4
+ port: '8081'
5
+ database: 'stg-db-1.dev.example.com'
@@ -0,0 +1,9 @@
1
+ [http]
2
+ http.port=<%= port %>
3
+ http.hostname=<%= environment %>.<%= domain_name %>
4
+
5
+ [smtp]
6
+ mail_domain_name=<%= domain_name %>
7
+
8
+ [db]
9
+ db.host=<%= database %>
@@ -0,0 +1,40 @@
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
11
+
12
+
13
+ class DefaultsDataSource < Tiller::DataSource
14
+ def setup
15
+ defaults_file = File.join(@config[:tiller_base], 'defaults.yaml')
16
+ defaults_dir = File.join(@config[:tiller_base], 'defaults.d')
17
+ @defaults_hash = Hash.new
18
+
19
+ # Read defaults in from defaults file
20
+ if File.file? defaults_file
21
+ @defaults_hash.deep_merge!(YAML.load(open(defaults_file)))
22
+ end
23
+
24
+ # If we have YAML files in defaults.d, also merge them
25
+ if File.directory? defaults_dir
26
+ Dir.glob(File.join(defaults_dir,'*.yaml')).each do |d|
27
+ @defaults_hash.deep_merge!(YAML.load(open(d)))
28
+ end
29
+ end
30
+ end
31
+
32
+ def global_values
33
+ @defaults_hash.key?('global') ? @defaults_hash['global'] : Hash.new
34
+ end
35
+
36
+ def values(template_name)
37
+ @defaults_hash.key?(template_name) ? @defaults_hash[template_name] : Hash.new
38
+ end
39
+
40
+ end
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.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Round
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-27 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tool to create configuration files in Docker containers from a variety
14
14
  of sources. See https://github.com/markround/tiller for examples and documentation.
@@ -19,6 +19,18 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - bin/tiller
22
+ - examples/defaults.d/common.yaml
23
+ - examples/defaults.d/defaults.d/app.conf.yaml
24
+ - examples/defaults.d/defaults.d/global.yaml
25
+ - examples/defaults.d/defaults.yaml
26
+ - examples/defaults.d/environments/production.yaml
27
+ - examples/defaults.d/environments/staging.yaml
28
+ - examples/defaults.d/templates/app.conf.erb
29
+ - examples/defaults/common.yaml
30
+ - examples/defaults/defaults.yaml
31
+ - examples/defaults/environments/production.yaml
32
+ - examples/defaults/environments/staging.yaml
33
+ - examples/defaults/templates/app.conf.erb
22
34
  - examples/json/common.yaml
23
35
  - examples/json/environments/array.yaml
24
36
  - examples/json/environments/simple_keys.yaml
@@ -38,6 +50,7 @@ files:
38
50
  - lib/tiller/api/handlers/ping.rb
39
51
  - lib/tiller/api/handlers/template.rb
40
52
  - lib/tiller/api/handlers/templates.rb
53
+ - lib/tiller/data/defaults.rb
41
54
  - lib/tiller/data/environment.rb
42
55
  - lib/tiller/data/environment_json.rb
43
56
  - lib/tiller/data/file.rb