tiller 0.3.0 → 0.3.1

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: 6aa333d19e0893f11f9eb96e2b676beb5e5cc453
4
- data.tar.gz: 99928301c66ea05edaa4ad90da59cb56d550008c
3
+ metadata.gz: 783e5f461315d6b6c76b7f1bdc6c8c907056c2fb
4
+ data.tar.gz: cf893537c943b65c6ef30c1af5a86ed53eadf984
5
5
  SHA512:
6
- metadata.gz: 3b2c666d5b7ca26051c2cbb1fa22da3eae3d47e6a44772d938284f145bc71b4b31da3e25d4586496a5ff6f77a08ae8f56f6b808c6689fff5b30a383afc8c3e08
7
- data.tar.gz: 6e2f2f1a075669c1918ae2005bef7b8a33654a8af8e0c27a693aeebc205d5346bb6e26eab672049229cf5a6e0994bda106e5bb5b7c07e32a63b3530f77061c39
6
+ metadata.gz: 3d36202ffecd118009d50b7efcf908825207965ba62b1b53e8aef34c3c1b4f8187124510d6236ecf5a37223036500a0751c80badcd3e3faa8566d68b03d050fa
7
+ data.tar.gz: 23ed8c7bd87be72c791fc8da4aa237932b44776540d82a555ce134c69d54f3259de7a8a355c6e0cb337af066a31f88687aa53e11555a5b820fe782db28cdb92c
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.3.0'
7
+ VERSION = '0.3.1'
8
8
 
9
9
  require 'erb'
10
10
  require 'ostruct'
@@ -15,85 +15,26 @@ require 'pp'
15
15
  require 'json'
16
16
  require 'socket'
17
17
  require 'tiller/api'
18
-
19
- # This is needed so we can enumerate all the loaded plugins later
20
- class Class
21
- def subclasses
22
- ObjectSpace.each_object(Class).select { |c| c < self }
23
- end
24
- end
25
-
26
- def warn_merge(key, old, new, type, source)
27
- puts "Warning, merging duplicate #{type} values."
28
- puts "#{key} => '#{old}' being replaced by : '#{new}' from #{source}"
29
- new
30
- end
18
+ require 'tiller/defaults'
19
+ require 'tiller/loader'
20
+ require 'tiller/options'
21
+ require 'tiller/util'
22
+ require 'tiller/templatesource'
23
+ require 'tiller/datasource'
31
24
 
32
25
  # And we're on our way...
33
26
  module Tiller
34
- # Set these two environment variables if you want to debug a configuration
35
- # in a temporary directory, or use the -b and -l arguments.
36
- # EG: $ ./bin/tiller -b /tmp/tiller/etc -l /tmp/tiller/lib
37
- config = {
38
- :tiller_base => (ENV['tiller_base'].nil?) ? '/etc/tiller' : ENV['tiller_base'],
39
- :tiller_lib => (ENV['tiller_lib'].nil?) ? '/usr/local/lib' : ENV['tiller_lib'],
40
- # This is the main variable, usually the only one you pass into Docker.
41
- :environment => (ENV['environment'].nil?) ? 'production' : ENV['environment']
42
- }
43
-
44
- # Parse command-line arguments
45
- config[:no_exec] = false
46
- config[:verbose] = false
47
- config['api_enable'] = false
48
- config['api_port'] = 6275
49
-
50
- optparse = OptionParser.new do |opts|
51
- opts.on('-n', '--no-exec', 'Do not execute a replacement process') do
52
- config[:no_exec] = true
53
- end
54
- opts.on('-v', '--verbose', 'Display verbose output') do
55
- config[:verbose] = true
56
- end
57
- opts.on('-a', '--api', 'Enable HTTP API') do
58
- config['api_enable'] = true
59
- end
60
- opts.on('-p', '--api-port [API_PORT]', 'HTTP API port') do |api_port|
61
- config['api_port'] = api_port
62
- end
63
- opts.on('-b', '--base-dir [BASE_DIR]', 'Override the tiller_base environment variable') do |base_dir|
64
- config[:tiller_base] = base_dir
65
- end
66
- opts.on('-l', '--lib-dir [LIB_DIR]', 'Override the tiller_lib environment variable') do |lib_dir|
67
- config[:tiller_lib] = lib_dir
68
- end
69
- opts.on('-e', '--environment [ENV]', 'Override the \'environment\' environment variable') do |environment|
70
- config[:environment] = environment
71
- end
72
27
 
