From 154d592acec7ea0c132d4654c4713da9143e4c4b Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Wed, 8 Oct 2025 01:26:20 +0200 Subject: [PATCH] work --- ssh_lib/benchmark.py | 4 ++-- ssh_lib/kernel.py | 8 ++++++-- ssh_lib/nginx.py | 10 +++++----- ssh_lib/planetiler.py | 20 ++++++++++---------- ssh_lib/tasks_http_host.py | 38 +++++++++++++++++++++++++++++++------- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/ssh_lib/benchmark.py b/ssh_lib/benchmark.py index 8e42ea9..0834183 100644 --- a/ssh_lib/benchmark.py +++ b/ssh_lib/benchmark.py @@ -1,4 +1,4 @@ -from ssh_lib import MODULES_DIR +from ssh_lib.config import config from ssh_lib.utils import apt_get_install, exists, put @@ -20,4 +20,4 @@ def c1000k(c): def wrk(c): apt_get_install(c, 'wrk') c.sudo('mkdir -p /data/ofm/benchmark') - put(c, f'{MODULES_DIR}/http_host/benchmark/wrk_custom_list.lua', '/data/ofm/benchmark') + put(c, f'{config.modules_dir}/http_host/benchmark/wrk_custom_list.lua', '/data/ofm/benchmark') diff --git a/ssh_lib/kernel.py b/ssh_lib/kernel.py index f317095..f8933c2 100644 --- a/ssh_lib/kernel.py +++ b/ssh_lib/kernel.py @@ -1,4 +1,4 @@ -from ssh_lib import ASSETS_DIR +from ssh_lib.config import config from ssh_lib.utils import put, put_str @@ -25,6 +25,10 @@ def kernel_vmovercommit(c): def kernel_thp_fix(c): # transparent_hugepage - put(c, f'{ASSETS_DIR}/kernel/thp_fix_service', '/etc/systemd/system/thp_fix.service') + put( + c, + f'{config.local_assets_dir}/kernel/thp_fix_service', + '/etc/systemd/system/thp_fix.service', + ) c.sudo('systemctl daemon-reload') c.sudo('systemctl enable thp_fix') diff --git a/ssh_lib/nginx.py b/ssh_lib/nginx.py index 5325473..602745c 100644 --- a/ssh_lib/nginx.py +++ b/ssh_lib/nginx.py @@ -1,4 +1,4 @@ -from ssh_lib import ASSETS_DIR +from ssh_lib.config import config from ssh_lib.utils import ( apt_get_install, apt_get_purge, @@ -41,10 +41,10 @@ def nginx(c): generate_self_signed_cert(c) - put(c, f'{ASSETS_DIR}/nginx/nginx.conf', '/etc/nginx/') - put(c, f'{ASSETS_DIR}/nginx/mime.types', '/etc/nginx/') - put(c, f'{ASSETS_DIR}/nginx/default_disable.conf', '/data/nginx/sites') - put(c, f'{ASSETS_DIR}/nginx/cloudflare.conf', '/data/nginx/config') + put(c, f'{config.local_assets_dir}/nginx/nginx.conf', '/etc/nginx/') + put(c, f'{config.local_assets_dir}/nginx/mime.types', '/etc/nginx/') + put(c, f'{config.local_assets_dir}/nginx/default_disable.conf', '/data/nginx/sites') + put(c, f'{config.local_assets_dir}/nginx/cloudflare.conf', '/data/nginx/config') sudo_cmd(c, 'curl https://ssl-config.mozilla.org/ffdhe2048.txt -o /etc/nginx/ffdhe2048.txt') diff --git a/ssh_lib/planetiler.py b/ssh_lib/planetiler.py index f71257b..d2d8f4b 100644 --- a/ssh_lib/planetiler.py +++ b/ssh_lib/planetiler.py @@ -1,10 +1,10 @@ -from ssh_lib import PLANETILER_BIN, PLANETILER_SRC +from ssh_lib.config import config from ssh_lib.java import java from ssh_lib.utils import exists, sudo_cmd PLANETILER_COMMIT = 'cc769c' -PLANETILER_PATH = f'{PLANETILER_BIN}/planetiler.jar' +PLANETILER_PATH = f'{config.planetiler_bin}/planetiler.jar' def install_planetiler(c): @@ -15,24 +15,24 @@ def install_planetiler(c): java(c) c.sudo('rm -rf /root/.m2') # cleaning maven cache - c.sudo(f'rm -rf {PLANETILER_BIN} {PLANETILER_SRC}') - c.sudo(f'mkdir -p {PLANETILER_BIN} {PLANETILER_SRC}') + c.sudo(f'rm -rf {config.planetiler_bin} {config.planetiler_src}') + c.sudo(f'mkdir -p {config.planetiler_bin} {config.planetiler_src}') c.sudo('git config --global advice.detachedHead false') c.sudo( - f'git clone --recurse-submodules https://github.com/onthegomap/planetiler.git {PLANETILER_SRC}' + f'git clone --recurse-submodules https://github.com/onthegomap/planetiler.git {config.planetiler_src}' ) - sudo_cmd(c, f'cd {PLANETILER_SRC} && git checkout {PLANETILER_COMMIT}') - sudo_cmd(c, f'cd {PLANETILER_SRC} && git submodule update --init --recursive') + sudo_cmd(c, f'cd {config.planetiler_src} && git checkout {PLANETILER_COMMIT}') + sudo_cmd(c, f'cd {config.planetiler_src} && git submodule update --init --recursive') - sudo_cmd(c, f'cd {PLANETILER_SRC} && ./mvnw clean test package') + sudo_cmd(c, f'cd {config.planetiler_src} && ./mvnw clean test package') c.sudo( - f'mv {PLANETILER_SRC}/planetiler-dist/target/planetiler-dist-*-SNAPSHOT-with-deps.jar {PLANETILER_PATH}', + f'mv {config.planetiler_src}/planetiler-dist/target/planetiler-dist-*-SNAPSHOT-with-deps.jar {PLANETILER_PATH}', warn=True, ) c.sudo(f'java -jar {PLANETILER_PATH} --help', hide=True) - c.sudo(f'rm -rf {PLANETILER_SRC}') + c.sudo(f'rm -rf {config.planetiler_src}') diff --git a/ssh_lib/tasks_http_host.py b/ssh_lib/tasks_http_host.py index 6cc0ae6..74124c0 100644 --- a/ssh_lib/tasks_http_host.py +++ b/ssh_lib/tasks_http_host.py @@ -1,6 +1,8 @@ import json +from pathlib import Path import json5 +from jsonschema import ValidationError, validate from ssh_lib.benchmark import c1000k, wrk from ssh_lib.config import config @@ -37,17 +39,41 @@ def upload_config_and_certs(c): print(f'{config.local_config_jsonc} not found. Make sure it exists in the /config dir') return - # validate using json5 + jsonschema - # use config.config_schema_json - config_data = json5.loads(config.local_config_jsonc.read_text()) + # Load and parse the JSONC/JSON5 config file + try: + config_data = json5.loads(config.local_config_jsonc.read_text()) + except Exception as e: + print(f'❌ Error parsing config file: {e}') + return + + # Load the JSON schema + try: + schema = json.loads(config.config_schema_json.read_text()) + except Exception as e: + print(f'❌ Error loading schema file: {e}') + return + + # Validate the config against the schema + try: + validate(instance=config_data, schema=schema) + print('✓ Configuration is valid') + except ValidationError as e: + print('❌ Configuration validation failed:') + print(f' Error: {e.message}') + if e.path: + print(f' Path: {".".join(str(p) for p in e.path)}') + return + except Exception as e: + print(f'❌ Validation error: {e}') + return # pre-generate all the slugs for domain_data in config_data['domains']: domain_data['slug'] = slugify(domain_data['domain'], separator='_') if domain_data['cert']['type'] == 'upload': - local_cert_path = domain_data['cert']['cert_path'] - cert_basename = local_cert_path.basename + local_cert_path = Path(domain_data['cert']['cert_path']) + cert_basename = local_cert_path.stem local_key_path = local_cert_path.parent / f'{cert_basename}.key' if not local_cert_path.is_file() or local_key_path.is_file(): print( @@ -61,8 +87,6 @@ def upload_config_and_certs(c): put(c, local_cert_path, remote_cert_path) put(c, local_key_path, remote_key_path) - - # generate a normal JSON and upload it config_str = json.dumps(config_data, indent=2, ensure_ascii=False) put_str(c, f'{config.remote_config}/config.json', config_str)