mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
set version
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
|
||||
class Configuration:
|
||||
@@ -14,8 +17,19 @@ class Configuration:
|
||||
|
||||
runs_dir = tile_gen_dir / 'runs'
|
||||
|
||||
ofm_config_dir = Path('/data/ofm/config')
|
||||
if Path('/data/ofm').exists():
|
||||
ofm_config_dir = Path('/data/ofm/config')
|
||||
else:
|
||||
repo_root = Path(__file__).parent.parent.parent.parent
|
||||
|
||||
ofm_config_dir = repo_root / 'config'
|
||||
|
||||
ofm_config = json.loads((ofm_config_dir / 'config.json').read_text())
|
||||
pprint(ofm_config)
|
||||
|
||||
rclone_config = ofm_config_dir / 'rclone.conf'
|
||||
|
||||
rclone_bin = subprocess.run(['which', 'rclone'], capture_output=True, text=True).stdout.strip()
|
||||
|
||||
|
||||
config = Configuration()
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
import subprocess
|
||||
|
||||
from http_host_lib.config import config
|
||||
|
||||
from tile_gen_lib.shared import get_versions_for_area
|
||||
|
||||
|
||||
def check_all_hosts(area, version):
|
||||
pass
|
||||
from tile_gen_lib.config import config
|
||||
from tile_gen_lib.shared import check_host_version, get_versions_for_area
|
||||
|
||||
|
||||
def check_and_set_version(area, version):
|
||||
if version == 'latest':
|
||||
versions = get_versions_for_area(area)
|
||||
version = versions[-1]
|
||||
print(f'Latest version on bucket: {area} {version}')
|
||||
|
||||
if not check_all_hosts(area, version):
|
||||
return
|
||||
|
||||
set_version(area, version)
|
||||
|
||||
|
||||
def set_version(area, version):
|
||||
print(f'setting version: {area} {version}')
|
||||
subprocess.run(
|
||||
[
|
||||
'rclone',
|
||||
config.rclone_bin,
|
||||
'rcat',
|
||||
f'remote:ofm-assets/deployed_versions/{area}.txt',
|
||||
],
|
||||
@@ -29,3 +28,19 @@ def set_version(area, version):
|
||||
check=True,
|
||||
input=version.strip().encode(),
|
||||
)
|
||||
|
||||
|
||||
def check_all_hosts(area, version) -> bool:
|
||||
oc = config.ofm_config
|
||||
|
||||
domain = oc['domain_ledns'] or oc['domain_le']
|
||||
print(f'Using domain: {domain}')
|
||||
|
||||
try:
|
||||
for host_ip in oc['http_host_list']:
|
||||
print(f'Checking {area} {version} on host {host_ip}')
|
||||
check_host_version(domain, host_ip, area, version)
|
||||
return True
|
||||
except Exception:
|
||||
print('Error, version not available')
|
||||
return False
|
||||
|
||||
@@ -15,14 +15,18 @@ def get_versions_for_area(area: str) -> list:
|
||||
|
||||
|
||||
def check_host_version(domain, host_ip, area, version):
|
||||
# check versioned TileJSON
|
||||
url = f'https://{domain}/{area}/{version}'
|
||||
tilejson_str = pycurl_get(url, domain, host_ip)
|
||||
tilejson = json.loads(tilejson_str)
|
||||
tiles_url = tilejson['tiles'][0]
|
||||
version_in_tilejson = tiles_url.split('/')[4]
|
||||
assert version_in_tilejson == version
|
||||
|
||||
# check actual vector tile
|
||||
url = f'https://{domain}/{area}/{version}/14/8529/5975.pbf'
|
||||
assert pycurl_status(url, domain, host_ip) == 200
|
||||
|
||||
# check style
|
||||
url = f'https://{domain}/styles/bright'
|
||||
assert pycurl_status(url, domain, host_ip) == 200
|
||||
|
||||
|
||||
def check_host_latest(domain, host_ip, area, version):
|
||||
# check TileJSON first
|
||||
@@ -42,6 +46,9 @@ def check_host_latest(domain, host_ip, area, version):
|
||||
assert pycurl_status(url, domain, host_ip) == 200
|
||||
|
||||
|
||||
# pycurl
|
||||
|
||||
|
||||
def pycurl_status(url, domain, host_ip):
|
||||
"""
|
||||
Uses pycurl to make a HTTPS HEAD request using custom resolving,
|
||||
|
||||
Reference in New Issue
Block a user