This commit is contained in:
Zsolt Ero
2025-10-09 01:22:53 +02:00
parent f7299f6836
commit b3e8bff774
3 changed files with 36 additions and 37 deletions

View File

@@ -120,11 +120,11 @@ def tile_gen(
# #
# @cli.command() @cli.command()
# @common_options @common_options
# def debug(hostname, user, port, noninteractive): def debug(hostname, user, port, noninteractive):
# c = get_connection(hostname, user, port) c = get_connection(hostname, user, port)
# run_http_host_sync(c) upload_config_and_certs(c)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -21,25 +21,23 @@ def write_nginx_config():
conf = config.json_config conf = config.json_config
curl_help_lines = [] curl_help_text = ''
for domain_data in conf['domains']: for domain_data in conf['domains']:
curl_help_lines += process_domain(domain_data) curl_help_text += process_domain(domain_data)
subprocess.run(['nginx', '-t'], check=True) subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True) subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
if config.ofm_config.get('skip_planet'): exclude_path = '/planet' if conf.get('skip_planet') else '/monaco'
curl_help_lines = [l for l in curl_help_lines if '/planet' not in l] curl_help_lines = [l for l in curl_help_text.splitlines() if exclude_path not in l]
else:
curl_help_lines = [l for l in curl_help_lines if '/monaco' not in l]
curl_help_str = '\n'.join(curl_help_lines) curl_help_joined = '\n'.join(curl_help_lines)
print(f'test with:\n{curl_help_str}') print(f'test with:\n{curl_help_joined}')
def process_domain(domain_data) -> list: def process_domain(domain_data) -> str:
if domain_data['cert'] == 'upload': if domain_data['cert']['type'] == 'upload':
domain_data['cert_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.cert' domain_data['cert_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.cert'
domain_data['key_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.key' domain_data['key_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.key'
@@ -50,38 +48,40 @@ def process_domain(domain_data) -> list:
return create_nginx_conf(domain_data) return create_nginx_conf(domain_data)
return [] return ''
def create_nginx_conf(domain_data: dict): def create_nginx_conf(domain_data: dict) -> str:
dynamic_block_lines, curl_help = dynamic_blocks(domain_data) dynamic_block_text, curl_help_text = dynamic_blocks(domain_data)
template = (config.nginx_templates / 'common.conf').read_text() template = (config.nginx_templates / 'common.conf').read_text()
template = template.replace('__DYNAMIC_BLOCKS__', dynamic_block_lines) template = template.replace('__DYNAMIC_BLOCKS__', dynamic_block_text)
template = template.replace('__DOMAIN_SLUG__', domain_data['slug']) template = template.replace('__DOMAIN_SLUG__', domain_data['slug'])
template = template.replace('__DOMAIN__', domain_data['domain']) template = template.replace('__DOMAIN__', domain_data['domain'])
curl_help = curl_help.replace('__DOMAIN_SLUG__', domain_data['slug']) curl_help_text = curl_help_text.replace('__DOMAIN_SLUG__', domain_data['slug'])
curl_help = curl_help.replace('__DOMAIN__', domain_data['domain']) curl_help_text = curl_help_text.replace('__DOMAIN__', domain_data['domain'])
(config.nginx_sites_dir / f'ofm-{domain_data["slug"]}.conf').write_text(template) (config.nginx_sites_dir / f'ofm-{domain_data["slug"]}.conf').write_text(template)
print(f' nginx config written: {domain_data["domain"]} {domain_data["slug"]}') print(f' nginx config written: {domain_data["domain"]} {domain_data["slug"]}')
return curl_help print('=' * 20, curl_help_text)
return curl_help_text
def dynamic_blocks(domain_data: dict): def dynamic_blocks(domain_data: dict) -> tuple[str, str]:
nginx_conf_lines = '' nginx_conf_text = ''
curl_help_lines = [] curl_help_text = ''
for subdir in config.mnt_dir.iterdir(): for subdir in config.mnt_dir.iterdir():
if not subdir.is_dir(): if not subdir.is_dir():
continue continue
area, version = subdir.name.split('-') area, version = subdir.name.split('-')
nginx_conf_lines += create_version_location( nginx_conf_text += create_version_location(
area=area, version=version, mnt_dir=subdir, domain_data=domain_data area=area, version=version, mnt_dir=subdir, domain_data=domain_data
) )
@@ -90,12 +90,10 @@ def dynamic_blocks(domain_data: dict):
f'/{area}/{version}/14/8529/5975.pbf', f'/{area}/{version}/14/8529/5975.pbf',
f'/{area}/{version}/9999/9999/9999.pbf', # empty_tile test f'/{area}/{version}/9999/9999/9999.pbf', # empty_tile test
]: ]:
curl_help_lines += [ curl_help_text += f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}\n'
f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}', curl_help_text += f'curl -sI https://__DOMAIN__{path} | sort\n'
f'curl -sI https://__DOMAIN__{path} | sort',
]
nginx_conf_lines += create_latest_locations(domain_data=domain_data) nginx_conf_text += create_latest_locations(domain_data=domain_data)
for area in config.areas: for area in config.areas:
for path in [ for path in [
@@ -104,14 +102,13 @@ def dynamic_blocks(domain_data: dict):
f'/{area}/19700101_old_version_test/14/8529/5975.pbf', f'/{area}/19700101_old_version_test/14/8529/5975.pbf',
f'/{area}/19700101_old_version_test/9999/9999/9999.pbf', # empty_tile test f'/{area}/19700101_old_version_test/9999/9999/9999.pbf', # empty_tile test
]: ]:
curl_help_lines += [ curl_help_text += f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}\n'
f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}', curl_help_text += f'curl -sI https://__DOMAIN__{path} | sort\n'
f'curl -sI https://__DOMAIN__{path} | sort',
]
nginx_conf_lines += '\n' + (config.nginx_templates / 'static_blocks.conf').read_text() nginx_conf_text += '\n' + (config.nginx_templates / 'static_blocks.conf').read_text()
print(curl_help_text)
return nginx_conf_lines, curl_help_lines return nginx_conf_text, curl_help_text
def create_version_location(*, area: str, version: str, mnt_dir: Path, domain_data: dict) -> str: def create_version_location(*, area: str, version: str, mnt_dir: Path, domain_data: dict) -> str:

View File

@@ -1,4 +1,5 @@
import json import json
import sys
from pathlib import Path from pathlib import Path
import json5 import json5
@@ -71,6 +72,7 @@ def upload_config_and_certs(c):
domain_data['slug'] = slugify(domain_data['domain'], separator='_') domain_data['slug'] = slugify(domain_data['domain'], separator='_')
if domain_data['cert']['type'] == 'upload': if domain_data['cert']['type'] == 'upload':
print(domain_data)
local_cert_path = Path(domain_data['cert']['cert_path']) local_cert_path = Path(domain_data['cert']['cert_path'])
# handle relative paths - make them relative to config.local_config_dir # handle relative paths - make them relative to config.local_config_dir