stack_master 0.9.0 → 0.10.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: 669fe955eddbb4bac2997b5225589202c839cd51
4
- data.tar.gz: 8f4a070bf9d8a239dad4af929f77205cf28ca2e2
3
+ metadata.gz: a85d9f970dc4d0ab565bef1908fee42dfa1e018a
4
+ data.tar.gz: adc99ec3388382b0c65630b254c5bfd4d1bfb8b1
5
5
  SHA512:
6
- metadata.gz: 27fc53a556cfdb8cdf310c7ccf2072ab9de8554c9c8f70ca57789ae9522a357974502dec79f9a5456a98ba47a38d27690cb47d6272c17a91ab3de5286d3b4a69
7
- data.tar.gz: 68ccfeb10eb82cc6cde54d2ba559a3eebf80e5d882369d41ef267b79b08672c281906312fd73928a028e3224558a38986670b8a7996c3140f894fc43302eae60
6
+ metadata.gz: f961b7bf042713969f1cfcff18da0a1fabf9c674a566fd82be1486f0514ef2792efbf4b96a07d01c9f867c1174bc1bb6ad7036691fda4fa31311c54deae979b1
7
+ data.tar.gz: 07c708405ab34720c7ed62fdaace92fff09c86dc22bb6817008abc202de6626cdf9e1511085cfd890c2a88605a1efbad758934cc0788d3e5dfc3fdd09d519f28
data/README.md CHANGED
@@ -329,7 +329,7 @@ my_parameter:
329
329
  - value2
330
330
  ```
331
331
 
332
- ## User Data Files in SparkleFormation templates
332
+ ## ERB Template Files in SparkleFormation templates
333
333
 
334
334
  An extension to SparkleFormation is the `user_data_file!` method, which evaluates templates in `templates/user_data/[file_name]`. Most of the usual SparkleFormation methods are available in user data templates. Example:
335
335
 
@@ -346,6 +346,27 @@ And used like this in SparkleFormation templates:
346
346
  user_data user_data_file!('app.erb', role: :worker)
347
347
  ```
348
348
 
349
+ You can also use the `joined_file!` method which evaluates templates in `templates/config/[file_name]`. It is similar to `user_data_file!` but doesn't do base64 encoding. Example:
350
+
351
+ ```
352
+ # templates/config/someconfig.conf.erb
353
+ my_variable=<%= ref!(:foo) %>
354
+ my_other_variable=<%= account_id! %>
355
+ ```
356
+
357
+ ```
358
+ # templates/ecs_task.rb
359
+ container_definitions array!(
360
+ -> {
361
+ command array!(
362
+ "-e",
363
+ joined_file!('someconfig.conf.erb')
364
+ )
365
+ ...
366
+ }
367
+ )
368
+ ```
369
+
349
370
  ## Commands
350
371
 
