mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
nginx sync
This commit is contained in:
@@ -113,18 +113,12 @@ def prepare_http_host(c):
|
|||||||
def upload_https_host_files(c):
|
def upload_https_host_files(c):
|
||||||
c.sudo(f'mkdir -p {HTTP_HOST_BIN}')
|
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(
|
put_dir(
|
||||||
c,
|
c,
|
||||||
SCRIPTS_DIR / 'http_host',
|
SCRIPTS_DIR / 'http_host' / 'http_host_lib' / 'templates',
|
||||||
HTTP_HOST_BIN,
|
f'{HTTP_HOST_BIN}/http_host_lib/templates',
|
||||||
file_permissions='755',
|
|
||||||
exclude_set={'.gitignore'},
|
|
||||||
)
|
|
||||||
|
|
||||||
put_dir(
|
|
||||||
c,
|
|
||||||
SCRIPTS_DIR / 'http_host' / 'http_host_lib',
|
|
||||||
f'{HTTP_HOST_BIN}/http_host_lib',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
c.sudo('chown -R ofm:ofm /data/ofm/http_host')
|
c.sudo('chown -R ofm:ofm /data/ofm/http_host')
|
||||||
|
|||||||
@@ -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_fonts import download_fonts
|
||||||
from http_host_lib.download_tileset import download_and_extract_tileset
|
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.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
|
from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ def mount():
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
def deploy_tileset_version():
|
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
|
https://assets.openfreemap.com/versions/deployed_planet.txt
|
||||||
|
|
||||||
1. Check if the given version is present on the disk and is mounted
|
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()
|
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()
|
@cli.command()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def sync(ctx):
|
def sync(ctx):
|
||||||
@@ -147,7 +163,10 @@ def sync(ctx):
|
|||||||
|
|
||||||
ctx.invoke(download_assets)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
TEMPLATES_DIR = Path(__file__).parent / 'templates'
|
||||||
|
|
||||||
DEFAULT_RUNS_DIR = Path('/data/ofm/http_host/runs')
|
DEFAULT_RUNS_DIR = Path('/data/ofm/http_host/runs')
|
||||||
DEFAULT_ASSETS_DIR = Path('/data/ofm/http_host/assets')
|
DEFAULT_ASSETS_DIR = Path('/data/ofm/http_host/assets')
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ def deploy_tileset():
|
|||||||
need_nginx_sync = False
|
need_nginx_sync = False
|
||||||
|
|
||||||
for area in ['planet', 'monaco']:
|
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()
|
r.raise_for_status()
|
||||||
remote_version = r.text.strip()
|
remote_version = r.text.strip()
|
||||||
print(f' remote version for {area}: {remote_version}')
|
print(f' remote version for {area}: {remote_version}')
|
||||||
|
|||||||
33
scripts/http_host/nginx_sync/nginx_sync.py → scripts/http_host/http_host_lib/nginx.py
Executable file → Normal file
33
scripts/http_host/nginx_sync/nginx_sync.py → scripts/http_host/http_host_lib/nginx.py
Executable file → Normal file
@@ -1,39 +1,24 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
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')
|
def write_nginx_config():
|
||||||
|
with open(TEMPLATES_DIR / 'nginx_cf.conf') as fp:
|
||||||
|
|
||||||
@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:
|
|
||||||
nginx_template = fp.read()
|
nginx_template = fp.read()
|
||||||
|
|
||||||
location_block_str = ''
|
location_block_str = ''
|
||||||
curl_text = ''
|
curl_text = ''
|
||||||
|
|
||||||
for subdir in Path('/mnt/ofm').iterdir():
|
for subdir in 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('-')
|
||||||
|
|
||||||
run_dir = RUNS_DIR / area / version
|
run_dir = DEFAULT_RUNS_DIR / area / version
|
||||||
if not run_dir.is_dir():
|
if not run_dir.is_dir():
|
||||||
print(f"{run_dir} doesn't exists, skipping")
|
print(f"{run_dir} doesn't exists, skipping")
|
||||||
continue
|
continue
|
||||||
@@ -59,7 +44,7 @@ def cli():
|
|||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO raise expires if everything is stable
|
# TODO raise the expires times once things are stable
|
||||||
version_str = f"""
|
version_str = f"""
|
||||||
location /{area}/{version} {{ # no trailing hash
|
location /{area}/{version} {{ # no trailing hash
|
||||||
alias {tilejson_path}; # 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:
|
with open('/data/nginx/sites/ofm-tiles-org.conf', 'w') as fp:
|
||||||
fp.write(nginx_template)
|
fp.write(nginx_template)
|
||||||
print('nginx config written')
|
print(' nginx config written')
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
print(curl_text)
|
print(curl_text)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
cli()
|
|
||||||
Reference in New Issue
Block a user