dry-stack 0.1.14 → 0.1.16

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 +23 -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: 9b41f8af6bdca698d05c32a0d92a406473d6d6ccdc8b30cad42dff9545cde0f5
4
- data.tar.gz: e5c3103939a0ab2b6a0205872f034d00ab60181d7e991127fa0b31adf8570cc9
3
+ metadata.gz: b5ebf65f6db6234c39d5bfe0b4b6c0be4dc1a2528a361a497b3aa80d093b3e02
4
+ data.tar.gz: 823bc35c24d568a2c76b4ed921e13e2ed6c9779a1deab5abcf22cc54bb97bc58
5
5
  SHA512:
6
- metadata.gz: 2e8c41dc8516b11bf54f0470cf8cdedc105a0d6812567c59d06a98db5b22da64a7fec6111a47de1e135e1b65f49fdcca141e81effdb6e917001fdcd5a386f3a2
7
- data.tar.gz: 6d74c7b2af40b3a36cdcddf9a1ff0546679b86cc4be3c50cb081db967170a7f7feafc576532e2bce8506d9872e7b03e541dfa0c0acec503757f30692481b1040
6
+ metadata.gz: 0eb24c92c82d33345308c66f430ffce14cad8fc841c212c9f9927f13c3273c9d66eff66f9dffe25ca7aad43e26a10b5cedda1fef1572b45ac23875490497e03c
7
+ data.tar.gz: 829f7596fda69391400a2166256632c2e4b5516cf6b07ae445a7c7eb49c24c90e8df80cc9558424b2dc9d3e6f36a33fc0e2abb56eb82be89fac18f262dd17a30
@@ -41,6 +41,19 @@ module Dry
41
41
  end
42
42
  end
43
43
 
44
+ def expand_hash(hash)
45
+ hash.select { _1.to_s =~ /\./ }.each do |k, v|
46
+ name = k.to_s.scan(/([^\.]*)\.(.*)/).flatten
47
+ hash.delete k
48
+ hash[name[0]] ||= {}
49
+ hash[name[0]][name[1]] ||= {}
50
+ hash[name[0]][name[1]].merge! v if v.is_a?(Hash)
51
+ hash[name[0]][name[1]] = v unless v.is_a?(Hash)
52
+ end
53
+ hash.each { expand_hash(_2) if _2.is_a?(Hash) }
54
+ hash
55
+ end
56
+
44
57
  attr_accessor :cmd_params
45
58
  @cmd_params = {}
46
59
 
@@ -64,6 +77,7 @@ module Dry
64
77
  def command(cmd)= @service[:command] = cmd
65
78
  def entrypoint(cmd)= @service[:entrypoint] = cmd
66
79
  def deploy_label(str)= @service[:deploy][:labels] << str
80
+ def deploy(opts)=@service[:deploy].merge! expand_hash(opts)
67
81
  def config(name = nil, opts)= (@service[:configs] ||= []) << {source: name.to_s}.merge(opts)
68
82
  def logging(opts) = (@service[:logging] ||= {}).merge! opts
69
83
  def user(user) = @service[:user] = user # "${UID}:${GID}", "www-data:www-data"
@@ -106,19 +120,6 @@ module Dry
106
120
  @configurations = {}
107
121
  end
108
122
 
109
- def expand_hash(hash)
110
- hash.select { _1.to_s =~ /\./ }.each do |k, v|
111
- name = k.to_s.scan(/([^\.]*)\.(.*)/).flatten
112
- hash.delete k
113
- hash[name[0]] ||= {}
114
- hash[name[0]][name[1]] ||= {}
115
- hash[name[0]][name[1]].merge! v if v.is_a?(Hash)
116
- hash[name[0]][name[1]] = v unless v.is_a?(Hash)
117
- end
118
- hash.each { expand_hash(_2) if _2.is_a?(Hash) }
119
- hash
120
- end
121
-
122
123
  def nginx_host2regexp(str)
123
124
  # http://nginx.org/en/docs/http/server_names.html
124
125
  if str[0] == '~'
@@ -231,13 +232,15 @@ module Dry
231
232
 
232
233
  service[:deploy].deep_merge! @deploy[name] if @deploy[name]
233
234
 
234
- hash = {'service-name': service_name, 'stack-name': @name}
235
- hash.default = ''
236
- original_verbosity = $VERBOSE
237
- $VERBOSE = nil
238
- service[:deploy][:labels] = service[:deploy][:labels].map{ _1 % hash }
239
- service[:environment].transform_values!{ _1.is_a?(String) ? (_1 % hash) : _1 }
240
- $VERBOSE = original_verbosity
235
+ # hash = {'service-name': service_name, 'stack-name': @name}
236
+ env_sub = ->(s) {
237
+ s = s.to_s.dup
238
+ s.gsub!('%{stack-name}', @name.to_s)
239
+ s.gsub!('%{service-name}', service_name)
240
+ s
241
+ }
242
+ service[:deploy][:labels] = service[:deploy][:labels].map{ env_sub[_1] }
243
+ service[:environment].transform_values!{ _1.is_a?(String) ? (env_sub[_1]) : _1 }
241
244
 
242
245
  pp_i = @publish_ports[name]&.reject { _1.class == String }
243
246
  pp_s = @publish_ports[name]&.select { _1.class == String }
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Stack
3
- VERSION = '0.1.14'
3
+ VERSION = '0.1.16'
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.14
4
+ version: 0.1.16
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-09-05 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake