From cf59c5f807cbcf32d2fa5204d439260521b7f28d Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sat, 28 Oct 2023 17:01:51 -0400 Subject: [PATCH 1/5] Add healthcheck and dependency conditions --- templates/docker-compose.yml.j2 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index 4741b95..3842474 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -1,4 +1,7 @@ {{ ansible_managed | comment }} +############################## +# If you're seeing this, you're using a symlinked version of this role. +############################## --- version: "{{ compose_schema_version | default('2') }}" services: @@ -74,7 +77,12 @@ services: {% if container.depends_on is defined %} depends_on: {% for dependent in container.depends_on %} +{% if dependent.condition is defined %} + {{ dependent }}: + condition: {{ dependent.condition }} +{% else %} - {{ dependent }} +{% endif %} {% endfor %} {% endif %} {% if container.hostname is defined %} @@ -154,8 +162,15 @@ services: - {{ envfile }} {% endfor %} {% endif %} -{% if container.user is defined %} - user: {{ container.user }} +{% if container.healthcheck is defined %} + healthcheck: + test: {{ container.healthcheck.test }} + interval: {{ container.healthcheck.interval }} + timeout: {{ container.healthcheck.timeout }} +{% if container.healthcheck.retries is defined %} + retries: {{ container.healthcheck.retries }} +{% endif %} + start_period: {{ container.healthcheck.start_period }} {% endif %} {% if container.restart is defined %} restart: {{ container.restart }} From b8bccf6413acbd22a44b2f36fa8a53b4e920dac6 Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sat, 28 Oct 2023 20:36:43 -0400 Subject: [PATCH 2/5] use jinja `mapping` test --- templates/docker-compose.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index 3842474..b149c7f 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -77,7 +77,7 @@ services: {% if container.depends_on is defined %} depends_on: {% for dependent in container.depends_on %} -{% if dependent.condition is defined %} +{% if dependent is mapping %} {{ dependent }}: condition: {{ dependent.condition }} {% else %} From 0b12d4324026f0cfd4f269dc0db6c61fb4f4f1a4 Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sat, 28 Oct 2023 20:38:48 -0400 Subject: [PATCH 3/5] Add example usage to README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 667d007..74fdbd5 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ containers: mem_limit: 512m volumes: - "{{ appdata_path }}/unifi:{{ container_config_path }}" + depends_on: + - service: mongodb + condition: service_started include_global_env_vars: true restart: "{{ unless_stopped }}" - service_name: quassel @@ -75,4 +78,4 @@ containers: mem_limit: 128m ports: - "4242:4242" -``` \ No newline at end of file +``` From b8e5485956506c6b5aeb3faef98e6b88c4f7d82a Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sat, 28 Oct 2023 20:45:24 -0400 Subject: [PATCH 4/5] Fix stupid typo --- templates/docker-compose.yml.j2 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index b149c7f..b134ada 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -1,7 +1,4 @@ {{ ansible_managed | comment }} -############################## -# If you're seeing this, you're using a symlinked version of this role. -############################## --- version: "{{ compose_schema_version | default('2') }}" services: @@ -78,7 +75,7 @@ services: depends_on: {% for dependent in container.depends_on %} {% if dependent is mapping %} - {{ dependent }}: + {{ dependent.service}}: condition: {{ dependent.condition }} {% else %} - {{ dependent }} From 4642c4a72b18708d93e414b25c69defaed8bc9bf Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sat, 28 Oct 2023 21:02:50 -0400 Subject: [PATCH 5/5] escape test with quotes, make interval and timeout optional --- templates/docker-compose.yml.j2 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index b134ada..47ff813 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -161,9 +161,13 @@ services: {% endif %} {% if container.healthcheck is defined %} healthcheck: - test: {{ container.healthcheck.test }} + test: "{{ container.healthcheck.test }}" +{% if container.healthcheck.interval is defined %} interval: {{ container.healthcheck.interval }} +{% endif %} +{% if container.healthcheck.timeout is defined %} timeout: {{ container.healthcheck.timeout }} +{% endif %} {% if container.healthcheck.retries is defined %} retries: {{ container.healthcheck.retries }} {% endif %}