Skip to content

Commit

Permalink
fix: artifacts gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Morriz committed Mar 26, 2024
1 parent c9c09a4 commit 7e70e99
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
14 changes: 6 additions & 8 deletions lib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,17 @@ def get_projects(
for project in projects_raw:
services = []
p = Project(**project)
if not filter:
if not filter or filter.__code__.co_argcount == 1 and cast(Callable[[Project], bool], filter)(p):
ret.append(p)
continue
for s in p.services.copy():
if filter.__code__.co_argcount == 2 and cast(Callable[[Project, Service], bool], filter)(p, s):
services.append(s)
continue
ingress = []
for i in s.ingress.copy():
if (
(
filter.__code__.co_argcount == 3
and cast(Callable[[Project, Service, Ingress], bool], filter)(p, s, i)
)
or (filter.__code__.co_argcount == 2 and cast(Callable[[Project, Service], bool], filter)(p, s))
or (filter.__code__.co_argcount == 1 and cast(Callable[[Project], bool], filter)(p))
if filter.__code__.co_argcount == 3 and cast(Callable[[Project, Service, Ingress], bool], filter)(
p, s, i
):
ingress.append(i)
if len(ingress) > 0:
Expand Down
4 changes: 2 additions & 2 deletions lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class ProxyProtocol(str, Enum):
class Ingress(BaseModel):
"""Ingress model"""

domain: str
"""The domain to use for the service"""
domain: str = None
"""The domain to use for the service. If omitted, the service will not be publicly accessible."""
hostport: int = None
"""The port to expose on the host"""
passthrough: bool = False
Expand Down
7 changes: 3 additions & 4 deletions lib/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def write_upstream(project: Project) -> None:
tpl = Template(t)
tpl.globals["Protocol"] = Protocol
tpl.globals["isinstance"] = isinstance
tpl.globals["len"] = len
tpl.globals["list"] = list
tpl.globals["str"] = str
if os.environ.get("PYTHON_ENV") != "production":
content = tpl.render(project=project, domain=os.environ.get("TRAEFIK_DOMAIN"), env="development")
else:
content = tpl.render(project=project, domain=project.domain)
content = tpl.render(project=project)
with open(f"upstream/{project.name}/docker-compose.yml", "w", encoding="utf-8") as f:
f.write(content)

Expand Down
23 changes: 14 additions & 9 deletions tpl/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ networks:

services:
{%- for s in project.services %}
{%- set has_ingress = list(s.ingress | selectattr('domain')) | length > 0 %}
{{ project.name }}-{{ s.name }}:
{%- if s.command %}
command: {{ s.command }}
Expand All @@ -24,29 +25,33 @@ services:
- '{{ i.port }}/{{ Protocol[i.protocol].value }}'
{%- endfor %}
image: {{ s.image }}
{%- if s.ingress | length > 1 %}
{%- if has_ingress or (s.labels | length > 0) %}
labels:
{%- if has_ingress %}
- traefik.enable=true
- traefik.docker.network=proxynet
{%- for i in s.ingress %}
{%- set name = project.name ~ '-' ~ s.name.replace('.', '-') ~ '-' ~ i.port %}
{%- for i in s.ingress %}
{%- if i.domain %}
{%- set name = project.name ~ '-' ~ s.name.replace('.', '-') ~ '-' ~ i.port %}
- traefik.http.routers.{{ name }}.entrypoints=web-secure
- traefik.http.routers.{{ name }}.rule=Host(`{{ i.domain }}`){%- if i.path_prefix %} && PathPrefix(`{{ i.path_prefix }}`){%- endif %}
- traefik.http.routers.{{ name }}.tls.certresolver=letsencrypt
{%- if i.path_prefix and i.path_remove %}
{%- if i.path_prefix and i.path_remove %}
- traefik.http.middlewares.removeServiceSelector.stripPrefix.prefixes={{ i.path_prefix }}
{%- endif %}
{%- endif %}
- traefik.http.services.{{ name }}.loadbalancer.server.port={{ i.port }}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- for l in s.labels %}
- {{ l }}
{%- endfor %}
{%- endif %}0
{%- endif %}
networks:
{%- if p.services | length > 1 %}
- default
{%- endif %}
{%- if s.ingress | length > 1 %}
{%- endif %}
{%- if has_ingress %}
- proxynet
{%- endif %}
restart: {{ s.restart }}
Expand Down

0 comments on commit 7e70e99

Please sign in to comment.