Skip to content

Commit ba7a1d0

Browse files
committed
update
1 parent ce42ae2 commit ba7a1d0

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

lib/dry-stack/stack.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def logging(opts) = (@service[:logging] ||= {}).merge! opts
8484
def user(user) = @service[:user] = user # "${UID}:${GID}", "www-data:www-data"
8585
def network(name, opts = {}) = (@service[:networks][name] ||={}).merge! opts
8686
def ingress(ing) = ((@service[:ingress] ||=[]) << ing).flatten!
87+
def oauth_provider(address) = (@service[:oauth_provider] = address)
8788
end
8889

8990
class ConfigurationFunction
@@ -234,6 +235,13 @@ def to_compose(opts = @options)
234235
rule << "#{ing[:rule]}" if ing[:rule]
235236

236237
middlewares = []
238+
if ing[:oauth_provider] || service[:oauth_provider]
239+
pname = "#{service_name}-#{index}_oauth_provider"
240+
value = ing[:oauth_provider] || service[:oauth_provider]
241+
value = "http://#{value}" unless value =~ /^http/
242+
middlewares << pname
243+
service[:deploy][:labels] << "traefik.http.middlewares.#{pname}.forwardauth.address=#{value}"
244+
end
237245

238246
if ing[:basic_auth]
239247
ba_user, ba_password, salt = ing[:basic_auth].split ':'
@@ -257,6 +265,7 @@ def to_compose(opts = @options)
257265
end
258266
end
259267
service.delete :ingress
268+
service.delete :oauth_provider
260269

261270
service[:environment] = @environment[name].merge(service[:environment]) if @environment[name]
262271
service[:environment].merge! STACK_NAME: @name.to_s, STACK_SERVICE_NAME: name.to_s

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Dry
22
class Stack
3-
VERSION = '0.1.45'
3+
VERSION = '0.1.46'
44
end
55
end

spec/data/stack18-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ services:
1919
ingress_routing:
2020
init: true
2121
image: reports:0.1
22+
front2:
23+
environment:
24+
STACK_NAME: stack
25+
STACK_SERVICE_NAME: front2
26+
deploy:
27+
labels:
28+
- traefik.enable=true
29+
- traefik.http.routers.stack_front2-0.service=stack_front2-0
30+
- traefik.http.services.stack_front2-0.loadbalancer.server.port=7000
31+
- traefik.http.routers.stack_front2-0.tls=true
32+
- traefik.http.routers.stack_front2-0.tls.certresolver=le
33+
- traefik.http.routers.stack_front2-0.tls.domains[0].main=my.com
34+
- traefik.http.routers.stack_front2-0.rule=PathPrefix(`/test`)
35+
networks:
36+
default:
37+
ingress_routing:
38+
init: true
39+
image: reports:0.1
2240
networks:
2341
ingress_routing:
2442
external: true

spec/data/stack18.drs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Options traefik_tls: true, tls_domain: 'my.com', ingress: true
22

3-
Service :front, image: 'reports:0.1', ports: 7000, ingress: { host: '*' }
3+
Service :front, image: 'reports:0.1', ports: 7000, ingress: { host: '*' }
4+
5+
Service :front2, image: 'reports:0.1', ports: 7000, ingress: { path: '/test' }

spec/data/stack19.drs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# "traefik.http.middlewares.auth-0.forwardauth.address=http://oauth_provider:7000/auth"
3+
# "traefik.http.routers.%{service-name}-0.middlewares=auth-0"
4+
5+
Service :odata1, ingress: { path: '/odata', oauth_provider: 'stack_name_oauth_provider:7000/auth' }
6+
Service :odata2, ingress: { path: '/odata', oauth_provider: 'stack_name_oauth_provider_override' }
7+
Service :odata3, ingress: { path: '/odata' }
8+
9+
BeforeService [:odata2, :odata3] do
10+
oauth_provider 'stack_name_oauth_provider_global'
11+
end
12+
13+
Service :odata4, ingress: { path: '/odata' }, oauth_provider: 'stack_name_oauth_provider:7000/auth'

spec/simple_stack_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
compose = YAML.load_file stack_file.gsub('.drs', sufix), aliases: true rescue ''
2828
# puts stack_compose_shell
2929

30-
# unless stack_compose_shell == compose.to_yaml
31-
# yaml = YAML.load stack_compose_shell, aliases: true
32-
# File.write stack_file.gsub('.drs', sufix), yaml.to_yaml
33-
# compose = YAML.load_file stack_file.gsub('.drs', sufix), aliases: true
34-
# end
30+
unless stack_compose_shell == compose.to_yaml
31+
yaml = YAML.load stack_compose_shell, aliases: true
32+
File.write stack_file.gsub('.drs', sufix), yaml.to_yaml
33+
compose = YAML.load_file stack_file.gsub('.drs', sufix), aliases: true
34+
end
3535
expect(stack_compose_shell).to eq(compose.to_yaml)
3636
end
3737
end

0 commit comments

Comments
 (0)