1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2026-01-09 23:19:25 +00:00

restructure configuration directories

This commit is contained in:
FreddleSpl0it
2025-05-22 15:37:15 +02:00
parent dba9675a9b
commit f35def48cb
25 changed files with 113 additions and 124 deletions

View File

@@ -30,25 +30,27 @@ class BootstrapBase:
self.mysql_conn = None
self.redis_conn = None
def render_config(self, config_file):
def render_config(self, config_dir):
"""
Renders multiple Jinja2 templates based on a JSON config file.
Renders multiple Jinja2 templates from a config.json file in a given directory.
Each config entry must include:
- template (str): the template filename
- output (str): absolute path to the output file
Args:
config_dir (str or Path): Path to the directory containing config.json
Optional:
- clean_blank_lines (bool): remove empty lines from output
- if_not_exists (bool): skip rendering if output file already exists
Behavior:
- Renders each template defined in config.json
- Writes the result to the specified output path
- Also copies the rendered file to: <config_dir>/rendered_configs/<relative_output_path>
"""
from pathlib import Path
import json
from pathlib import Path
config_dir = Path(config_dir)
config_path = config_dir / "config.json"
config_path = Path(config_file)
if not config_path.exists():
print(f"Template config file not found: {config_path}")
print(f"config.json not found in: {config_dir}")
return
with config_path.open("r") as f:
@@ -76,7 +78,11 @@ class BootstrapBase:
with output_path.open("w") as f:
f.write(rendered)
print(f"Rendered {template_name} to {output_path}")
rendered_copy_path = config_dir / "rendered_configs" / output_path.name
rendered_copy_path.parent.mkdir(parents=True, exist_ok=True)
self.copy_file(output_path, rendered_copy_path)
print(f"Rendered {template_name}{output_path}")
def prepare_template_vars(self, overwrite_path, extra_vars = None):
"""

View File

@@ -32,8 +32,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/clamav/custom_templates',
'/etc/clamav/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -47,7 +47,7 @@ class Bootstrap(BootstrapBase):
self.set_timezone()
print("Render config")
self.render_config("/etc/clamav/config.json")
self.render_config("/service_config")
# Fix permissions
self.set_owner("/var/lib/clamav", "clamav", "clamav", recursive=True)

View File

@@ -31,8 +31,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/dovecot/custom_templates',
'/etc/dovecot/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -55,7 +55,7 @@ class Bootstrap(BootstrapBase):
self.set_timezone()
print("Render config")
self.render_config("/etc/dovecot/config.json")
self.render_config("/service_config")
files = [
"/etc/dovecot/mail_plugins",

View File

@@ -31,8 +31,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/mysql/conf.d/custom_templates',
'/etc/mysql/conf.d/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -46,7 +46,7 @@ class Bootstrap(BootstrapBase):
self.set_timezone()
print("Render config")
self.render_config("/etc/mysql/conf.d/config.json")
self.render_config("/service_config")
def start_temporary(self, socket):
"""

View File

@@ -23,8 +23,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/nginx/conf.d/custom_templates',
'/etc/nginx/conf.d/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -41,7 +41,7 @@ class Bootstrap(BootstrapBase):
self.set_timezone()
print("Render config")
self.render_config("/etc/nginx/conf.d/config.json")
self.render_config("/service_config")
def get_valid_cert_dirs(self):
ssl_dir = '/etc/ssl/mail/'

View File

@@ -16,8 +16,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/php-conf/custom_templates',
'/php-conf/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -44,7 +44,7 @@ class Bootstrap(BootstrapBase):
print("Render config")
self.render_config("/php-conf/config.json")
self.render_config("/service_config")
self.copy_file("/usr/local/etc/php/conf.d/opcache-recommended.ini", "/php-conf/opcache-recommended.ini")
self.copy_file("/usr/local/etc/php-fpm.d/z-pools.conf", "/php-conf/pools.conf")

View File

