seira 0.4.3 → 0.4.4

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: 7dc4d9f9ef065f08ef6890cdff4d3e53609b4c87
4
- data.tar.gz: 77bcbfdde4975bbb2893103c1b13556e43f2ed0b
3
+ metadata.gz: 0d7dd4175a2ca8716b7226970d47d7273024ef9d
4
+ data.tar.gz: 9fbc31ace33e51e8eaccacbeb928a2ff7ba48a32
5
5
  SHA512:
6
- metadata.gz: f267f44d5e953aa8bfaaaace6f673c4c55c8be016a8bc83e39a1925e5414b904557f2de4fba931391e8c42bd4ce045fe645aa35d553726b955e28308bb0a6d5b
7
- data.tar.gz: cf2e852fd7645b16bfdf25752295342fbe31192c44501e3b7e1cf236451381de8ed45662bf1c09834f03b9b5368bfc82755b5b7b1ffe38ec8be1f090615f7a97
6
+ metadata.gz: 0c161b97c31a7798c21b7c76076082c53984be70ce9570faa683306b5018225ad6718c7b17deec62e67479e0187012c79c6f3a1142d16e1192cf8e143883ef77
7
+ data.tar.gz: f09128aed8bb270c446110192ce94de26bc51fd2f91a098a90df5b7de0894e083ec77b3daafe2d0b061260ffc374ddf79621ca0e5e942c15e5284047c151b420
@@ -30,6 +30,11 @@ module Seira
30
30
  Secrets.new(app: context[:app], action: 'get', args: [], context: context).get(key)
31
31
  end
32
32
 
33
+ def get_current_replicas(deployment:, context:)
34
+ output = Seira::Commands.kubectl("get deployment #{deployment} -o json", context: context, return_output: true)
35
+ JSON.parse(output)['spec']['replicas']
36
+ end
37
+
33
38
  def shell_username
34
39
  `whoami`
35
40
  rescue
@@ -20,6 +20,7 @@ require 'seira/secrets'
20
20
  require 'seira/settings'
21
21
  require 'seira/setup'
22
22
  require 'seira/node_pools'
23
+ require 'seira/util/resource_renderer'
23
24
 
24
25
  # A base runner class that does base checks and then delegates the actual
25
26
  # work for the command to a class in lib/seira folder.
@@ -206,12 +206,21 @@ module Seira
206
206
  # If we have run into a directory item, skip it
207
207
  next if File.directory?("#{source}/#{item}")
208
208
 
209
- # Skip any manifest file that has "seira-skip.yaml" at the end. Common use case is for Job definitions
209
+ # Skip any manifest file that has "seira-skip.yaml" in the file name (ERB or not). Common use case is for Job definitions
210
210
  # to be used in "seira staging <app> jobs run"
211
- next if item.end_with?("seira-skip.yaml")
211
+ next if item.include?("seira-skip.yaml")
212
212
 
213
213
  text = File.read("#{source}/#{item}")
214
214
 
215
+ # First run it through ERB if it should be
216
+ if item.end_with?('.erb')
217
+ locals = {}.merge(replacement_hash)
218
+ renderer = Seira::Util::ResourceRenderer.new(template: text, context: context, locals: locals)
219
+ text = renderer.render
220
+ end
221
+
222
+ # Then run through old basic find/replace tempalating.
223
+ # TODO: Do deprecation process for old home-made templating
215
224
  new_contents = text
216
225
  replacement_hash.each do |key, value|
217
226
  new_contents.gsub!(key, value)
@@ -0,0 +1,50 @@
1
+ module Seira
2
+ module Util
3
+ class ResourceRenderer
4
+ include ERB::Util
5
+
6
+ def initialize(template:, context:, locals:)
7
+ @template = template
8
+ @context = context
9
+ @locals = locals
10
+ @summary = {}
11
+ end
12
+
13
+ # "binding" is a special method every ruby object has to expose its
14
+ # instance variables
15
+ # https://ruby-doc.org/core-2.2.0/Binding.html
16
+ def render
17
+ result = ERB.new(@template).result(binding)
18
+
19
+ puts "Rendered with following ERB variables:"
20
+ @summary.each do |key, value|
21
+ puts "#{key}: #{value}"
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ # BEGIN ERB templating methods and variables
28
+ def current_replica_count(deployment)
29
+ count = Seira::Helpers.get_current_replicas(deployment: deployment, context: @context)
30
+ @summary["#{deployment}-replicas"] = count
31
+
32
+ # Validate a sane count so that we don't accidentally deploy 0 replicas
33
+ unless count && count.is_a?(Integer)
34
+ fail "Received invalid value for replica count for Deployment #{deployment} '#{count}'"
35
+ end
36
+
37
+ count
38
+ end
39
+
40
+ def target_revision
41
+ @locals['REVISION']
42
+ end
43
+
44
+ def restarted_at_value
45
+ @locals['RESTARTED_AT_VALUE']
46
+ end
47
+ # END ERB templating methods and variables
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Seira
2
- VERSION = "0.4.3".freeze
2
+ VERSION = "0.4.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -135,6 +135,7 @@ files:
135
135
  - lib/seira/secrets.rb
136
136
  - lib/seira/settings.rb
137
137
  - lib/seira/setup.rb
138
+ - lib/seira/util/resource_renderer.rb
138
139
  - lib/seira/version.rb
139
140
  - seira.gemspec
140
141
  homepage: https://github.com/joinhandshake/seira