dry-stack 0.1.10 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dry-stack/command_line.rb +0 -1
- data/lib/dry-stack/stack.rb +50 -26
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbaeac98b043b8dccbbd59e01fd5777b7e9f6a94a7020e560750ee537c283e83
|
4
|
+
data.tar.gz: 7cb8549b37702848f761d7a56afb4baed6a73a419282415bd680aae2b76d7ebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20109696956962c30782c47495ffcf267e7c9360fd9793bff44e9dbd30cdec3efb2824b8ac729399f01b2abcc3544daa61c5b71c5ba31f6593af1ce34a41d5ea
|
7
|
+
data.tar.gz: a14a9a310271f6dfa43059ad027dc6f8e3ac18d8e776d952af24ce9a4de11e365d58ce25de5b46914e454665ebed1d8c432604048947a5451667d5de74ff3ac2
|
data/lib/dry-stack/stack.rb
CHANGED
@@ -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|
|
@@ -45,6 +47,10 @@ module Dry
|
|
45
47
|
def Stack(name = nil, configuration = nil, &)
|
46
48
|
Stack.last_stack = Stack.new name
|
47
49
|
Stack.last_stack.instance_exec(&) if block_given?
|
50
|
+
Stack.last_stack.instance_exec do
|
51
|
+
@services_blocks&.each { instance_exec &_1 }
|
52
|
+
@after_blocks&.each { instance_exec &_1 }
|
53
|
+
end
|
48
54
|
Stack.last_stack.apply_configuration configuration if configuration
|
49
55
|
end
|
50
56
|
|
@@ -61,7 +67,7 @@ module Dry
|
|
61
67
|
def config(name = nil, opts)= (@service[:configs] ||= []) << {source: name.to_s}.merge(opts)
|
62
68
|
def logging(opts) = (@service[:logging] ||= {}).merge! opts
|
63
69
|
def user(user) = @service[:user] = user # "${UID}:${GID}", "www-data:www-data"
|
64
|
-
def network(
|
70
|
+
def network(name, opts = {}) = (@service[:networks][name] ||={}).merge! opts
|
65
71
|
def ingress(ing) = ((@service[:ingress] ||=[]) << ing).flatten!
|
66
72
|
end
|
67
73
|
|
@@ -147,7 +153,7 @@ module Dry
|
|
147
153
|
|
148
154
|
compose[:services].each do |name, service|
|
149
155
|
|
150
|
-
service[:image].gsub!(/:latest$/, '') # let docker swarm to create tag: :latest@sha265:0000...
|
156
|
+
service[:image].gsub!(/:latest$/, '') if service[:image] # let docker swarm to create tag: :latest@sha265:0000...
|
151
157
|
|
152
158
|
ingress = [@ingress[name], service[:ingress] || [] ].flatten.compact
|
153
159
|
|
@@ -156,9 +162,9 @@ module Dry
|
|
156
162
|
service[:deploy][:labels] += @labels.map { "#{_1}=#{_2}" }
|
157
163
|
|
158
164
|
if ingress[0] && (opts[:ingress] || opts[:traefik] || opts[:traefik_tls])
|
159
|
-
service[:networks] ||=
|
160
|
-
service[:networks]
|
161
|
-
service[:networks]
|
165
|
+
service[:networks] ||= {}
|
166
|
+
service[:networks][:default] ||= {} if service[:networks].empty?
|
167
|
+
service[:networks][:ingress_routing] ||= {}
|
162
168
|
end
|
163
169
|
|
164
170
|
ingress.each do |rule|
|
@@ -262,21 +268,15 @@ module Dry
|
|
262
268
|
end
|
263
269
|
end
|
264
270
|
|
265
|
-
service[:networks]&.
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
(compose[:networks][n_name] ||= {}).merge! network
|
271
|
-
end
|
272
|
-
n_name
|
273
|
-
else
|
274
|
-
$stderr.puts ':name must be specified in network declaration'
|
275
|
-
raise 'invalid network declaration'
|
276
|
-
end
|
277
|
-
else
|
278
|
-
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])
|
279
276
|
end
|
277
|
+
network.delete :external
|
278
|
+
network.delete :name
|
279
|
+
service[:networks][name] = EMPTY_HASH if network.empty?
|
280
280
|
end
|
281
281
|
|
282
282
|
service[:configs]&.each_with_index do |config, index|
|
@@ -307,14 +307,16 @@ module Dry
|
|
307
307
|
|
308
308
|
prune = ->(o) {
|
309
309
|
o.each { prune[_2] } if o.is_a? Hash
|
310
|
-
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
|
311
311
|
}
|
312
312
|
prune[compose]
|
313
313
|
|
314
314
|
each_recursive _root: compose do |_path, node, v|
|
315
|
+
|
315
316
|
v.transform_keys!(&:to_s) if v.is_a? Hash
|
316
317
|
node.transform_keys!(&:to_s) if node.is_a? Hash
|
317
318
|
_path.last[node] = v.to_s if v.is_a? Symbol
|
319
|
+
_path.last[node] = nil if v == EMPTY_HASH
|
318
320
|
|
319
321
|
_path.last[node] = v.to_s if node.to_s == 'fluentd-async'
|
320
322
|
end
|
@@ -332,11 +334,19 @@ module Dry
|
|
332
334
|
(@after_blocks ||=[]) << block
|
333
335
|
end
|
334
336
|
|
335
|
-
def
|
337
|
+
def BeforeService(name = nil, opts = {}, &block)
|
338
|
+
(@before_blocks ||=[]).push names: [name].flatten.compact, except: opts[:except],
|
339
|
+
block: ->(s_name) {
|
340
|
+
_ServiceImplementation s_name, opts, &block
|
341
|
+
}
|
342
|
+
end
|
343
|
+
|
344
|
+
def AfterService(name = nil, opts = {}, &block)
|
336
345
|
After do
|
337
|
-
name
|
338
|
-
[
|
339
|
-
|
346
|
+
names = [name || @services.keys].flatten
|
347
|
+
names -= [opts[:except]].flatten if opts.key? :except
|
348
|
+
names.each do |s_name|
|
349
|
+
_ServiceImplementation s_name, opts, &block
|
340
350
|
end
|
341
351
|
end
|
342
352
|
end
|
@@ -345,12 +355,26 @@ module Dry
|
|
345
355
|
@publish_ports.merge! ports.to_h { |k, v| [k,[v].flatten] }
|
346
356
|
end
|
347
357
|
|
348
|
-
def Service(name, opts = {}, &)
|
358
|
+
def Service(name, opts = {}, &block)
|
359
|
+
@services_blocks ||=[]
|
360
|
+
(@services_blocks ||=[]).push -> { _ServiceDeferred(name, opts, &block) }
|
361
|
+
end
|
362
|
+
|
363
|
+
def _ServiceDeferred(name, opts = {}, &block)
|
364
|
+
(@before_blocks || []).each do |before|
|
365
|
+
next unless before[:names].empty? || before[:names].include?(name)
|
366
|
+
next if before[:except]&.include? name
|
367
|
+
before[:block].call(name)
|
368
|
+
end
|
369
|
+
_ServiceImplementation(name, opts, &block)
|
370
|
+
end
|
371
|
+
|
372
|
+
def _ServiceImplementation(name, opts = {}, &)
|
349
373
|
opts = opts.dup
|
350
374
|
opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
|
351
375
|
opts[:environment] = opts.delete(:env) if opts.key? :env
|
352
376
|
|
353
|
-
service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
|
377
|
+
service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}, networks: {}}
|
354
378
|
service.deep_merge! opts
|
355
379
|
ServiceFunction.new(service, &) if block_given?
|
356
380
|
end
|
data/lib/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|