dry-stack 0.1.11 → 0.1.13

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 +22 -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: 54ac4c65eb9a540d8b78351dc5bdc4510034618928f212532fa18a18db143ac2
4
+ data.tar.gz: cc6ccabf6a2a75b31236355012cfb033ce732f1b2379996aa519068ba95a51bd
5
5
  SHA512:
6
- metadata.gz: da8b13fa2ede538ad057ff761e5a66c9764e4c246581687bdafafbe6f7783fe036c3b1ff4580032a4fc103b4e2ff936a4001b62efa16b4be1342fb421ffb9969
7
- data.tar.gz: 75fd19165a78349b402fd32c1a913c5b0697e833a448de9284e890657e7f9ea2c1aab94f281f877e6afcb51ada962c49eb485f88e0ea9941f265d2a94f0ff4fa
6
+ metadata.gz: 4873a1ff78e0ff316448b84d33d2dee65c928069b30a575dc45af76635884ee77de33dd8aa6178aff29e21d05cbd2dc35c488d21c4cc92ff71830414771bc2b0
7
+ data.tar.gz: 8f85f6126686c34d6219dd8a21f50d8765d34fe1db4e9a4b6f753894d48bb5f0a609035dc9fd92b550d9df863b27948044ad081208d528435b9996c7977e1fdf
@@ -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|
@@ -309,16 +305,22 @@ module Dry
309
305
  end
310
306
  end
311
307
 
308
+ compose[:networks].transform_values! do |network|
309
+ network.empty? ? EMPTY_HASH : network
310
+ end
311
+
312
312
  prune = ->(o) {
313
313
  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
314
+ o.delete_if { _2.nil? || ( _2.respond_to?(:empty?) && _2.empty?) } if o.is_a? Hash
315
315
  }
316
316
  prune[compose]
317
317
 
318
318
  each_recursive _root: compose do |_path, node, v|
319
+
319
320
  v.transform_keys!(&:to_s) if v.is_a? Hash
320
321
  node.transform_keys!(&:to_s) if node.is_a? Hash
321
322
  _path.last[node] = v.to_s if v.is_a? Symbol
323
+ _path.last[node] = nil if v == EMPTY_HASH
322
324
 
323
325
  _path.last[node] = v.to_s if node.to_s == 'fluentd-async'
324
326
  end
@@ -376,7 +378,7 @@ module Dry
376
378
  opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
377
379
  opts[:environment] = opts.delete(:env) if opts.key? :env
378
380
 
379
- service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
381
+ service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}, networks: {}}
380
382
  service.deep_merge! opts
381
383
  ServiceFunction.new(service, &) if block_given?
382
384
  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.13'
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.13
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