Ensure that keycloak is up

This commit is contained in:
Kevin Veen-Birkenbach 2025-08-08 17:25:31 +02:00
parent c7b25ed093
commit aae69ea15b
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
27 changed files with 74 additions and 47 deletions

View File

@ -50,16 +50,17 @@ certbot_dns_propagation_wait_seconds: 300 # How long sho
certbot_flavor: san # Possible options: san (recommended, with a dns flavor like cloudflare, or hetzner), wildcard(doesn't function with www redirect), dedicated certbot_flavor: san # Possible options: san (recommended, with a dns flavor like cloudflare, or hetzner), wildcard(doesn't function with www redirect), dedicated
# Path where Certbot stores challenge webroot files # Path where Certbot stores challenge webroot files
letsencrypt_webroot_path: "/var/lib/letsencrypt/" letsencrypt_webroot_path: "/var/lib/letsencrypt/"
# Base directory containing Certbot configuration, account data, and archives # Base directory containing Certbot configuration, account data, and archives
letsencrypt_base_path: "/etc/letsencrypt/" letsencrypt_base_path: "/etc/letsencrypt/"
# Symlink directory for the current active certificate and private key # Symlink directory for the current active certificate and private key
letsencrypt_live_path: "{{ letsencrypt_base_path }}live/" letsencrypt_live_path: "{{ letsencrypt_base_path }}live/"
## Docker Role Specific Parameters ## Docker Role Specific Parameters
docker_restart_policy: "unless-stopped" DOCKER_RESTART_POLICY: "unless-stopped"
DOCKER_VARS_FILE: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"
# default value if not set via CLI (-e) or in playbook vars # default value if not set via CLI (-e) or in playbook vars
allowed_applications: [] allowed_applications: []

View File

@ -7,7 +7,7 @@
- name: "For '{{ application_id }}': Load database variables" - name: "For '{{ application_id }}': Load database variables"
include_vars: "{{ item }}" include_vars: "{{ item }}"
loop: loop:
- "{{ cmp_db_docker_vars_file_docker }}" # Important to load docker variables first so that database can use them - "{{ DOCKER_VARS_FILE }}" # Important to load docker variables first so that database can use them
- "{{ cmp_db_docker_vars_file_db }}" # Important to load them before docker role so that backup can use them - "{{ cmp_db_docker_vars_file_db }}" # Important to load them before docker role so that backup can use them
- name: "For '{{ application_id }}': Load cmp-docker-oauth2" - name: "For '{{ application_id }}': Load cmp-docker-oauth2"

View File

@ -1,2 +1 @@
cmp_db_docker_vars_file_db: "{{ playbook_dir }}/roles/cmp-rdbms/vars/database.yml" cmp_db_docker_vars_file_db: "{{ playbook_dir }}/roles/cmp-rdbms/vars/database.yml"
cmp_db_docker_vars_file_docker: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"

View File

@ -6,7 +6,7 @@
logging: logging:
driver: journald driver: journald
image: mariadb image: mariadb
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
env_file: env_file:
- {{database_env}} - {{database_env}}
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW"

View File

@ -6,7 +6,7 @@
container_name: {{ application_id | get_entity_name }}-database container_name: {{ application_id | get_entity_name }}-database
env_file: env_file:
- {{database_env}} - {{database_env}}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{database_name}}"] test: ["CMD-SHELL", "pg_isready -U {{database_name}}"]
interval: 10s interval: 10s

View File

@ -0,0 +1,5 @@
- name: "Load handlers without when condition. to guaranty that they are executed"
import_role:
name: docker-compose
tasks_from: helpers/none
handlers_from: main

View File

@ -0,0 +1 @@
# Dummy file for handler import

View File

@ -16,7 +16,7 @@
mode: '0755' mode: '0755'
with_dict: "{{ docker_compose.directories }}" with_dict: "{{ docker_compose.directories }}"
- name: "Include routines to set up a git repository based installaion for '{{application_id}}'." - name: "Include routines to set up a git repository based installation for '{{application_id}}'."
include_tasks: "02_repository.yml" include_tasks: "02_repository.yml"
when: docker_pull_git_repository | bool when: docker_pull_git_repository | bool

View File

