mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 22:12:15 +00:00
host_manager
This commit is contained in:
@@ -9,7 +9,7 @@ def write_nginx_config():
|
||||
with open(TEMPLATES_DIR / 'nginx_cf.conf') as fp:
|
||||
nginx_template = fp.read()
|
||||
|
||||
location_block_str = ''
|
||||
location_str = ''
|
||||
curl_text = ''
|
||||
|
||||
for subdir in MNT_DIR.iterdir():
|
||||
@@ -18,55 +18,7 @@ def write_nginx_config():
|
||||
|
||||
area, version = subdir.name.split('-')
|
||||
|
||||
run_dir = DEFAULT_RUNS_DIR / area / version
|
||||
if not run_dir.is_dir():
|
||||
print(f" {run_dir} doesn't exists, skipping")
|
||||
continue
|
||||
|
||||
tilejson_path = run_dir / 'tilejson-tiles-org.json'
|
||||
|
||||
metadata_path = subdir / 'metadata.json'
|
||||
if not metadata_path.is_file():
|
||||
print(f" {metadata_path} doesn't exists, skipping")
|
||||
continue
|
||||
|
||||
url_prefix = f'https://tiles.openfreemap.org/{area}/{version}'
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
Path(__file__).parent.parent / 'metadata_to_tilejson.py',
|
||||
'--minify',
|
||||
metadata_path,
|
||||
tilejson_path,
|
||||
url_prefix,
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# TODO # target 10y
|
||||
version_str = f"""
|
||||
location /{area}/{version} {{ # no trailing hash
|
||||
alias {tilejson_path}; # no trailing hash
|
||||
default_type application/json;
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d;
|
||||
}}
|
||||
|
||||
location /{area}/{version}/ {{ # trailing hash
|
||||
alias {subdir}/tiles/; # trailing hash
|
||||
try_files $uri @empty;
|
||||
|
||||
add_header Content-Encoding gzip;
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d; # target 10y
|
||||
}}
|
||||
"""
|
||||
|
||||
location_block_str += version_str
|
||||
location_str += create_version_location(area, version, subdir)
|
||||
|
||||
if not curl_text:
|
||||
curl_text = (
|
||||
@@ -75,7 +27,9 @@ def write_nginx_config():
|
||||
f'curl -I https://tiles.openfreemap.org/{area}/{version}/14/8529/5975.pbf'
|
||||
)
|
||||
|
||||
nginx_template = nginx_template.replace('___LOCATION_BLOCKS___', location_block_str)
|
||||
location_str += create_deployed_location(area, version, subdir)
|
||||
|
||||
nginx_template = nginx_template.replace('___LOCATION_BLOCKS___', location_str)
|
||||
|
||||
with open('/data/nginx/sites/ofm-tiles-org.conf', 'w') as fp:
|
||||
fp.write(nginx_template)
|
||||
@@ -85,3 +39,57 @@ def write_nginx_config():
|
||||
subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
|
||||
|
||||
print(curl_text)
|
||||
|
||||
|
||||
def create_version_location(area: str, version: str, subdir: Path):
|
||||
run_dir = DEFAULT_RUNS_DIR / area / version
|
||||
if not run_dir.is_dir():
|
||||
print(f" {run_dir} doesn't exists, skipping")
|
||||
return ''
|
||||
|
||||
tilejson_path = run_dir / 'tilejson-tiles-org.json'
|
||||
|
||||
metadata_path = subdir / 'metadata.json'
|
||||
if not metadata_path.is_file():
|
||||
print(f" {metadata_path} doesn't exists, skipping")
|
||||
return ''
|
||||
|
||||
url_prefix = f'https://tiles.openfreemap.org/{area}/{version}'
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
Path(__file__).parent.parent / 'metadata_to_tilejson.py',
|
||||
'--minify',
|
||||
metadata_path,
|
||||
tilejson_path,
|
||||
url_prefix,
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# TODO # target 10y
|
||||
return f"""
|
||||
location /{area}/{version} {{ # no trailing hash
|
||||
alias {tilejson_path}; # no trailing hash
|
||||
default_type application/json;
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d;
|
||||
}}
|
||||
|
||||
location /{area}/{version}/ {{ # trailing hash
|
||||
alias {subdir}/tiles/; # trailing hash
|
||||
try_files $uri @empty;
|
||||
|
||||
add_header Content-Encoding gzip;
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d; # target 10y
|
||||
}}
|
||||
"""
|
||||
|
||||
|
||||
def create_deployed_location(area: str, version: str, subdir: Path):
|
||||
pass
|
||||
|
||||
@@ -3,7 +3,7 @@ from pathlib import Path
|
||||
import requests
|
||||
|
||||
|
||||
def deploy_tileset():
|
||||
def set_tileset_versions():
|
||||
need_nginx_sync = False
|
||||
|
||||
for area in ['planet', 'monaco']:
|
||||
Reference in New Issue
Block a user