dry-stack 0.1.62 → 0.1.64
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 +4 -4
- data/lib/dry-stack/stack.rb +88 -6
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95ad6d62ec5d85d07851461288f12ed5ce8bbebaf328df21aeec840e4afd6e79
|
|
4
|
+
data.tar.gz: 29d03966adbc9b8b8364440fe32922d9b62fdd95f11c54badf5d43f3d370a2ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61044ae2310b923a97b773e4e08ef9091dbfeed006175a077e2d0b5b0650d2d09db6c4679cc73843264b6328c177c6d7f27f5082ceaa87ef18466e40a03d8b5e
|
|
7
|
+
data.tar.gz: 5a21c7f7d3f65137286ab1c1cbe1a03ebccdcc281e12231c46354da2ba880b34c8cb1c1ec1ef0323d8482f30c1e57d4e37a866fba398ee5725d52e74aef57a05
|
data/lib/dry-stack/stack.rb
CHANGED
|
@@ -143,6 +143,51 @@ module Dry
|
|
|
143
143
|
@configurations[configuration.to_sym][:block_function].call
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
+
private def ingress_mount(ing)
|
|
147
|
+
return unless ing.key?(:mount)
|
|
148
|
+
|
|
149
|
+
conflicts = %i[path path_sub path_regexp host_sni] & ing.keys
|
|
150
|
+
raise ArgumentError, "ingress mount cannot be combined with #{conflicts.join(', ')}" unless conflicts.empty?
|
|
151
|
+
|
|
152
|
+
ingress_path(ing[:mount], :mount)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private def ingress_path(value, option, root: false)
|
|
156
|
+
return '' if root && value == '/'
|
|
157
|
+
|
|
158
|
+
unless value.is_a?(String) && value.match?(%r{\A/[A-Za-z0-9._~!$&'()*+;=:@/-]+\z})
|
|
159
|
+
raise ArgumentError, "ingress #{option} requires a literal absolute URL path without encoding, query, fragment or comma"
|
|
160
|
+
end
|
|
161
|
+
path = value.delete_suffix('/')
|
|
162
|
+
if path.empty? || path.split('/', -1).drop(1).any? { _1.empty? || %w[. ..].include?(_1) }
|
|
163
|
+
raise ArgumentError, "ingress #{option} must have nonempty path segments other than . or .."
|
|
164
|
+
end
|
|
165
|
+
path
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
private def ingress_http_options(ing, mount)
|
|
169
|
+
%i[target_prefix redirect_root].each do |option|
|
|
170
|
+
next unless ing.key?(option)
|
|
171
|
+
|
|
172
|
+
conflicts = %i[path path_sub path_regexp host_sni] & ing.keys
|
|
173
|
+
raise ArgumentError, "ingress #{option} cannot be combined with #{conflicts.join(', ')}" unless conflicts.empty?
|
|
174
|
+
end
|
|
175
|
+
target = ingress_path(ing[:target_prefix], :target_prefix, root: true) if ing.key?(:target_prefix)
|
|
176
|
+
if ing.key?(:redirect_root)
|
|
177
|
+
redirect = ingress_path(ing[:redirect_root], :redirect_root, root: true)
|
|
178
|
+
raise ArgumentError, 'ingress redirect_root must differ from the public route root' if redirect == mount.to_s
|
|
179
|
+
end
|
|
180
|
+
if ing.key?(:service)
|
|
181
|
+
backend = ing[:service]
|
|
182
|
+
unless backend.is_a?(String) && backend.match?(/\A[A-Za-z0-9_.-]+(?:@[A-Za-z0-9_.-]+)?\z/)
|
|
183
|
+
raise ArgumentError, 'ingress service requires a Traefik service name, optionally qualified with @provider'
|
|
184
|
+
end
|
|
185
|
+
conflicts = %i[port url host_sni] & ing.keys
|
|
186
|
+
raise ArgumentError, "ingress service cannot be combined with #{conflicts.join(', ')}" unless conflicts.empty?
|
|
187
|
+
end
|
|
188
|
+
[target, ing[:redirect_root], backend]
|
|
189
|
+
end
|
|
190
|
+
|
|
146
191
|
def to_compose(opts = @options)
|
|
147
192
|
@name = @options[:name] || @name
|
|
148
193
|
deploy_source = opts[:deploy_source].to_s.strip
|
|
@@ -195,13 +240,13 @@ module Dry
|
|
|
195
240
|
|
|
196
241
|
if ingress[0] && (opts[:traefik] || opts[:traefik_tls])
|
|
197
242
|
service[:deploy][:labels] << 'traefik.enable=true'
|
|
198
|
-
ingress[0][:port] ||= service[:ports]&.first
|
|
199
|
-
|
|
200
243
|
ingress.each_with_index do |ing, index|
|
|
201
|
-
|
|
244
|
+
mount = ingress_mount(ing)
|
|
245
|
+
target, redirect, backend = ingress_http_options(ing, mount)
|
|
246
|
+
port = backend ? nil : (ing[:port] || service[:ports]&.first)
|
|
202
247
|
load_balancer = []
|
|
203
248
|
load_balancer << "server.url=#{ing[:url]}" if ing[:url]
|
|
204
|
-
load_balancer << "server.port=#{
|
|
249
|
+
load_balancer << "server.port=#{port}" if port
|
|
205
250
|
|
|
206
251
|
if ing[:host_sni]
|
|
207
252
|
domain = opts[:tls_domain] || 'example.com'
|
|
@@ -233,7 +278,7 @@ module Dry
|
|
|
233
278
|
|
|
234
279
|
else
|
|
235
280
|
service[:deploy][:labels] += [
|
|
236
|
-
"traefik.http.routers.#{service_name}-#{index}.service=#{service_name}-#{index}",
|
|
281
|
+
"traefik.http.routers.#{service_name}-#{index}.service=#{backend || "#{service_name}-#{index}"}",
|
|
237
282
|
]
|
|
238
283
|
service[:deploy][:labels] += load_balancer.map { "traefik.http.services.#{service_name}-#{index}.loadbalancer.#{_1}" }
|
|
239
284
|
|
|
@@ -258,7 +303,11 @@ module Dry
|
|
|
258
303
|
rule = []
|
|
259
304
|
rule << "HostRegexp(`{name:#{nginx_host2regexp ing[:host]}}`)" if ing[:host]
|
|
260
305
|
rule << "ClientIP(#{[ing[:client_ip]].flatten.map{ "`#{_1}`" }.join ','})" if ing[:client_ip]
|
|
261
|
-
|
|
306
|
+
if mount
|
|
307
|
+
rule << "(Path(`#{mount}`) || PathPrefix(`#{mount}/`))".gsub('$', '$$')
|
|
308
|
+
else
|
|
309
|
+
rule << "PathPrefix(`#{ing[:path]}`)" if ing[:path]
|
|
310
|
+
end
|
|
262
311
|
rule << "PathRegexp(`#{ing[:path_regexp]}`)" if ing[:path_regexp]
|
|
263
312
|
rule << "#{ing[:rule]}" if ing[:rule]
|
|
264
313
|
|
|
@@ -282,6 +331,32 @@ module Dry
|
|
|
282
331
|
service[:deploy][:labels] << "traefik.http.routers.#{service_name}-#{index}.rule=#{rule.join ' && '}"
|
|
283
332
|
service[:deploy][:labels] << "traefik.http.routers.#{service_name}-#{index}.priority=#{ing[:priority].to_i}" if ing[:priority]
|
|
284
333
|
|
|
334
|
+
if mount || redirect
|
|
335
|
+
prefix = "#{service_name}-#{index}-mount"
|
|
336
|
+
regex = "^(https?://[^/]+#{Regexp.escape(mount.to_s)})(\\?.*)?$"
|
|
337
|
+
replacement = '${1}/${2}'
|
|
338
|
+
if redirect
|
|
339
|
+
root = mount ? "#{Regexp.escape(mount)}/?" : '/'
|
|
340
|
+
regex = "^(https?://[^/]+)#{root}(\\?.*)?$"
|
|
341
|
+
replacement = "${1}#{redirect.gsub('$', '$$')}${2}"
|
|
342
|
+
end
|
|
343
|
+
middlewares << "#{prefix}-redirect"
|
|
344
|
+
service[:deploy][:labels] += [
|
|
345
|
+
"traefik.http.middlewares.#{prefix}-redirect.redirectregex.regex=#{regex.gsub('$', '$$')}",
|
|
346
|
+
"traefik.http.middlewares.#{prefix}-redirect.redirectregex.replacement=#{replacement.gsub('$', '$$')}",
|
|
347
|
+
"traefik.http.middlewares.#{prefix}-redirect.redirectregex.permanent=false"
|
|
348
|
+
]
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
if mount && mount != target
|
|
352
|
+
middlewares << "#{service_name}-#{index}-mount-strip"
|
|
353
|
+
service[:deploy][:labels] << "traefik.http.middlewares.#{service_name}-#{index}-mount-strip.stripprefix.prefixes=#{mount.gsub('$', '$$')}"
|
|
354
|
+
end
|
|
355
|
+
if target && !target.empty? && target != mount
|
|
356
|
+
middlewares << "#{service_name}-#{index}-target"
|
|
357
|
+
service[:deploy][:labels] << "traefik.http.middlewares.#{service_name}-#{index}-target.addprefix.prefix=#{target.gsub('$', '$$')}"
|
|
358
|
+
end
|
|
359
|
+
|
|
285
360
|
if ing[:path_sub]
|
|
286
361
|
middlewares << "#{service_name}-#{index}-path_sub"
|
|
287
362
|
service[:deploy][:labels] += [
|
|
@@ -293,6 +368,13 @@ module Dry
|
|
|
293
368
|
service[:deploy][:labels] << "traefik.http.routers.#{service_name}-#{index}.middlewares=#{middlewares.join ","}" unless middlewares.empty?
|
|
294
369
|
end
|
|
295
370
|
end
|
|
371
|
+
|
|
372
|
+
http_ingress = ingress.reject { _1[:host_sni] }
|
|
373
|
+
if http_ingress.any? && http_ingress.all? { _1[:service] } &&
|
|
374
|
+
service[:deploy][:labels].none? { _1.start_with?('traefik.http.services.') }
|
|
375
|
+
# Swarm requires a port even when every HTTP router uses an existing service.
|
|
376
|
+
service[:deploy][:labels] << "traefik.http.services.#{service_name}-unused.loadbalancer.server.port=9999"
|
|
377
|
+
end
|
|
296
378
|
end
|
|
297
379
|
service.delete :ingress
|
|
298
380
|
service.delete :oauth_provider
|
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.64
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artyom B
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
131
|
- !ruby/object:Gem::Version
|
|
132
132
|
version: '0'
|
|
133
133
|
requirements: []
|
|
134
|
-
rubygems_version: 3.3.
|
|
134
|
+
rubygems_version: 3.3.27
|
|
135
135
|
signing_key:
|
|
136
136
|
specification_version: 4
|
|
137
137
|
summary: Dry docker swarm stack definition
|