mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
setversion, http_host
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import click
|
import click
|
||||||
from fabric import Config, Connection
|
from fabric import Config, Connection
|
||||||
|
|
||||||
from ssh_lib import SCRIPTS_DIR, TILE_GEN_BIN, dotenv_val
|
from ssh_lib import SCRIPTS_DIR, dotenv_val
|
||||||
from ssh_lib.tasks import (
|
from ssh_lib.tasks import (
|
||||||
prepare_http_host,
|
prepare_http_host,
|
||||||
prepare_shared,
|
prepare_shared,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ pip install -U pip wheel setuptools
|
|||||||
pip install -e .
|
pip install -e .
|
||||||
pip install -e scripts/http_host
|
pip install -e scripts/http_host
|
||||||
pip install -e scripts/tile_gen
|
pip install -e scripts/tile_gen
|
||||||
|
pip install -e scripts/loadbalancer
|
||||||
|
pip install -e scripts/setversion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,5 +198,5 @@ def sync(ctx):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(HOST_CONFIG)
|
# print(HOST_CONFIG)
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ def write_nginx_config():
|
|||||||
domain_le = HOST_CONFIG['domain_le']
|
domain_le = HOST_CONFIG['domain_le']
|
||||||
domain_ledns = HOST_CONFIG['domain_ledns']
|
domain_ledns = HOST_CONFIG['domain_ledns']
|
||||||
|
|
||||||
|
# remove old configs and certs
|
||||||
|
for file in Path('/data/nginx/sites').glob('ofm_*.conf'):
|
||||||
|
file.unlink()
|
||||||
|
|
||||||
|
for file in Path('/data/nginx/certs').glob('ofm_*'):
|
||||||
|
file.unlink()
|
||||||
|
|
||||||
# processing Round Robin DNS config
|
# processing Round Robin DNS config
|
||||||
if domain_ledns:
|
if domain_ledns:
|
||||||
if not (OFM_CONFIG_DIR / 'rclone.conf').is_file():
|
if not (OFM_CONFIG_DIR / 'rclone.conf').is_file():
|
||||||
|
|||||||
17
scripts/setversion/setup.py
Normal file
17
scripts/setversion/setup.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
|
||||||
|
requirements = [
|
||||||
|
'click',
|
||||||
|
'requests',
|
||||||
|
'pycurl',
|
||||||
|
'python-dotenv',
|
||||||
|
'questionary',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
python_requires='>=3.10',
|
||||||
|
install_requires=requirements,
|
||||||
|
packages=find_packages(),
|
||||||
|
)
|
||||||
62
scripts/setversion/setversion.py
Executable file
62
scripts/setversion/setversion.py
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import click
|
||||||
|
import questionary
|
||||||
|
from setversion_lib import RCLONE_BIN, RCLONE_CONF
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def cli():
|
||||||
|
"""
|
||||||
|
Sets deployed reference versions
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument('area', required=True)
|
||||||
|
def interactive(area):
|
||||||
|
versions = get_available_versions(area)[::-1]
|
||||||
|
|
||||||
|
choices = [questionary.Choice(title=r, value=i) for i, r in enumerate(versions)]
|
||||||
|
answer = questionary.select(f'Select version for: {area}', choices=choices).ask()
|
||||||
|
|
||||||
|
selected = versions[answer]
|
||||||
|
|
||||||
|
set_version(area, selected)
|
||||||
|
|
||||||
|
|
||||||
|
def get_available_versions(area):
|
||||||
|
p = subprocess.run(
|
||||||
|
[
|
||||||
|
RCLONE_BIN,
|
||||||
|
'cat',
|
||||||
|
f'remote:ofm-{area}/dirs.txt',
|
||||||
|
],
|
||||||
|
env=dict(RCLONE_CONFIG=RCLONE_CONF),
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
versions = [l.strip() for l in p.stdout.strip().splitlines()]
|
||||||
|
versions.sort()
|
||||||
|
|
||||||
|
return versions
|
||||||
|
|
||||||
|
|
||||||
|
def set_version(area, version):
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
RCLONE_BIN,
|
||||||
|
'rcat',
|
||||||
|
f'remote:ofm-assets/versions/deployed_{area}.txt',
|
||||||
|
],
|
||||||
|
env=dict(RCLONE_CONFIG=RCLONE_CONF),
|
||||||
|
check=True,
|
||||||
|
input=version.encode(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cli()
|
||||||
16
scripts/setversion/setversion_lib/__init__.py
Normal file
16
scripts/setversion/setversion_lib/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
if Path('/data/ofm/config').exists():
|
||||||
|
OFM_CONFIG_DIR = Path('/data/ofm/config')
|
||||||
|
else:
|
||||||
|
OFM_CONFIG_DIR = Path(__file__).parent.parent.parent.parent / 'config'
|
||||||
|
|
||||||
|
assert OFM_CONFIG_DIR.exists()
|
||||||
|
|
||||||
|
RCLONE_CONF = OFM_CONFIG_DIR / 'rclone.conf'
|
||||||
|
|
||||||
|
if Path('/opt/homebrew/bin/rclone').exists():
|
||||||
|
RCLONE_BIN = '/opt/homebrew/bin/rclone'
|
||||||
|
else:
|
||||||
|
RCLONE_BIN = 'rclone'
|
||||||
@@ -155,43 +155,5 @@ def index():
|
|||||||
make_indexes()
|
make_indexes()
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
def set_latest_versions():
|
|
||||||
"""
|
|
||||||
Sets the latest version as the deployed one
|
|
||||||
"""
|
|
||||||
|
|
||||||
for area in AREAS:
|
|
||||||
print(f'setting latest version for {area}')
|
|
||||||
|
|
||||||
p = subprocess.run(
|
|
||||||
[
|
|
||||||
'rclone',
|
|
||||||
'cat',
|
|
||||||
f'remote:ofm-{area}/dirs.txt',
|
|
||||||
],
|
|
||||||
env=dict(RCLONE_CONFIG='/data/ofm/config/rclone.conf'),
|
|
||||||
check=True,
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
versions = [l.strip() for l in p.stdout.strip().splitlines()]
|
|
||||||
versions.sort(reverse=True)
|
|
||||||
|
|
||||||
latest_version = versions[0]
|
|
||||||
print(latest_version)
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
[
|
|
||||||
'rclone',
|
|
||||||
'rcat',
|
|
||||||
f'remote:ofm-assets/versions/deployed_{area}.txt',
|
|
||||||
],
|
|
||||||
env=dict(RCLONE_CONFIG='/data/ofm/config/rclone.conf'),
|
|
||||||
check=True,
|
|
||||||
input=latest_version.encode(),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user