114 lines
4.6 KiB
Python
114 lines
4.6 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)
|
|
if var_name not in old_vars or '$' in val:
|
|
old_vars[var_name] = line.strip()
|
|
|
|
output_lines = []
|
|
in_executor_env = False
|
|
in_traefik_ports = False
|
|
current_service = None
|
|
|
|
with open('new_base.yml', 'r') as f:
|
|
for line in f:
|
|
m_service = re.match(r'^ ([a-zA-Z0-9_-]+):$', line)
|
|
if m_service:
|
|
current_service = m_service.group(1)
|
|
|
|
# Traefik ports removal
|
|
if current_service == 'traefik' and line.strip() == 'ports:':
|
|
in_traefik_ports = True
|
|
continue
|
|
if in_traefik_ports:
|
|
if line.strip().startswith('-'):
|
|
continue
|
|
else:
|
|
in_traefik_ports = False
|
|
|
|
# Executor Env to Dict
|
|
if line.strip() == 'container_name: openruntimes-executor':
|
|
output_lines.append(' container_name: exc1\n')
|
|
continue
|
|
if line.strip() == 'hostname: appwrite-executor':
|
|
output_lines.append(' hostname: exc1\n')
|
|
continue
|
|
|
|
if current_service == 'openruntimes-executor' and line.strip() == 'environment:':
|
|
in_executor_env = True
|
|
output_lines.append(line)
|
|
continue
|
|
|
|
if in_executor_env:
|
|
if line.strip() == '' or (not line.strip().startswith('-') and not line.startswith(' ')):
|
|
in_executor_env = False
|
|
elif line.strip().startswith('-'):
|
|
m = re.match(r'^(\s+)-\s+([A-Z0-9_]+)=?(.*)', line)
|
|
if m:
|
|
indent = m.group(1)
|
|
var_name = m.group(2)
|
|
val = m.group(3)
|
|
|
|
# Apply merge
|
|
if var_name in old_vars:
|
|
old_val_full = old_vars[var_name]
|
|
if '=' in old_val_full:
|
|
val = old_val_full.split('=', 1)[1]
|
|
|
|
if var_name == 'OPR_EXECUTOR_RUNTIMES':
|
|
val = '${_APP_FUNCTIONS_RUNTIMES},${_APP_SITES_RUNTIMES}'
|
|
if var_name == 'OPEN_RUNTIMES_NFT':
|
|
if var_name == 'OPR_EXECUTOR_SECRET':
|
|
val = '$SERVICE_PASSWORD_64_APPWRITE'
|
|
if var_name == '_APP_OPENSSL_KEY_V1':
|
|
val = '$SERVICE_PASSWORD_64_APPWRITE'
|
|
if var_name == '_APP_DB_USER':
|
|
val = '$SERVICE_USER_MARIADB'
|
|
if var_name == '_APP_DB_PASS':
|
|
val = '$SERVICE_PASSWORD_MARIADB'
|
|
val = '${_APP_OPEN_RUNTIMES_NFT}'
|
|
|
|
output_lines.append(f"{indent}{var_name}: {val}\n")
|
|
continue
|
|
|
|
# Normal merge for everything else
|
|
if line.strip().startswith('-'):
|
|
m = re.match(r'^(\s+-\s+)([A-Z0-9_]+)=?(.*)', line)
|
|
if m:
|
|
indent = m.group(1)
|
|
var_name = m.group(2)
|
|
if var_name in old_vars:
|
|
# EXCEPT mariadb vars we just handled
|
|
if current_service == 'mariadb' and var_name in ['MYSQL_ROOT_PASSWORD', 'MYSQL_DATABASE', 'MYSQL_USER', 'MYSQL_PASSWORD']:
|
|
pass
|
|
else:
|
|
base_indent = indent.split('-')[0]
|
|
output_lines.append(f"{base_indent}{old_vars[var_name]}\n")
|
|
continue
|
|
|
|
output_lines.append(line)
|
|
|
|
# Post processing for networks external
|
|
final_out = []
|
|
for line in output_lines:
|
|
final_out.append(line)
|
|
if line.strip() in ['name: gateway', 'name: appwrite', 'name: runtimes']:
|
|
final_out.append(' external: true\n')
|
|
|
|
# rename mariadb and redis service names
|
|
final_str = "".join(final_out)
|
|
final_str = final_str.replace(" mariadb:\n", " appwrite-mariadb:\n")
|
|
final_str = final_str.replace(" redis:\n", " appwrite-redis:\n")
|
|
|
|
with open('appwrite-coolify.yml', 'w') as f:
|
|
f.write(final_str)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|