Skip to content

Commit

Permalink
refactor: simplified network selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Morriz committed Dec 9, 2024
1 parent ff4e696 commit de389d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def get_projects(
project.services = []
for service_dict in project_dict["services"]:
service = Service(**service_dict)
service.ingress = [Ingress(**ingress) for ingress in service_dict["ingress"]]
service.ingress = [
Ingress(**ingress) for ingress in (service_dict["ingress"] if "ingress" in service_dict else [])
]
project.services.append(service)
filtered_projects.append(project)
continue
Expand All @@ -104,12 +106,14 @@ def get_projects(
service = Service(**service_dict)

if filter.__code__.co_argcount == 2 and cast(Callable[[Project, Service], bool], filter)(project, service):
service.ingress = [Ingress(**ingress) for ingress in service_dict["ingress"]]
service.ingress = [
Ingress(**ingress) for ingress in (service_dict["ingress"] if "ingress" in service_dict else [])
]
filtered_services.append(service)
continue

filtered_ingress = []
for ingress_dict in service_dict["ingress"] or []:
for ingress_dict in service_dict["ingress"] if "ingress" in service_dict else []:
ingress = Ingress(**ingress_dict)

if filter.__code__.co_argcount == 3 and cast(Callable[[Project, Service, Ingress], bool], filter)(
Expand Down
3 changes: 1 addition & 2 deletions tpl/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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')) or list(s.ingress | selectattr('expose')) | length > 0 %}
{{ project.name }}-{{ s.host }}:
{%- if s.command %}
command: {{ s.command }}
Expand Down Expand Up @@ -95,7 +94,7 @@ services:
- {{ l }}
{%- endfor %}
{%- endif %}
{%- if has_ingress or p.services | length > 1 %}
{%- if s.ingress | length > 0 or p.services | length > 1 %}
networks:
{%- if p.services | length > 1 %}
- default
Expand Down

0 comments on commit de389d0

Please # to comment.