From b4d37f985268e57160011c91b9f0cf7609ca82c5 Mon Sep 17 00:00:00 2001 From: Maurice Faber Date: Thu, 3 Oct 2024 23:08:26 +0200 Subject: [PATCH] feat: allow dict for depends_on, conf files --- conf/README.md | 15 +++++++++++++++ lib/models.py | 2 +- tpl/docker-compose.yml.j2 | 30 ++++++++++++++++++------------ 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 conf/README.md diff --git a/conf/README.md b/conf/README.md new file mode 100644 index 0000000..ff23505 --- /dev/null +++ b/conf/README.md @@ -0,0 +1,15 @@ +# extra conf folder + +Put in any extra configuration for apps. Example: + +``` +zep/ + config.yaml +``` + +And then reference those from `db.yaml` like this: + +```yaml +volumes: + - ../../conf/zep/zep.yaml:/app/zep.yaml +``` diff --git a/lib/models.py b/lib/models.py index 268147b..7c94fb0 100644 --- a/lib/models.py +++ b/lib/models.py @@ -114,7 +114,7 @@ class Service(BaseModel): """Additional docker compose properties to pass to the service""" command: str = None """The command to run in the service""" - depends_on: List[str] = [] + depends_on: List[str] | Dict[str, Any] = [] """A list of services to depend on""" env: Env = Env() """A dictionary of environment variables to pass to the service""" diff --git a/tpl/docker-compose.yml.j2 b/tpl/docker-compose.yml.j2 index 9445813..c9e5d31 100755 --- a/tpl/docker-compose.yml.j2 +++ b/tpl/docker-compose.yml.j2 @@ -15,11 +15,18 @@ services: {%- if s.command %} command: {{ s.command }} {%- endif %} - {%- if s.depends_on | length > 0 %} + {%- if s.depends_on %} depends_on: - {%- for dep in s.depends_on %} + {%- if s.depends_on is mapping %} + {%- for key, dep in s.depends_on.items() %} + {{ project.name }}-{{ key }}: + {{ dep }} + {%- endfor %} + {%- else %} + {%- for dep in s.depends_on %} - {{ project.name }}-{{ dep }} - {%- endfor %} + {%- endfor %} + {%- endif %} {%- endif %} {%- if s.env.model_dump() | length > 0 %} environment: @@ -47,14 +54,11 @@ services: {%- if i.router != Router.udp %} {%- set domains = ([i.tls.main] + i.tls.sans) if (i.tls and i.tls.main) else [i.domain] %} - traefik.{{ router }}.routers.{{ name }}.rule={% for d in domains %}Host{% if i.router == Router.tcp %}SNI{% endif %}(`{{ d }}`){% if not loop.last %} || {% endif %}{% endfor %}{% if i.path_prefix %} && PathPrefix(`{{ i.path_prefix }}`){% endif %} - {%- if i.tls %} - - traefik.{{ router }}.routers.{{ name }}.tls.certresolver=letsencrypt - {%- if i.tls.main %} + {%- if i.tls and i.tls.main %} - traefik.{{ router }}.routers.{{ name }}.tls.domains[0].main={{ i.tls.main }} - {%- for s in i.tls.sans %} + {%- for s in i.tls.sans %} - traefik.{{ router }}.routers.{{ name }}.tls.domains[0].sans[{{ loop.index0 }}]={{ s }} - {%- endfor %} - {%- endif %} + {%- endfor %} {%- endif %} {%- endif %} - traefik.{{ router }}.routers.{{ name }}.service={{ name }} @@ -69,12 +73,14 @@ services: - {{ l }} {%- endfor %} {%- endif %} + {%- if has_ingress or p.services | length > 1 %} networks: - {%- if p.services | length > 1 %} + {%- if p.services | length > 1 %} - default - {%- endif %} - {%- if has_ingress %} + {%- endif %} + {%- if has_ingress %} - proxynet + {%- endif %} {%- endif %} restart: {{ s.restart }} {%- if s.volumes %}