mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
feat(deploy): add deploy-sync script for production environment setup
feat(init-server.py): implement http_host_sync command for server initialization refactor(http_host_lib): enhance asset downloading functions to return status of changes made
This commit is contained in:
7
deploy-sync.sh
Executable file
7
deploy-sync.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export ENV=prod
|
||||
|
||||
./init-server.py http-host-sync ofm-h-fi-1 -y
|
||||
./init-server.py http-host-sync ofm-h-de-2 -y
|
||||
|
||||
@@ -125,6 +125,16 @@ def loadbalancer(hostname, user, port, noninteractive):
|
||||
setup_loadbalancer(c)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@common_options
|
||||
def http_host_sync(hostname, user, port, noninteractive):
|
||||
if not noninteractive and not click.confirm(f'Run script on {hostname}?'):
|
||||
return
|
||||
|
||||
c = get_connection(hostname, user, port)
|
||||
run_http_host_sync(c)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@common_options
|
||||
def debug(hostname, user, port, noninteractive):
|
||||
|
||||
@@ -7,21 +7,26 @@ from http_host_lib.config import config
|
||||
from http_host_lib.utils import download_file_aria2, download_if_size_differs
|
||||
|
||||
|
||||
def download_assets():
|
||||
def download_assets() -> bool:
|
||||
"""
|
||||
Downloads and extracts assets
|
||||
"""
|
||||
|
||||
download_and_extract_asset_tar_gz('fonts')
|
||||
download_and_extract_asset_tar_gz('styles')
|
||||
download_and_extract_asset_tar_gz('natural_earth')
|
||||
changed = False
|
||||
|
||||
download_sprites()
|
||||
changed += download_and_extract_asset_tar_gz('fonts')
|
||||
changed += download_and_extract_asset_tar_gz('styles')
|
||||
changed += download_and_extract_asset_tar_gz('natural_earth')
|
||||
|
||||
changed += download_sprites()
|
||||
|
||||
return changed
|
||||
|
||||
|
||||
def download_and_extract_asset_tar_gz(asset_kind):
|
||||
"""
|
||||
Download and extract asset.tgz if the file size differ or not available locally
|
||||
Returns True if modified
|
||||
"""
|
||||
|
||||
print(f'Downloading asset {asset_kind}')
|
||||
@@ -33,7 +38,7 @@ def download_and_extract_asset_tar_gz(asset_kind):
|
||||
local_file = asset_dir / 'ofm.tar.gz'
|
||||
if not download_if_size_differs(url, local_file):
|
||||
print(f' skipping asset: {asset_kind}')
|
||||
return
|
||||
return False
|
||||
|
||||
ofm_dir = asset_dir / 'ofm'
|
||||
ofm_dir_bak = asset_dir / 'ofm.bak'
|
||||
@@ -47,9 +52,10 @@ def download_and_extract_asset_tar_gz(asset_kind):
|
||||
)
|
||||
|
||||
print(f' downloaded asset: {asset_kind}')
|
||||
return True
|
||||
|
||||
|
||||
def download_sprites():
|
||||
def download_sprites() -> bool:
|
||||
"""
|
||||
Sprites are special assets, as we have to keep the old versions indefinitely
|
||||
"""
|
||||
@@ -64,6 +70,8 @@ def download_sprites():
|
||||
|
||||
sprites_remote = [l for l in r.text.splitlines() if l.startswith('sprites/')]
|
||||
|
||||
changed = False
|
||||
|
||||
for sprite in sprites_remote:
|
||||
sprite_name = sprite.split('/')[1].replace('.tar.gz', '')
|
||||
|
||||
@@ -81,3 +89,6 @@ def download_sprites():
|
||||
)
|
||||
local_file.unlink()
|
||||
print(f' downloaded sprite version: {sprite_name}')
|
||||
changed = True
|
||||
|
||||
return changed
|
||||
|
||||
@@ -19,10 +19,9 @@ def full_sync(force=False):
|
||||
assert_sudo()
|
||||
|
||||
# start
|
||||
|
||||
versions_changed = fetch_version_files()
|
||||
|
||||
download_assets()
|
||||
assets_changed = download_assets()
|
||||
|
||||
btrfs_downloaded = False
|
||||
|
||||
@@ -35,7 +34,7 @@ def full_sync(force=False):
|
||||
btrfs_downloaded += download_area_version(area='planet', version='latest')
|
||||
btrfs_downloaded += download_area_version(area='planet', version='deployed')
|
||||
|
||||
if btrfs_downloaded or versions_changed or force:
|
||||
if btrfs_downloaded or versions_changed or assets_changed or force:
|
||||
auto_clean_btrfs()
|
||||
auto_mount()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user