dry-stack 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dry-stack/stack.rb +18 -20
  3. data/lib/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee77026f4dbbad4d93821303e117f494ca9ee63277d6ac75f9ee4bd4bf8f85f3
4
- data.tar.gz: 115fd41b201a1483b0485639309e06f132f1247a7712f8c4a49ed26197ef3fa9
3
+ metadata.gz: cbaeac98b043b8dccbbd59e01fd5777b7e9f6a94a7020e560750ee537c283e83
4
+ data.tar.gz: 7cb8549b37702848f761d7a56afb4baed6a73a419282415bd680aae2b76d7ebd
5
5
  SHA512:
6
- metadata.gz: da8b13fa2ede538ad057ff761e5a66c9764e4c246581687bdafafbe6f7783fe036c3b1ff4580032a4fc103b4e2ff936a4001b62efa16b4be1342fb421ffb9969
7
- data.tar.gz: 75fd19165a78349b402fd32c1a913c5b0697e833a448de9284e890657e7f9ea2c1aab94f281f877e6afcb51ada962c49eb485f88e0ea9941f265d2a94f0ff4fa
6
+ metadata.gz: 20109696956962c30782c47495ffcf267e7c9360fd9793bff44e9dbd30cdec3efb2824b8ac729399f01b2abcc3544daa61c5b71c5ba31f6593af1ce34a41d5ea
7
+ data.tar.gz: a14a9a310271f6dfa43059ad027dc6f8e3ac18d8e776d952af24ce9a4de11e365d58ce25de5b46914e454665ebed1d8c432604048947a5451667d5de74ff3ac2
@@ -14,6 +14,8 @@ require_relative 'apache_specific_md5'
14
14
  # end
15
15
 
16
16
  module Dry
17
+ EMPTY_HASH = :empty_hash
18
+
17
19
  class ::Hash
18
20
  def deep_merge!(second)
19
21
  merger = proc { |_, v1, v2|
@@ -65,7 +67,7 @@ module Dry
65
67
  def config(name = nil, opts)= (@service[:configs] ||= []) << {source: name.to_s}.merge(opts)
66
68
  def logging(opts) = (@service[:logging] ||= {}).merge! opts
67
69
  def user(user) = @service[:user] = user # "${UID}:${GID}", "www-data:www-data"
68
- def network(names) = (@service[:networks] ||= []) << names
70
+ def network(name, opts = {}) = (@service[:networks][name] ||={}).merge! opts
69
71
  def ingress(ing) = ((@service[:ingress] ||=[]) << ing).flatten!
70
72
  end
71
73
 
@@ -160,9 +162,9 @@ module Dry
160
162
  service[:deploy][:labels] += @labels.map { "#{_1}=#{_2}" }
161
163
 
162
164
  if ingress[0] && (opts[:ingress] || opts[:traefik] || opts[:traefik_tls])
163
- service[:networks] ||= []
164
- service[:networks] << 'default' if service[:networks].empty?
165
- service[:networks] << 'ingress_routing'
165
+ service[:networks] ||= {}
166
+ service[:networks][:default] ||= {} if service[:networks].empty?
167
+ service[:networks][:ingress_routing] ||= {}
166
168
  end
167
169
 
168
170
  ingress.each do |rule|
@@ -266,21 +268,15 @@ module Dry
266
268
  end
267
269
  end
268
270
 
269
- service[:networks]&.map! do |network|
270
- if network.is_a?(Hash)
271
- if network.key?(:name)
272
- n_name = network[:name].gsub('-','_').to_sym
273
- if n_name != :default
274
- (compose[:networks][n_name] ||= {}).merge! network
275
- end
276
- n_name
277
- else
278
- $stderr.puts ':name must be specified in network declaration'
279
- raise 'invalid network declaration'
280
- end
281
- else
282
- network
271
+ service[:networks]&.each do |name, network|
272
+ next unless network.is_a? Hash
273
+
274
+ if network[:name]
275
+ (compose[:networks][name] ||= {}).merge! network.except(:aliases).merge(name: network[:name])
283
276
  end
277
+ network.delete :external
278
+ network.delete :name
279
+ service[:networks][name] = EMPTY_HASH if network.empty?
284
280
  end
285
281
 
286
282
  service[:configs]&.each_with_index do |config, index|
@@ -311,14 +307,16 @@ module Dry
311
307
 
312
308
  prune = ->(o) {
313
309
  o.each { prune[_2] } if o.is_a? Hash
314
- o.delete_if { _2.nil? || (_2.respond_to?(:empty?) && _2.empty?) } if o.is_a? Hash
310
+ o.delete_if { _2.nil? || ( _2.respond_to?(:empty?) && _2.empty?) } if o.is_a? Hash
315
311
  }
316
312
  prune[compose]
317
313
 
318
314
  each_recursive _root: compose do |_path, node, v|
315
+
319
316
  v.transform_keys!(&:to_s) if v.is_a? Hash
320
317
  node.transform_keys!(&:to_s) if node.is_a? Hash
321
318
  _path.last[node] = v.to_s if v.is_a? Symbol
319
+ _path.last[node] = nil if v == EMPTY_HASH
322
320
 
323
321
  _path.last[node] = v.to_s if node.to_s == 'fluentd-async'
324
322
  end
@@ -376,7 +374,7 @@ module Dry
376
374
  opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
377
375
  opts[:environment] = opts.delete(:env) if opts.key? :env
378
376
 
379
- service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
377
+ service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}, networks: {}}
380
378
  service.deep_merge! opts
381
379
  ServiceFunction.new(service, &) if block_given?
382
380
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Stack
3
- VERSION = '0.1.11'
3
+ VERSION = '0.1.12'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-14 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake