mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Refactored docker-compose roles
This commit is contained in:
9
roles/docker-container/templates/base.yml.j2
Normal file
9
roles/docker-container/templates/base.yml.j2
Normal file
@@ -0,0 +1,9 @@
|
||||
{# Base for docker services #}
|
||||
|
||||
restart: {{docker_restart_policy}}
|
||||
env_file:
|
||||
- "{{docker_compose.files.env}}"
|
||||
logging:
|
||||
driver: journald
|
||||
|
||||
{{ "\n" }}
|
17
roles/docker-container/templates/depends_on_dmbs.j2
Normal file
17
roles/docker-container/templates/depends_on_dmbs.j2
Normal file
@@ -0,0 +1,17 @@
|
||||
{# This template needs to be included in docker-compose.yml containers, which depend on a database, redis and optional additional volumes #}
|
||||
{% if applications | is_feature_enabled('central_database', application_id)
|
||||
and not (applications[application_id].docker.redis.enabled
|
||||
| default(false)
|
||||
| bool) %}
|
||||
depends_on: []
|
||||
{% else %}
|
||||
depends_on:
|
||||
{% if not applications | is_feature_enabled('central_database', application_id) %}
|
||||
database:
|
||||
condition: service_healthy
|
||||
{% endif %}
|
||||
{% if applications[application_id].docker.redis.enabled | default(false) | bool %}
|
||||
redis:
|
||||
condition: service_healthy
|
||||
{% endif %}
|
||||
{% endif %}
|
9
roles/docker-container/templates/healthcheck/curl.yml.j2
Normal file
9
roles/docker-container/templates/healthcheck/curl.yml.j2
Normal file
@@ -0,0 +1,9 @@
|
||||
healthcheck:
|
||||
test:
|
||||
- "CMD"
|
||||
- "curl"
|
||||
- "-f"
|
||||
- "http://127.0.0.1{{ (":" ~ container_port) if container_port is defined else '' }}/{{ container_healthcheck | default('') }}"
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 3
|
@@ -0,0 +1,24 @@
|
||||
|
||||
{#
|
||||
This health check ensures the test email is sent only once to prevent
|
||||
hitting SMTP rate limits due to multiple health check executions.
|
||||
The logic checks for a temporary file (/tmp/email_sent) to determine
|
||||
if the email has already been sent. If the file exists, the email
|
||||
is skipped, but the health check continues by verifying the HTTP service.
|
||||
Refer to the conversation with ChatGPT (https://chatgpt.com/share/67898c3f-2c1c-800f-861c-47dcbe109135)
|
||||
on January 16, 2025, for the background behind this complexity.
|
||||
|
||||
Additional it is also checked if the host is reachable
|
||||
#}
|
||||
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD-SHELL
|
||||
- >
|
||||
if [ ! -f /tmp/email_sent ]; then
|
||||
echo 'Subject: testmessage from {{domains | get_domain(application_id)}}\n\nSUCCESSFULL' | msmtp -t {{users.blackhole.email}} && touch /tmp/email_sent;
|
||||
fi &&
|
||||
curl -f http://localhost:80/ || exit 1
|
||||
interval: 1m
|
||||
timeout: 20s
|
||||
retries: 3
|
6
roles/docker-container/templates/healthcheck/tcp.yml.j2
Normal file
6
roles/docker-container/templates/healthcheck/tcp.yml.j2
Normal file
@@ -0,0 +1,6 @@
|
||||
healthcheck:
|
||||
test:
|
||||
- "CMD"
|
||||
- "bash"
|
||||
- "-c"
|
||||
- "exec 3<>/dev/tcp/localhost/{{ container_port }} && echo -e 'GET /{{ container_healthcheck | default('') }} HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && cat <&3 | grep -q 'HTTP/1.1'"
|
10
roles/docker-container/templates/healthcheck/wget.yml.j2
Normal file
10
roles/docker-container/templates/healthcheck/wget.yml.j2
Normal file
@@ -0,0 +1,10 @@
|
||||
healthcheck:
|
||||
test:
|
||||
- "CMD"
|
||||
- "wget"
|
||||
- "--spider"
|
||||
- "--proxy=off"
|
||||
- "http://127.0.0.1{{ (":" ~ container_port) if container_port is defined else '' }}/{{ container_healthcheck | default('') }}"
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 3
|
Reference in New Issue
Block a user