Refactor: migrate cmp/* and srv/* roles into sys-stk/* and sys-svc/* namespaces

- Removed obsolete 'cmp' category, introduced 'stk' category (fa-bars-staggered icon).
- Renamed roles:
  * cmp-db-docker → sys-stk-back-stateful
  * cmp-docker-oauth2 → sys-stk-back-stateless
  * srv-domain-provision → sys-stk-front
  * cmp-db-docker-proxy → sys-stk-full-stateful
  * cmp-docker-proxy → sys-stk-full-stateless
  * cmp-rdbms → sys-svc-rdbms
- Updated all include_role references, vars, templates and README.md files.
- Adjusted run_once comments and variable paths accordingly.
- Updated all web-app roles to use new sys-stk/* and sys-svc/* roles.

Conversation: https://chatgpt.com/share/68b0ba66-09f8-800f-86fc-76c47009d431
This commit is contained in:
2025-08-28 22:23:09 +02:00
parent 92f5bf6481
commit 6ea8301364
94 changed files with 112 additions and 114 deletions

View File

@@ -0,0 +1,30 @@
# Central Database
## Description
This Ansible role provisions a centralized database system in your Docker Compose environment. It supports both MariaDB and PostgreSQL, providing a robust, scalable, and low-maintenance database solution. Whether you're consolidating your application's data or creating a dedicated central storage, this role simplifies setup and integration.
## Overview
Tailored for environments that require a central data repository, this role:
- Loads necessary database variables defined in [vars/database.yml](./vars/database.yml).
- Generates an environment file based on the chosen database engine.
- Integrates seamlessly with Docker Compose to deploy a centralized database container (if enabled).
## Purpose
The role's purpose is to automate the provisioning and configuration of a centralized database service. This not only reduces manual setup but also ensures consistent, reliable deployment across production and homelab environments.
## Features
- **Supports Multiple Engines:** Easily switch between MariaDB and PostgreSQL.
- **Centralized Data Management:** Improves data consistency and security.
- **Docker Compose Integration:** Automates container setup and configuration.
- **Simplified Variable Management:** Preconfigured templates minimize manual intervention.
## Credits 📝
Developed and maintained by **Kevin Veen-Birkenbach**.
Learn more at [www.veen.world](https://www.veen.world)
Part of the [Infinito.Nexus Project](https://s.infinito.nexus/code)
License: [Infinito.Nexus NonCommercial License](https://s.infinito.nexus/license)

View File

@@ -0,0 +1,23 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: >-
The Docker Central Database Role lets you quickly provision a centralized database through Docker Compose.
Whether using MariaDB or PostgreSQL, this role provides a reliable, low-maintenance solution that supports your business applications.
license: "Infinito.Nexus NonCommercial License"
license_url: "https://s.infinito.nexus/license"
company: "Kevin Veen-Birkenbach Consulting & Coaching Solutions"
min_ansible_version: "2.9"
platforms:
- name: Docker
versions:
- "latest"
galaxy_tags:
- database
- docker
- mariadb
- postgresql
- central-database
repository: "https://s.infinito.nexus/code"
issue_tracker_url: "https://s.infinito.nexus/issues"
documentation: "https://docs.infinito.nexus"

View File

@@ -0,0 +1,26 @@
# run_once_sys_svc_rdbms: deactivated
# The following env file will just be used from the dedicated mariadb container
# and not the central one
- block:
- name: "Ensure env dir exists: {{ docker_compose.directories.env }}"
ansible.builtin.file:
path: "{{ docker_compose.directories.env }}"
state: directory
mode: "0755"
- name: "For '{{ application_id }}': Create {{database_env}}"
template:
src: "env/{{database_type}}.env.j2"
dest: "{{database_env}}"
notify: docker compose up
when: not applications | get_app_conf(application_id, 'features.central_database', False)
- name: "For '{{ application_id }}': Create central database"
# I don't know why this includes leads to that the application_id in vars/main.yml of the database role isn't used
# This is the behaviour which I want, but I'm still wondering why ;)
include_role:
name: "svc-db-{{database_type}}"
when: applications | get_app_conf(application_id, 'features.central_database', False)
- name: "For '{{ application_id }}': Add Entry for Backup Procedure"
include_tasks: "{{ playbook_dir }}/roles/sys-ctl-bkp-docker-2-loc/tasks/04_seed-database-to-backup.yml"

View File

@@ -0,0 +1,3 @@
# Jinja2 configuration template
# Define your variables here

View File

@@ -0,0 +1,5 @@
MYSQL_DATABASE="{{ database_name }}"
MYSQL_USER="{{ database_username }}"
MYSQL_PASSWORD="{{ database_password }}"
MYSQL_ROOT_PASSWORD="{{ database_password }}"
MARIADB_AUTO_UPGRADE="1"

View File

@@ -0,0 +1,4 @@
POSTGRES_PASSWORD={{ database_password }}
POSTGRES_USER={{ database_username }}
POSTGRES_DB={{ database_name }}
POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale=C

View File

@@ -0,0 +1 @@
{% include 'roles/sys-svc-rdbms/templates/services/' + database_type + '.yml.j2' %}

View File

@@ -0,0 +1,23 @@
{# This template needs to be included in docker-compose.yml, which depend on a mariadb database #}
{% if not applications | get_app_conf(application_id, 'features.central_database', False) %}
{{ database_host }}:
container_name: {{ application_id | get_entity_name }}-database
logging:
driver: journald
image: mariadb
restart: {{ DOCKER_RESTART_POLICY }}
env_file:
- {{database_env}}
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW"
volumes:
- database:/var/lib/mysql
healthcheck:
test: [ "CMD", "sh", "-c", "/usr/bin/mariadb --user=$$MYSQL_USER --password=$$MYSQL_PASSWORD --execute 'SHOW DATABASES;'" ]
interval: 10s
timeout: 5s
retries: 18
networks:
- default
{% endif %}
{{ "\n" }}

View File

@@ -0,0 +1,22 @@
{# This template needs to be included in docker-compose.yml, which depend on a postgres database #}
{% if not applications | get_app_conf(application_id, 'features.central_database', False) %}
{{ database_host }}:
image: postgres:{{applications['svc-db-postgres'].version}}-alpine
container_name: {{ application_id | get_entity_name }}-database
env_file:
- {{database_env}}
restart: {{ DOCKER_RESTART_POLICY }}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{ database_name }}"]
interval: 10s
timeout: 5s
retries: 6
volumes:
- type: volume
source: database
target: /var/lib/postgresql/data
networks:
- default
{% endif %}
{{ "\n" }}

View File

@@ -0,0 +1,20 @@
# Helper variables
_dbtype: "{{ (database_type | d('') | trim) }}"
_database_id: "{{ ('svc-db-' ~ _dbtype) if _dbtype else '' }}"
_database_central_name: "{{ (applications | get_app_conf(_database_id, 'docker.services.' ~ _dbtype ~ '.name', False, '')) if _dbtype else '' }}"
_database_consumer_id: "{{ database_application_id | d(application_id) }}"
_database_consumer_entity_name: "{{ _database_consumer_id | get_entity_name }}"
_database_central_enabled: "{{ (applications | get_app_conf(_database_consumer_id, 'features.central_database', False)) if _dbtype else False }}"
# Definition
database_name: "{{ _database_consumer_entity_name }}"
database_instance: "{{ _database_central_name if _database_central_enabled else database_name }}" # This could lead to bugs at dedicated database @todo cleanup
database_host: "{{ _database_central_name if _database_central_enabled else 'database' }}" # This could lead to bugs at dedicated database @todo cleanup
database_username: "{{ _database_consumer_entity_name }}"
database_password: "{{ applications | get_app_conf(_database_consumer_id, 'credentials.database_password', true) }}"
database_port: "{{ (ports.localhost.database[_database_id] | d('')) if _dbtype else '' }}"
database_env: "{{ docker_compose.directories.env }}{{ database_type }}.env"
database_url_jdbc: "jdbc:{{ database_type if database_type == 'mariadb' else 'postgresql' }}://{{ database_host }}:{{ database_port }}/{{ database_name }}"
database_url_full: "{{ database_type }}://{{ database_username }}:{{ database_password }}@{{ database_host }}:{{ database_port }}/{{ database_name }}"
database_volume: "{{ _database_consumer_entity_name ~ '_' if not _database_central_enabled }}{{ database_host }}"

View File

@@ -0,0 +1,2 @@
# Docker
docker_pull_git_repository: false # Deactivated here to don't inhire this