feat(docker-compose): Add example for health check between two services

This commit is contained in:
2023-06-11 22:49:45 +02:00
parent 3de179d613
commit b033946444
5 changed files with 37 additions and 0 deletions

View File

@@ -1,6 +1,15 @@
services:
{%- if ',' in cookiecutter.__component_list_slug -%}
{%- set components = cookiecutter.__component_list_slug.split(',') -%}
{%- set ns = namespace(found=false) -%}
{%- for component in components %}
{%- if loop.first -%}
{%- set ns.first_component = component -%}
{%- elif N is undefined -%}
{%- set ns.second_component = component -%}
{%- set N = 0 -%}
{%- endif -%}
{%- endfor -%}
{%- for component in components %}
{{ component }}:
image: "{{ component }}:${% raw %}{{% endraw %}{{ component.upper() }}_VERSION{% raw %}}{% endraw %}"
@@ -8,6 +17,18 @@ services:
networks:
{{ cookiecutter.__service_slug }}-default:
profiles: ["full", "{{ component }}"]
{% if loop.first -%}
depends_on:
{{ ns.second_component }}:
condition: service_healthy
{%- else -%}
healthcheck:
test: ["CMD", "fping", "--count=1", "${% raw %}{{% endraw %}{{ ns.first_component.upper() }}_VIP{% raw %}}{% endraw %}", "--period=500", "--quiet"]
interval: 3s
timeout: 1s
retries: 60
start_period: 2s
{%- endif %}
extends:
file: common-settings.yml
service: common-settings

View File

@@ -8,6 +8,11 @@ CONTEXT={{ cookiecutter.__context_slug }}
{% for component in components %}
# {{ component.upper() }}_VERSION=x.y.z
{%- endfor %}
{%- for component in components %}
{%- if loop.first %}
# {{ component.upper() }}_VIP=10.1.1.2
{%- endif %}
{%- endfor %}