From 0152088f7d7c4c9d3fb97dab7b96ebc856900382 Mon Sep 17 00:00:00 2001 From: Tuan-Dat Tran Date: Sat, 26 Apr 2025 00:00:51 +0200 Subject: [PATCH] feat(docker): Added healthcheck Signed-off-by: Tuan-Dat Tran --- roles/docker_host/templates/compose.yaml.j2 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/roles/docker_host/templates/compose.yaml.j2 b/roles/docker_host/templates/compose.yaml.j2 index 9648015..8e255e3 100644 --- a/roles/docker_host/templates/compose.yaml.j2 +++ b/roles/docker_host/templates/compose.yaml.j2 @@ -21,6 +21,27 @@ services: {% endfor %} {% endif %} {% endif %} +{% if service.ports is defined and service.ports is iterable %} +{% set first_http_port = service.ports | default([]) | selectattr('name', 'defined') | selectattr('name', 'search', 'http') | first %} +{% set chosen_http_port_value = none %} +{% if first_http_port is not none %} +{% if first_http_port.internal is defined and first_http_port.internal == 'proxy_only' %} +{% if first_http_port.external is defined %} +{% set chosen_http_port_value = first_http_port.external %} +{% endif %} +{% else %} +{% set chosen_http_port_value = first_http_port.internal %} +{% endif %} +{% if chosen_http_port_value is defined %} + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:{{ chosen_http_port_value }}"] + interval: 30s + timeout: 10s + retries: 5 + start_period: 20s +{% endif %} +{% endif %} +{% endif %} {% if service.cap_add is defined and service.cap_add is iterable %} cap_add: {% for cap in service.cap_add %}