Skip to content

Commit

Permalink
feat(deploy): add deploy-sync script for production environment setup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyperknot committed Oct 28, 2024
1 parent 6fbe9f0 commit bd7f5fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
7 changes: 7 additions & 0 deletions deploy-sync.sh
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions init-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 18 additions & 7 deletions modules/http_host/http_host_lib/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
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}')
Expand All @@ -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'
Expand All @@ -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
"""
Expand All @@ -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', '')

Expand All @@ -81,3 +89,6 @@ def download_sprites():
)
local_file.unlink()
print(f' downloaded sprite version: {sprite_name}')
changed = True

return changed
5 changes: 2 additions & 3 deletions modules/http_host/http_host_lib/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down

0 comments on commit bd7f5fa

Please sign in to comment.