@ -1,6 +1,6 @@
{# Base for docker services #} {# Base for docker services #}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
{% if application_id | has_env %} {% if application_id | has_env %}
env_file: env_file:
- "{{docker_compose.files.env}}" - "{{docker_compose.files.env}}"

View File

@ -21,7 +21,7 @@
published_ports: published_ports:
- "127.0.0.1:{{ mariadb_port }}:3306" # can be that this will be removed if all applications use sockets - "127.0.0.1:{{ mariadb_port }}:3306" # can be that this will be removed if all applications use sockets
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" #for nextcloud command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" #for nextcloud
restart_policy: "{{ docker_restart_policy }}" restart_policy: "{{ DOCKER_RESTART_POLICY }}"
healthcheck: healthcheck:
test: "/usr/bin/mariadb --user=root --password={{ mariadb_root_pwd }} --execute \"SHOW DATABASES;\"" test: "/usr/bin/mariadb --user=root --password={{ mariadb_root_pwd }} --execute \"SHOW DATABASES;\""
interval: 10s interval: 10s

View File

@ -25,6 +25,9 @@
- include_tasks: utils/run_once.yml - include_tasks: utils/run_once.yml
when: run_once_svc_db_postgres is not defined when: run_once_svc_db_postgres is not defined
- name: "Ensure that {{ docker_compose.directories.instance }} is up"
include_tasks: "{{ playbook_dir }}/roles/docker-compose/tasks/helpers/ensure.yml"
- name: "Initialize database for '{{ database_name }}'" - name: "Initialize database for '{{ database_name }}'"
include_tasks: init.yml include_tasks: init.yml
when: "{{ postgres_init }}" when: "{{ postgres_init }}"

View File

@ -25,7 +25,7 @@ Include this snippet in your top-level `docker-compose.yml.j2` where you want Re
Sets container name (`{{ application_id }}-redis`). Sets container name (`{{ application_id }}-redis`).
- **Restart policy** - **Restart policy**
Controlled by `docker_restart_policy`. Controlled by `DOCKER_RESTART_POLICY`.
- **Journald logging** - **Journald logging**
Ensures logs are captured by systemds journal. Ensures logs are captured by systemds journal.

View File

@ -4,7 +4,7 @@
redis: redis:
image: "{{ redis_image }}:{{ redis_version }}" image: "{{ redis_image }}:{{ redis_version }}"
container_name: {{ application_id | get_entity_name }}-redis container_name: {{ application_id | get_entity_name }}-redis
restart: {{ docker_restart_policy }} restart: {{ DOCKER_RESTART_POLICY }}
logging: logging:
driver: journald driver: journald
volumes: volumes:

View File

@ -13,7 +13,7 @@
daemon: daemon:
image: "{{ espocrm_image }}:{{ espocrm_version }}" image: "{{ espocrm_image }}:{{ espocrm_version }}"
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
logging: logging:
driver: journald driver: journald
entrypoint: docker-daemon.sh entrypoint: docker-daemon.sh
@ -23,7 +23,7 @@
websocket: websocket:
image: "{{ espocrm_image }}:{{ espocrm_version }}" image: "{{ espocrm_image }}:{{ espocrm_version }}"
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
logging: logging:
driver: journald driver: journald
environment: environment:

View File

@ -1,7 +1,7 @@
{% include 'roles/docker-compose/templates/base.yml.j2' %} {% include 'roles/docker-compose/templates/base.yml.j2' %}
application: application:
image: jenkins/jenkins:lts image: jenkins/jenkins:lts
restart: "{{docker_restart_policy}}" restart: "{{DOCKER_RESTART_POLICY}}"
ports: ports:
- "127.0.0.1:{{ports.localhost.http[application_id]}}:8080" - "127.0.0.1:{{ports.localhost.http[application_id]}}:8080"
volumes: volumes:

View File

@ -0,0 +1,19 @@
- name: "load variables from {{ DOCKER_VARS_FILE }}"
include_vars: "{{ DOCKER_VARS_FILE }}"
- name: Set the directory to which keycloack import files will be copied on host
set_fact:
keycloak_host_import_directory: "{{ docker_compose.directories.volumes }}import/"
- name: "create directory {{keycloak_host_import_directory}}"
file:
path: "{{keycloak_host_import_directory}}"
state: directory
mode: 0755
- name: "Copy import files to {{ keycloak_host_import_directory }}"
template:
src: "{{ item }}"
dest: "{{ keycloak_host_import_directory }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
mode: '770'
loop: "{{ lookup('fileglob', '{{ role_path }}/templates/import/*.j2', wantlist=True) }}"

View File

@ -1,22 +1,11 @@
--- ---
- name: "create import files for {{application_id}}"
include_tasks: 01_import.yml
- name: "load docker, db and proxy for {{application_id}}" - name: "load docker, db and proxy for {{application_id}}"
include_role: include_role:
name: cmp-db-docker-proxy name: cmp-db-docker-proxy
- name: "create directory {{keycloak_host_import_directory}}"
file:
path: "{{keycloak_host_import_directory}}"
state: directory
mode: 0755
- name: "Copy import files to {{ keycloak_host_import_directory }}"
template:
src: "{{ item }}"
dest: "{{ keycloak_host_import_directory }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
mode: '770'
loop: "{{ lookup('fileglob', '{{ role_path }}/templates/import/*.j2', wantlist=True) }}"
notify: docker compose up
# Deactivated temporary. Import now via realm.yml # Deactivated temporary. Import now via realm.yml
#- name: Implement SSH Public Key Attribut #- name: Implement SSH Public Key Attribut
# include_tasks: attributes/ssh_public_key.yml # include_tasks: attributes/ssh_public_key.yml

View File

@ -4,7 +4,6 @@ database_type: "postgres"
# Keycloak Specific # Keycloak Specific
keycloak_container: "{{ applications | get_app_conf(application_id, 'docker.services.keycloak.name', True) }}" # Name of the keycloack docker container keycloak_container: "{{ applications | get_app_conf(application_id, 'docker.services.keycloak.name', True) }}" # Name of the keycloack docker container
keycloak_host_import_directory: "{{ docker_compose.directories.volumes }}import/" # Directory in which keycloack import files are placed on the host
keycloak_docker_import_directory: "/opt/keycloak/data/import/" # Directory in which keycloack import files are placed in the running docker container keycloak_docker_import_directory: "/opt/keycloak/data/import/" # Directory in which keycloack import files are placed in the running docker container
keycloak_realm: "{{ primary_domain}}" # This is the name of the default realm which is used by the applications keycloak_realm: "{{ primary_domain}}" # This is the name of the default realm which is used by the applications
keycloak_administrator: "{{ applications | get_app_conf(application_id, 'users.administrator', True) }}" # Master Administrator keycloak_administrator: "{{ applications | get_app_conf(application_id, 'users.administrator', True) }}" # Master Administrator
@ -20,4 +19,4 @@ keycloak_import_realm: "{{ applications | get_app_conf(application_id
keycloak_debug_enabled: "{{ enable_debug }}" keycloak_debug_enabled: "{{ enable_debug }}"
# Docker # Docker
docker_compose_flush_handlers: false # Copy realm import etc. before flush docker_compose_flush_handlers: true # Remember to copy realm import before flushg when set to true

View File

@ -82,7 +82,7 @@
container_name: {{mailu_name}}_oletools container_name: {{mailu_name}}_oletools
image: {{docker_source}}/oletools:{{ mailu_version }} image: {{docker_source}}/oletools:{{ mailu_version }}
hostname: oletools hostname: oletools
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
depends_on: depends_on:
- resolver - resolver
dns: dns:

View File

@ -3,7 +3,7 @@
{% set container_port = 8008 %} {% set container_port = 8008 %}
image: "{{ matrix_synapse_image }}:{{ matrix_synapse_version }}" image: "{{ matrix_synapse_image }}:{{ matrix_synapse_version }}"
container_name: {{ matrix_synapse_name }} container_name: {{ matrix_synapse_name }}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
logging: logging:
driver: journald driver: journald
volumes: volumes:
@ -32,7 +32,7 @@
{% set container_port = 80 %} {% set container_port = 80 %}
image: "{{ matrix_element_image }}:{{ matrix_element_version }}" image: "{{ matrix_element_image }}:{{ matrix_element_version }}"
container_name: {{ matrix_element_name }} container_name: {{ matrix_element_name }}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
volumes: volumes:
- ./element-config.json:/app/config.json - ./element-config.json:/app/config.json
ports: ports:
@ -44,7 +44,7 @@
mautrix-{{item.bridge_name}}: mautrix-{{item.bridge_name}}:
container_name: matrix-{{item.bridge_name}} container_name: matrix-{{item.bridge_name}}
image: dock.mau.dev/mautrix/{{ item.bridge_name }}:latest image: dock.mau.dev/mautrix/{{ item.bridge_name }}:latest
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
volumes: volumes:
- ./mautrix/{{item.bridge_name}}:/data - ./mautrix/{{item.bridge_name}}:/data
healthcheck: healthcheck:
@ -56,7 +56,7 @@
{% endfor %} {% endfor %}
{% if applications | get_app_conf(application_id, 'plugins.chatgpt', True) | bool %} {% if applications | get_app_conf(application_id, 'plugins.chatgpt', True) | bool %}
matrix-chatgpt-bot: matrix-chatgpt-bot:
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
container_name: matrix-chatgpt container_name: matrix-chatgpt
image: ghcr.io/matrixgpt/matrix-chatgpt-bot:latest image: ghcr.io/matrixgpt/matrix-chatgpt-bot:latest
volumes: volumes:

View File

@ -6,7 +6,7 @@
tag: "mybb_application" tag: "mybb_application"
image: {{ mybb_image }}:{{ mybb_version }} image: {{ mybb_image }}:{{ mybb_version }}
container_name: {{ mybb_name }} container_name: {{ mybb_name }}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
volumes: volumes:
- data:/var/www/html - data:/var/www/html
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %} {% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
@ -18,7 +18,7 @@
options: options:
tag: "mybb_server" tag: "mybb_server"
image: nginx:mainline image: nginx:mainline
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
ports: ports:
- "127.0.0.1:{{ports.localhost.http[application_id]}}:80" - "127.0.0.1:{{ports.localhost.http[application_id]}}:80"
volumes: volumes:

View File

@ -37,7 +37,7 @@
container_name: "{{ nextcloud_proxy_name }}" container_name: "{{ nextcloud_proxy_name }}"
logging: logging:
driver: journald driver: journald
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
ports: ports:
- "127.0.0.1:{{ports.localhost.http[application_id]}}:{{ container_port }}" - "127.0.0.1:{{ports.localhost.http[application_id]}}:{{ container_port }}"
volumes: volumes:
@ -53,7 +53,7 @@
cron: cron:
container_name: "{{ nextcloud_cron_name }}" container_name: "{{ nextcloud_cron_name }}"
image: "{{ nextcloud_image }}:{{ nextcloud_version }}" image: "{{ nextcloud_image }}:{{ nextcloud_version }}"
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
logging: logging:
driver: journald driver: journald
volumes: volumes:

View File

@ -1,7 +1,7 @@
{% if applications | get_app_conf(application_id, 'features.oauth2', False) %} {% if applications | get_app_conf(application_id, 'features.oauth2', False) %}
oauth2-proxy: oauth2-proxy:
image: quay.io/oauth2-proxy/oauth2-proxy:{{applications['web-app-oauth2-proxy'].version}} image: quay.io/oauth2-proxy/oauth2-proxy:{{applications['web-app-oauth2-proxy'].version}}
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
command: --config /oauth2-proxy.cfg command: --config /oauth2-proxy.cfg
hostname: oauth2-proxy hostname: oauth2-proxy
ports: ports:

View File

@ -5,6 +5,6 @@
context: . context: .
ports: ports:
- 127.0.0.1:{{ports.localhost.http[application_id]}}:8080 - 127.0.0.1:{{ports.localhost.http[application_id]}}:8080
restart: {{docker_restart_policy}} restart: {{DOCKER_RESTART_POLICY}}
{% include 'roles/docker-compose/templates/networks.yml.j2' %} {% include 'roles/docker-compose/templates/networks.yml.j2' %}

View File

@ -18,3 +18,6 @@
set_fact: set_fact:
run_once_web_svc_cdn: true run_once_web_svc_cdn: true
when: run_once_web_svc_cdn is not defined when: run_once_web_svc_cdn is not defined
- name: "Ensure that {{ docker_compose.directories.instance }} is up"
include_tasks: "{{ playbook_dir }}/roles/docker-compose/tasks/helpers/ensure.yml"

View File

@ -1,6 +1,14 @@
--- ---
# This is necessary to flush the handlers before the when is set, because otherwise the when will be attached to the handlers # This is necessary to flush the handlers before the when is set, because otherwise the when will be attached to the handlers
- name: "Ensure that {{ docker_compose.directories.instance }} is up"
# This is a little hack to guaranty that the docker containers are allways up
# It isn't the cleanest solution to have it here but it should fullfill their purpose
include_tasks: "{{ playbook_dir }}/roles/docker-compose/tasks/04_ensure_up.yml"
when:
- docker_compose is defined
- (application_id | get_entity_name) == (docker_compose.directories.instance | basename)
- meta: flush_handlers - meta: flush_handlers
- name: Set “run-once” fact for role {{ role_name }} - name: Set “run-once” fact for role {{ role_name }}