73
- opts.on('-h', '--help', 'Display this screen') do
74
- puts opts
75
- puts 'Tiller also uses the environment variables tiller_base, environment'
76
- puts 'and tiller_lib (or they can be provided using the arguments shown above).'
77
- puts 'See https://github.com/markround/tiller for documentation and usage.'
78
- puts 'Current configuration hash follows :'
79
- pp config
80
- exit
81
- end
82
- end
28
+ puts "tiller v#{VERSION} (https://github.com/markround/tiller) <github@markround.com>"
83
29
 
84
- optparse.parse!
30
+ config = parse_options(Tiller::Defaults)
85
31
 
86
32
  # Add tiller_lib to the LOAD PATH so we can pull in user-defined plugins
87
33
  $LOAD_PATH.unshift(config[:tiller_lib]) unless $LOAD_PATH.include?(config[:tiller_lib])
88
34
 
89
- require 'tiller/templatesource.rb'
90
- require 'tiller/datasource.rb'
91
-
92
35
  # Load the common YAML configuration file
93
36
  config.merge!(YAML.load(open(File.join(config[:tiller_base], 'common.yaml'))))
94
37
 
95
- puts "tiller v#{VERSION} (https://github.com/markround/tiller) <github@markround.com>"
96
-
97
38
  if config[:verbose]
98
39
  puts "Using configuration from #{config[:tiller_base]}"
99
40
  puts "Using plugins from #{config[:tiller_lib]}/tiller"
@@ -101,39 +42,16 @@ module Tiller
101
42
  end
102
43
 
103
44
  # Now load all our plugins
104
- template_sources = Array.new
105
- data_sources = Array.new
106
- template_sources |= config['template_sources']
107
- data_sources |= config['data_sources']
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
-
45
+ data_classes = loader(DataSource, config['data_sources'])
46
+ template_classes = loader(TemplateSource, config['template_sources'])
128
47
 
129
48
  if config[:verbose]
130
49
  puts 'Template sources loaded ' + template_classes.to_s
131
50
  puts 'Data sources loaded ' + data_classes.to_s
132
51
  end
133
52
 
134
-
135
53
  # Get all Templates for the given environment
136
- templates = Hash.new
54
+ templates = {}
137
55
  template_classes.each do |template_class|
138
56
  ts = template_class.new(config)
139
57
  ts.templates.each do |t|
@@ -157,10 +75,10 @@ module Tiller
157
75
 
158
76
  # Now we go through each template we've identified, and get the
159
77
  # values for each one.
160
- all_templates = Hash.new
78
+ all_templates = {}
161
79
  templates.each do |template, content|
162
- values = Hash.new
163
- target_values = Hash.new
80
+ values = {}
81
+ target_values = {}
164
82
 
165
83
  # Now we populate the hash with values from each DataSource, warning if we
166
84
  # get duplicate values.