@@ -18,15 +18,15 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/opt/postfix/conf/custom_templates',
'/opt/postfix/conf/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True
)
with open("/opt/postfix/conf/extra.cf", "r") as f:
extra_config = f.read()
extra_config_path = Path("/opt/postfix/conf/extra.cf")
extra_config = extra_config_path.read_text() if extra_config_path.exists() else ""
extra_vars = {
"VALID_CERT_DIRS": self.get_valid_cert_dirs(),
"EXTRA_CF": extra_config
@@ -40,7 +40,7 @@ class Bootstrap(BootstrapBase):
self.set_syslog_redis()
print("Render config")
self.render_config("/opt/postfix/conf/config.json")
self.render_config("/service_config")
# Create SNI Config
self.run_command(["postmap", "-F", "hash:/opt/postfix/conf/sni.map"])

View File

@@ -61,8 +61,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/rspamd/custom_templates',
'/etc/rspamd/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -80,7 +80,7 @@ class Bootstrap(BootstrapBase):
self.set_timezone()
print("Render config")
self.render_config("/etc/rspamd/config.json")
self.render_config("/service_config")
# Fix missing default global maps, if any
# These exists in mailcow UI and should not be removed

View File

@@ -28,8 +28,8 @@ class Bootstrap(BootstrapBase):
# Setup Jinja2 Environment and load vars
self.env = Environment(
loader=FileSystemLoader([
'/etc/sogo/custom_templates',
'/etc/sogo/config_templates'
'/service_config/custom_templates',
'/service_config/config_templates'
]),
keep_trailing_newline=True,
lstrip_blocks=True,
@@ -48,7 +48,7 @@ class Bootstrap(BootstrapBase):
self.set_syslog_redis()
print("Render config")
self.render_config("/etc/sogo/config.json")
self.render_config("/service_config")
print("Fix permissions")
self.set_owner("/var/lib/sogo", "sogo", "sogo", recursive=True)

View File

@@ -1,5 +1,13 @@
#!/bin/sh
# Run hooks
for file in /hooks/*; do
if [ -x "${file}" ]; then
echo "Running hook ${file}"
"${file}"
fi
done
python3 -u /bootstrap/main.py
BOOTSTRAP_EXIT_CODE=$?

View File

@@ -3,5 +3,13 @@
"template": "whitelist.ign2.j2",
"output": "/var/lib/clamav/whitelist.ign2",
"clean_blank_lines": true
},
{
"template": "clamd.conf.j2",
"output": "/etc/clamav/clamd.conf"
},
{
"template": "freshclam.conf.j2",
"output": "/etc/clamav/freshclam.conf"
}
]

View File

@@ -106,5 +106,25 @@
{
"template": "custom_transport.pcre.j2",
"output": "/opt/postfix/conf/custom_transport.pcre"
},
{
"template": "allow_mailcow_local.regexp.j2",
"output": "/opt/postfix/conf/allow_mailcow_local.regexp"
},
{
"template": "anonymize_headers.pcre.j2",
"output": "/opt/postfix/conf/anonymize_headers.pcre"
},
{
"template": "local_transport.j2",
"output": "/opt/postfix/conf/local_transport"
},
{
"template": "master.cf.j2",
"output": "/opt/postfix/conf/master.cf"
},
{
"template": "smtp_dsn_filter.j2",
"output": "/opt/postfix/conf/smtp_dsn_filter"
}
]

View File

@@ -6,5 +6,9 @@
{
"template": "UIxTopnavToolbar.wox.j2",
"output": "/usr/lib/GNUstep/SOGo/Templates/UIxTopnavToolbar.wox"
},
{
"template": "sogo.conf.j2",
"output": "/etc/sogo/sogo.conf"
}
]

View File

@@ -1,34 +0,0 @@
#!/bin/bash
domain="$1"
gal_status="$2"
echo "
<!--
<example>
<key>canAuthenticate</key>
<string>YES</string>
<key>id</key>
<string>"${domain}"_ldap</string>
<key>isAddressBook</key>
<string>"${gal_status}"</string>
<key>IDFieldName</key>
<string>mail</string>
<key>UIDFieldName</key>
<string>uid</string>
<key>bindFields</key>
<array>
<string>mail</string>
</array>
<key>type</key>
<string>ldap</string>
<key>bindDN</key>
<string>cn=admin,dc=example,dc=local</string>
<key>bindPassword</key>
<string>password</string>
<key>baseDN</key>
<string>ou=People,dc=example,dc=local</string>
<key>hostname</key>
<string>ldap://1.2.3.4:389</string>
</example>
-->"