Implemented correct path replace not just for context: but also for build: paths

This commit is contained in:
Kevin Veen-Birkenbach 2025-08-11 18:46:02 +02:00
parent b0737b1cdb
commit e8c19b4b84
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E

View File

@ -2,40 +2,67 @@ import re
import yaml import yaml
def compose_mods(yml_text, docker_repository_path, env_file): def compose_mods(yml_text, docker_repository_path, env_file):
# Named volume rewrites
yml_text = re.sub(r'\./data/postgres:/var/lib/postgresql/data', 'database:/var/lib/postgresql/data', yml_text) yml_text = re.sub(r'\./data/postgres:/var/lib/postgresql/data', 'database:/var/lib/postgresql/data', yml_text)
yml_text = re.sub(r'\./data/bigbluebutton:/var/bigbluebutton', 'bigbluebutton:/var/bigbluebutton', yml_text) yml_text = re.sub(r'\./data/bigbluebutton:/var/bigbluebutton', 'bigbluebutton:/var/bigbluebutton', yml_text)
yml_text = re.sub(r'\./data/freeswitch-meetings:/var/freeswitch/meetings', 'freeswitch:/var/freeswitch/meetings', yml_text) yml_text = re.sub(r'\./data/freeswitch-meetings:/var/freeswitch/meetings', 'freeswitch:/var/freeswitch/meetings', yml_text)
yml_text = re.sub(r'\./data/greenlight:/usr/src/app/storage', 'greenlight:/usr/src/app/storage', yml_text) yml_text = re.sub(r'\./data/greenlight:/usr/src/app/storage', 'greenlight:/usr/src/app/storage', yml_text)
yml_text = re.sub(r'\./data/mediasoup:/var/mediasoup', 'mediasoup:/var/mediasoup', yml_text) yml_text = re.sub(r'\./data/mediasoup:/var/mediasoup', 'mediasoup:/var/mediasoup', yml_text)
yml_text = re.sub(r'\./', docker_repository_path + '/', yml_text)
yml_text = re.sub( # Make other ./ paths absolute to the given repository
r'(^\s*context:\s*)' + re.escape(docker_repository_path) + r'/mod/(.*)', yml_text = re.sub(r'\./', docker_repository_path.rstrip('/') + '/', yml_text)
r'\1' + docker_repository_path + r'/mod/\2',
yml_text, flags=re.MULTILINE # Keep the old context helpers (harmless if YAML step below fixes everything)
)
yml_text = re.sub( yml_text = re.sub(
r'(^\s*context:\s*)mod/(.*)', r'(^\s*context:\s*)mod/(.*)',
r'\1' + docker_repository_path + r'/mod/\2', r'\1' + docker_repository_path.rstrip('/') + r'/mod/\2',
yml_text, flags=re.MULTILINE yml_text, flags=re.MULTILINE
) )
def _prefix_mod(path: str) -> str:
"""Prefix 'mod/...' (or './mod/...') with docker_repository_path, avoiding //."""
p = str(path).strip().strip('\'"')
p = p.lstrip('./')
if p.startswith('mod/'):
return docker_repository_path.rstrip('/') + '/' + p
return path
try: try:
data = yaml.safe_load(yml_text) data = yaml.safe_load(yml_text) or {}
services = data.get('services', {}) services = data.get('services', {}) or {}
for name, svc in services.items(): for name, svc in services.items():
if not isinstance(svc, dict):
continue
# ensure env_file
svc['env_file'] = [env_file] svc['env_file'] = [env_file]
# handle build when it is a string: e.g., build: "mod/periodic"
if 'build' in svc:
b = svc['build']
if isinstance(b, str):
svc['build'] = _prefix_mod(b)
elif isinstance(b, dict):
ctx = b.get('context')
if isinstance(ctx, str):
b['context'] = _prefix_mod(ctx)
# extras
if name == 'redis': if name == 'redis':
vols = svc.get('volumes') vols = svc.get('volumes')
if not vols or not isinstance(vols, list): if not vols or not isinstance(vols, list):
svc['volumes'] = ['redis:/data'] svc['volumes'] = ['redis:/data']
elif 'redis:/data' not in vols: elif 'redis:/data' not in vols:
svc['volumes'].append('redis:/data') svc['volumes'].append('redis:/data')
if name == 'coturn': if name == 'coturn':
vols = svc.get('volumes') vols = svc.get('volumes')
if not vols or not isinstance(vols, list): if not vols or not isinstance(vols, list):
svc['volumes'] = ['coturn:/var/lib/coturn'] svc['volumes'] = ['coturn:/var/lib/coturn']
elif 'coturn:/var/lib/coturn' not in vols: elif 'coturn:/var/lib/coturn' not in vols:
svc['volumes'].append('coturn:/var/lib/coturn') svc['volumes'].append('coturn:/var/lib/coturn')
if name == 'bbb-graphql-server': if name == 'bbb-graphql-server':
svc['healthcheck'] = { svc['healthcheck'] = {
'test': ['CMD', 'curl', '-f', 'http://localhost:8085/healthz'], 'test': ['CMD', 'curl', '-f', 'http://localhost:8085/healthz'],
@ -44,27 +71,28 @@ def compose_mods(yml_text, docker_repository_path, env_file):
'retries': 5, 'retries': 5,
'start_period': '10s' 'start_period': '10s'
} }
data['services'] = services data['services'] = services
# **ADD THIS BLOCK:**
# Only add volumes block if not present # Only add volumes block if not present
if 'volumes' not in data: data.setdefault('volumes', {
data['volumes'] = { 'database': None,
'database': None, 'greenlight': None,
'greenlight': None, 'redis': None,
'redis': None, 'coturn': None,
'coturn': None, 'freeswitch': None,
'freeswitch': None, 'bigbluebutton': None,
'bigbluebutton': None, 'mediasoup': None
'mediasoup': None })
}
yml_text = yaml.dump(data, default_flow_style=False, sort_keys=False) yml_text = yaml.dump(data, default_flow_style=False, sort_keys=False)
except Exception: except Exception:
# leave the original yml_text as-is if parsing fails
pass pass
return yml_text return yml_text
class FilterModule(object): class FilterModule(object):
def filters(self): def filters(self):
return { return {