@@ -0,0 +1,14 @@
1
+ module Tiller
2
+
3
+ Defaults = {
4
+ :tiller_base => (ENV['tiller_base'].nil?) ? '/etc/tiller' : ENV['tiller_base'],
5
+ :tiller_lib => (ENV['tiller_lib'].nil?) ? '/usr/local/lib' : ENV['tiller_lib'],
6
+ # This is the main variable, usually the only one you pass into Docker.
7
+ :environment => (ENV['environment'].nil?) ? 'production' : ENV['environment'],
8
+ :no_exec => false,
9
+ :verbose => false,
10
+ 'api_enable' => false,
11
+ 'api_port' => 6275
12
+ }
13
+
14
+ end
@@ -0,0 +1,31 @@
1
+ require 'tiller/templatesource'
2
+ require 'tiller/datasource'
3
+
4
+ def loader(type,sources)
5
+
6
+ case type.to_s
7
+ when 'Tiller::DataSource'
8
+ source_path = 'tiller/data'
9
+ when 'Tiller::TemplateSource'
10
+ source_path = 'tiller/template'
11
+ else
12
+ raise "Unsupported by loader : #{type}"
13
+ end
14
+
15
+ # This looks a little counter-intuitive, but it's for a reason.
16
+ # We load things this way so that we get an array that contains all the
17
+ # classes loaded, *in the order specified in common.yaml*
18
+ # This is very important, as it means we can specify the defaults DataSource
19
+ # first, for example and then let later DataSources override values from it.
20
+ # Otherwise, iterating through the available classes results in them being
21
+ # returned in no particular useful order.
22
+
23
+ classes = []
24
+ sources.each do |s|
25
+ require File.join(source_path,"#{s}.rb")
26
+ classes |= type.subclasses
27
+ end
28
+
29
+ classes
30
+
31
+ end
@@ -0,0 +1,39 @@
1
+ def parse_options(config)
2
+ optparse = OptionParser.new do |opts|
3
+ opts.on('-n', '--no-exec', 'Do not execute a replacement process') do
4
+ config[:no_exec] = true
5
+ end
6
+ opts.on('-v', '--verbose', 'Display verbose output') do
7
+ config[:verbose] = true
8
+ end
9
+ opts.on('-a', '--api', 'Enable HTTP API') do
10
+ config['api_enable'] = true
11
+ end
12
+ opts.on('-p', '--api-port [API_PORT]', 'HTTP API port') do |api_port|
13
+ config['api_port'] = api_port
14
+ end
15
+ opts.on('-b', '--base-dir [BASE_DIR]', 'Override the tiller_base environment variable') do |base_dir|
16
+ config[:tiller_base] = base_dir
17
+ end
18
+ opts.on('-l', '--lib-dir [LIB_DIR]', 'Override the tiller_lib environment variable') do |lib_dir|
19
+ config[:tiller_lib] = lib_dir
20
+ end
21
+ opts.on('-e', '--environment [ENV]', 'Override the \'environment\' environment variable') do |environment|
22
+ config[:environment] = environment
23
+ end
24
+
25
+ opts.on('-h', '--help', 'Display this screen') do
26
+ puts opts
27
+ puts 'Tiller also uses the environment variables tiller_base, environment'
28
+ puts 'and tiller_lib (or they can be provided using the arguments shown above).'
29
+ puts 'See https://github.com/markround/tiller for documentation and usage.'
30
+ puts 'Current configuration hash follows :'
31
+ pp config
32
+ exit
33
+ end
34
+ end
35
+
36
+ optparse.parse!
37
+
38
+ config
39
+ end
@@ -0,0 +1,13 @@
1
+ # This is needed so we can enumerate all the loaded plugins later
2
+ class Class
3
+ def subclasses
4
+ ObjectSpace.each_object(Class).select { |c| c < self }
5
+ end
6
+ end
7
+
8
+ # Warn if values are being merged
9
+ def warn_merge(key, old, new, type, source)
10
+ puts "Warning, merging duplicate #{type} values."
11
+ puts "#{key} => '#{old}' being replaced by : '#{new}' from #{source}"
12
+ new
13
+ 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.3.0
4
+ version: 0.3.1
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-12-05 00:00:00.000000000 Z
11
+ date: 2014-12-19 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.
@@ -56,9 +56,13 @@ files:
56
56
  - lib/tiller/data/file.rb
57
57
  - lib/tiller/data/random.rb
58
58
  - lib/tiller/datasource.rb
59
+ - lib/tiller/defaults.rb
59
60
  - lib/tiller/json.rb
61
+ - lib/tiller/loader.rb
62
+ - lib/tiller/options.rb
60
63
  - lib/tiller/template/file.rb
61
64
  - lib/tiller/templatesource.rb
65
+ - lib/tiller/util.rb
62
66
  homepage: http://www.markround.com
63
67
  licenses:
64
68
  - MIT