nginx sync

This commit is contained in:
Zsolt Ero
2024-01-03 16:51:50 +01:00
parent 395447bbbd
commit 67587076fd
6 changed files with 35 additions and 39 deletions

View File

@@ -113,18 +113,12 @@ def prepare_http_host(c):
def upload_https_host_files(c):
c.sudo(f'mkdir -p {HTTP_HOST_BIN}')
put_dir(c, SCRIPTS_DIR / 'http_host', HTTP_HOST_BIN, file_permissions='755')
put_dir(c, SCRIPTS_DIR / 'http_host' / 'http_host_lib', f'{HTTP_HOST_BIN}/http_host_lib')
put_dir(
c,
SCRIPTS_DIR / 'http_host',
HTTP_HOST_BIN,
file_permissions='755',
exclude_set={'.gitignore'},
)
put_dir(
c,
SCRIPTS_DIR / 'http_host' / 'http_host_lib',
f'{HTTP_HOST_BIN}/http_host_lib',
SCRIPTS_DIR / 'http_host' / 'http_host_lib' / 'templates',
f'{HTTP_HOST_BIN}/http_host_lib/templates',
)
c.sudo('chown -R ofm:ofm /data/ofm/http_host')

View File

@@ -11,6 +11,7 @@ from http_host_lib.deploy_tileset import deploy_tileset
from http_host_lib.download_fonts import download_fonts
from http_host_lib.download_tileset import download_and_extract_tileset
from http_host_lib.mount import clean_up_mounts, create_fstab
from http_host_lib.nginx import write_nginx_config
from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo
@@ -114,7 +115,7 @@ def mount():
@cli.command()
def deploy_tileset_version():
"""
Deploys the tileset version specified by
Deploys the latest tileset version specified by
https://assets.openfreemap.com/versions/deployed_planet.txt
1. Check if the given version is present on the disk and is mounted
@@ -130,6 +131,21 @@ def deploy_tileset_version():
return deploy_tileset()
@cli.command()
def nginx_sync():
"""
Syncs the nginx config to the state of the system
"""
assert_linux()
assert_sudo()
if not MNT_DIR.exists():
sys.exit('mount needs to be run first')
write_nginx_config()
@cli.command()
@click.pass_context
def sync(ctx):
@@ -147,7 +163,10 @@ def sync(ctx):
ctx.invoke(download_assets)
ctx.invoke(deploy_tileset_version)
deployed = ctx.invoke(deploy_tileset_version)
if downloaded or deployed:
ctx.invoke(nginx_sync)
if __name__ == '__main__':

View File

@@ -1,6 +1,8 @@
from pathlib import Path
TEMPLATES_DIR = Path(__file__).parent / 'templates'
DEFAULT_RUNS_DIR = Path('/data/ofm/http_host/runs')
DEFAULT_ASSETS_DIR = Path('/data/ofm/http_host/assets')

View File

@@ -7,7 +7,7 @@ def deploy_tileset():
need_nginx_sync = False
for area in ['planet', 'monaco']:
r = requests.get(f'https://assets.openfreemap.com/versions/deployed_tiles_{area}.txt')
r = requests.get(f'https://assets.openfreemap.com/versions/deployed_{area}.txt')
r.raise_for_status()
remote_version = r.text.strip()
print(f' remote version for {area}: {remote_version}')

View File

@@ -1,39 +1,24 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
from pathlib import Path
import click
from http_host_lib import DEFAULT_RUNS_DIR, MNT_DIR, TEMPLATES_DIR
RUNS_DIR = Path('/data/ofm/http_host/runs')
@click.command()
def cli():
if not Path('/etc/fstab').exists():
sys.exit('Needs to be run on Linux')
if os.geteuid() != 0:
sys.exit('Needs sudo')
if not Path('/mnt/ofm').exists():
sys.exit('mounter.py needs to be run first')
with open(Path(__file__).parent / 'nginx_template_cf.conf') as fp:
def write_nginx_config():
with open(TEMPLATES_DIR / 'nginx_cf.conf') as fp:
nginx_template = fp.read()
location_block_str = ''
curl_text = ''
for subdir in Path('/mnt/ofm').iterdir():
for subdir in MNT_DIR.iterdir():
if not subdir.is_dir():
continue
area, version = subdir.name.split('-')
run_dir = RUNS_DIR / area / version
run_dir = DEFAULT_RUNS_DIR / area / version
if not run_dir.is_dir():
print(f"{run_dir} doesn't exists, skipping")
continue
@@ -59,7 +44,7 @@ def cli():
check=True,
)
# TODO raise expires if everything is stable
# TODO raise the expires times once things are stable
version_str = f"""
location /{area}/{version} {{ # no trailing hash
alias {tilejson_path}; # no trailing hash
@@ -94,13 +79,9 @@ def cli():
with open('/data/nginx/sites/ofm-tiles-org.conf', 'w') as fp:
fp.write(nginx_template)
print('nginx config written')
print(' nginx config written')
subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
print(curl_text)
if __name__ == '__main__':
cli()