65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import re
|
|
|
|
def main():
|
|
old_vars = {}
|
|
with open('appwrite-coolify.yml', 'r') as f:
|
|
for line in f:
|
|
m = re.match(r'^\s+-\s+([A-Z0-9_]+)=(.*)', line)
|
|
if m:
|
|
var_name = m.group(1)
|
|
val = m.group(2)
|
|
# Prefer mappings that have a '$' (i.e. dynamic mapping)
|
|
if var_name not in old_vars or '$' in val:
|
|
old_vars[var_name] = line.strip()
|
|
|
|
# Let's explicitly check some known ones to be safe
|
|
# e.g., OPR_EXECUTOR_SECRET should be $SERVICE_PASSWORD_64_APPWRITE
|
|
|
|
output_lines = []
|
|
with open('new_base.yml', 'r') as f:
|
|
in_environment = False
|
|
for line in f:
|
|
if line.strip() == 'environment:':
|
|
in_environment = True
|
|
output_lines.append(line)
|
|
continue
|
|
|
|
# If we are in environment block but hit something that isn't a list item
|
|
if in_environment and line.strip() and not line.strip().startswith('-'):
|
|
in_environment = False
|
|
|
|
if in_environment and line.strip().startswith('-'):
|
|
m = re.match(r'^(\s+-\s+)([A-Z0-9_]+)(.*)', line)
|
|
# Check for quoted vars if any, though they shouldn't exist in new_base.yml
|
|
m_quoted = re.match(r'^(\s+-\s+)"([A-Z0-9_]+)=(.*)"', line)
|
|
|
|
if m_quoted:
|
|
indent = m_quoted.group(1)
|
|
var_name = m_quoted.group(2)
|
|
elif m:
|
|
indent = m.group(1)
|
|
var_name = m.group(2)
|
|
else:
|
|
output_lines.append(line)
|
|
continue
|
|
|
|
# Hardcoded fix for the bug
|
|
if var_name == 'OPR_EXECUTOR_RUNTIMES':
|
|
output_lines.append(f'{indent.split("-")[0]}- "OPR_EXECUTOR_RUNTIMES=${{_APP_FUNCTIONS_RUNTIMES}},${{_APP_SITES_RUNTIMES}}"\n')
|
|
continue
|
|
|
|
if var_name in old_vars:
|
|
base_indent = indent.split('-')[0]
|
|
output_lines.append(f"{base_indent}{old_vars[var_name]}\n")
|
|
else:
|
|
output_lines.append(line)
|
|
else:
|
|
output_lines.append(line)
|
|
|
|
with open('merged_appwrite-coolify.yml', 'w') as f:
|
|
for line in output_lines:
|
|
f.write(line)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|