Skip to content

Commit

Permalink
feat: expose ingress to internal services
Browse files Browse the repository at this point in the history
  • Loading branch information
Morriz committed Nov 9, 2024
1 parent b65e00a commit 19f5a02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Ingress(BaseModel):
"""The type of router to use for the service"""
tls: TLS = None
"""TLS settings that will be used instead of 'domain'"""
expose: bool = False
"""Expose the service to any other internal service"""

@model_validator(mode="after")
@classmethod
Expand Down
23 changes: 22 additions & 1 deletion tpl/docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{%- macro treedot(dict,string) %}
{%- for key, value in dict.items() -%}
{%- if value is mapping -%}
{%- if string -%}
{%- set str = string ~ '.' ~ key -%}
{%- else -%}
{%- set str = key -%}
{%- endif -%}
{{ treedot(value,str) }}
{%- else -%}
{%- if string %}
{{ string ~ '.' ~ key }} = {{ value }}
{%- else %}
{{ key }} = {{ value }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
---
networks:
proxynet:
Expand All @@ -10,7 +28,7 @@ services:
{#- The service needs discovery labels when one of its ingress entries has a domain or tls and is not using hostport #}
{#- (hostport services are handled by static routers because of their need to restart anyway for new entrypoints) #}
{%- set needs_discovery = (list(s.ingress | selectattr('domain')) + list(s.ingress | selectattr('tls'))) | length > list(s.ingress | selectattr('domain') | selectattr('hostport')) | length %}
{%- set has_ingress = list(s.ingress | selectattr('domain')) | length > 0 or list(s.ingress | selectattr('tls')) | length > 0 or list(s.ingress | selectattr('hostport')) | length > 0 %}
{%- set has_ingress = list(s.ingress | selectattr('domain')) | length > 0 or list(s.ingress | selectattr('tls')) | length > 0 or list(s.ingress | selectattr('hostport')) or list(s.ingress | selectattr('expose')) | length > 0 %}
{{ project.name }}-{{ s.host }}:
{%- if s.command %}
command: {{ s.command }}
Expand Down Expand Up @@ -66,6 +84,9 @@ services:
{%- if i.path_prefix and i.path_remove %}
- traefik.{{ router }}.middlewares.removeServiceSelector.stripPrefix.prefixes={{ i.path_prefix }}
{%- endif %}
{%- if i.middlewares %}
- traefik.{{ router }}.routers.{{ name }}.middlewares={{ i.middlewares | join(',') }}
{%- endif %}
- traefik.{{ router }}.services.{{ name }}.loadbalancer.server.port={{ i.port }}
{%- endif %}
{%- endfor %}
Expand Down

0 comments on commit 19f5a02

Please sign in to comment.