351
372
  ```bash
@@ -3,7 +3,7 @@ require 'erubis'
3
3
 
4
4
  module StackMaster
5
5
  module SparkleFormation
6
- UserDataFileNotFound = ::Class.new(StandardError)
6
+ TemplateFileNotFound = ::Class.new(StandardError)
7
7
 
8
8
  class SfEruby < Erubis::Eruby
9
9
  include Erubis::ArrayEnhancer
@@ -76,15 +76,28 @@ module StackMaster
76
76
  end
77
77
  end
78
78
 
79
- module UserDataFile
80
- def _user_data_file(file_name, vars = {})
81
- file_path = File.join(::SparkleFormation.sparkle_path, 'user_data', file_name)
79
+ module Template
80
+ def self.render(prefix, file_name, vars)
81
+ file_path = File.join(::SparkleFormation.sparkle_path, prefix, file_name)
82
82
  template = File.read(file_path)
83
83
  template_context = TemplateContext.build(vars)
84
84
  compiled_template = SfEruby.new(template).evaluate(template_context)
85
- base64!(join!(CloudFormationLineFormatter.format(compiled_template)))
85
+ CloudFormationLineFormatter.format(compiled_template)
86
86
  rescue Errno::ENOENT => e
87
- Kernel.raise UserDataFileNotFound, "Could not find user data file at path: #{file_path}"
87
+ Kernel.raise TemplateFileNotFound, "Could not find template file at path: #{file_path}"
88
+ end
89
+ end
90
+
91
+ module JoinedFile
92
+ def _joined_file(file_name, vars = {})
93
+ join!(Template.render('joined_file', file_name, vars))
94
+ end
95
+ alias_method :joined_file!, :_joined_file
96
+ end
97
+
98
+ module UserDataFile
99
+ def _user_data_file(file_name, vars = {})
100
+ base64!(join!(Template.render('user_data', file_name, vars)))
88
101
  end
89
102
  alias_method :user_data_file!, :_user_data_file
90
103
  end
@@ -92,3 +105,5 @@ module StackMaster
92
105
  end
93
106
 
94
107
  SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::UserDataFile)
108
+ SparkleFormation::SparkleAttribute::Aws.send(:include, StackMaster::SparkleFormation::JoinedFile)
109
+
@@ -2,7 +2,7 @@ module StackMaster::TemplateCompilers
2
2
  class SparkleFormation
3
3
  def self.require_dependencies
4
4
  require 'sparkle_formation'
5
- require 'stack_master/sparkle_formation/user_data_file'
5
+ require 'stack_master/sparkle_formation/template_file'
6
6
  end
7
7
 
8
8
  def self.compile(template_file_path)
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'stack_master/sparkle_formation/user_data_file'
1
+ require 'stack_master/sparkle_formation/template_file'
2
2
 
3
3
  RSpec.describe SparkleFormation::SparkleAttribute::Aws, '#user_data_file!' do
4
4
  let(:user_data) do
@@ -66,7 +66,44 @@ echo $REGION
66
66
  it 'raises a specific error' do
67
67
  expect {
68
68
  @attr.user_data_file!('test.erb')
69
- }.to raise_error(StackMaster::SparkleFormation::UserDataFileNotFound)
69
+ }.to raise_error(StackMaster::SparkleFormation::TemplateFileNotFound)
70
+ end
71
+ end
72
+ end
73
+
74
+ RSpec.describe SparkleFormation::SparkleAttribute::Aws, '#joined_file!' do
75
+ let(:config) do
76
+ <<-EOS
77
+ variable=<%= ref!(:test) %>
78
+ EOS
79
+ end
80
+
81
+ let(:expected_hash) do
82
+ {"Fn::Join"=>["", ["variable=", {"Ref"=>"Test"}, "\n"]]}
83
+ end
84
+
85
+ before do
86
+ allow(SparkleFormation).to receive(:sparkle_path).and_return('/templates_dir')
87
+ klass = Class.new(AttributeStruct)
88
+ klass.include(SparkleFormation::SparkleAttribute)
89
+ klass.include(SparkleFormation::SparkleAttribute::Aws)
90
+ klass.include(SparkleFormation::Utils::TypeCheckers)
91
+ @attr = klass.new
92
+ @attr._camel_keys = true
93
+ end
94
+
95
+ it 'reads from the config dir in templates' do
96
+ expect(File).to receive(:read).with('/templates_dir/joined_file/test.erb').and_return(config)
97
+ @attr.joined_file!('test.erb')
98
+ end
99
+
100
+ context 'when the file exists' do
101
+ before do
102
+ allow(File).to receive(:read).and_return(config)
103
+ end
104
+
105
+ it 'compiles the file and returns a joined version' do
106
+ expect(@attr.joined_file!('test.erb')).to eq expected_hash
70
107
  end
71
108
  end
72
109
  end
data/stack_master.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "timecop"
28
28
  spec.add_dependency "ruby-progressbar"
29
29
  spec.add_dependency "commander"
30
- spec.add_dependency "aws-sdk", "~> 2.2.31"
30
+ spec.add_dependency "aws-sdk", "~> 2.6.26"
31
31
  spec.add_dependency "diffy"
32
32
  spec.add_dependency "erubis"
33
33
  spec.add_dependency "colorize"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-04 00:00:00.000000000 Z
12
+ date: 2016-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -143,14 +143,14 @@ dependencies:
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: 2.2.31
146
+ version: 2.6.26
147
147
  type: :runtime
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 2.2.31
153
+ version: 2.6.26
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: diffy
156
156
  requirement: !ruby/object:Gem::Requirement
@@ -348,7 +348,7 @@ files:
348
348
  - lib/stack_master/resolver_array.rb
349
349
  - lib/stack_master/security_group_finder.rb
350
350
  - lib/stack_master/sns_topic_finder.rb
351
- - lib/stack_master/sparkle_formation/user_data_file.rb
351
+ - lib/stack_master/sparkle_formation/template_file.rb
352
352
  - lib/stack_master/stack.rb
353
353
  - lib/stack_master/stack_definition.rb
354
354
  - lib/stack_master/stack_differ.rb
@@ -405,7 +405,7 @@ files:
405
405
  - spec/stack_master/resolver_array_spec.rb
406
406
  - spec/stack_master/security_group_finder_spec.rb
407
407
  - spec/stack_master/sns_topic_finder_spec.rb
408
- - spec/stack_master/sparkle_formation/user_data_file_spec.rb
408
+ - spec/stack_master/sparkle_formation/template_file_spec.rb
409
409
  - spec/stack_master/stack_definition_spec.rb
410
410
  - spec/stack_master/stack_differ_spec.rb
411
411
  - spec/stack_master/stack_events/fetcher_spec.rb
@@ -447,7 +447,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
447
447
  version: '0'
448
448
  requirements: []
449
449
  rubyforge_project:
450
- rubygems_version: 2.4.5.1
450
+ rubygems_version: 2.5.1
451
451
  signing_key:
452
452
  specification_version: 4
453
453
  summary: StackMaster is a sure-footed way of creating, updating and keeping track
@@ -500,7 +500,7 @@ test_files:
500
500
  - spec/stack_master/resolver_array_spec.rb
501
501
  - spec/stack_master/security_group_finder_spec.rb
502
502
  - spec/stack_master/sns_topic_finder_spec.rb
503
- - spec/stack_master/sparkle_formation/user_data_file_spec.rb
503
+ - spec/stack_master/sparkle_formation/template_file_spec.rb
504
504
  - spec/stack_master/stack_definition_spec.rb
505
505
  - spec/stack_master/stack_differ_spec.rb
506
506
  - spec/stack_master/stack_events/fetcher_spec.rb