Skip to content

Commit bd7f5fa

Browse files
committed
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
1 parent 6fbe9f0 commit bd7f5fa

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

deploy-sync.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
export ENV=prod
4+
5+
./init-server.py http-host-sync ofm-h-fi-1 -y
6+
./init-server.py http-host-sync ofm-h-de-2 -y
7+

init-server.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def loadbalancer(hostname, user, port, noninteractive):
125125
setup_loadbalancer(c)
126126

127127

128+
@cli.command()
129+
@common_options
130+
def http_host_sync(hostname, user, port, noninteractive):
131+
if not noninteractive and not click.confirm(f'Run script on {hostname}?'):
132+
return
133+
134+
c = get_connection(hostname, user, port)
135+
run_http_host_sync(c)
136+
137+
128138
@cli.command()
129139
@common_options
130140
def debug(hostname, user, port, noninteractive):

modules/http_host/http_host_lib/assets.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
from http_host_lib.utils import download_file_aria2, download_if_size_differs
88

99

10-
def download_assets():
10+
def download_assets() -> bool:
1111
"""
1212
Downloads and extracts assets
1313
"""
1414

15-
download_and_extract_asset_tar_gz('fonts')
16-
download_and_extract_asset_tar_gz('styles')
17-
download_and_extract_asset_tar_gz('natural_earth')
15+
changed = False
1816

19-
download_sprites()
17+
changed += download_and_extract_asset_tar_gz('fonts')
18+
changed += download_and_extract_asset_tar_gz('styles')
19+
changed += download_and_extract_asset_tar_gz('natural_earth')
20+
21+
changed += download_sprites()
22+
23+
return changed
2024

2125

2226
def download_and_extract_asset_tar_gz(asset_kind):
2327
"""
2428
Download and extract asset.tgz if the file size differ or not available locally
29+
Returns True if modified
2530
"""
2631

2732
print(f'Downloading asset {asset_kind}')
@@ -33,7 +38,7 @@ def download_and_extract_asset_tar_gz(asset_kind):
3338
local_file = asset_dir / 'ofm.tar.gz'
3439
if not download_if_size_differs(url, local_file):
3540
print(f' skipping asset: {asset_kind}')
36-
return
41+
return False
3742

3843
ofm_dir = asset_dir / 'ofm'
3944
ofm_dir_bak = asset_dir / 'ofm.bak'
@@ -47,9 +52,10 @@ def download_and_extract_asset_tar_gz(asset_kind):
4752
)
4853

4954
print(f' downloaded asset: {asset_kind}')
55+
return True
5056

5157

52-
def download_sprites():
58+
def download_sprites() -> bool:
5359
"""
5460
Sprites are special assets, as we have to keep the old versions indefinitely
5561
"""
@@ -64,6 +70,8 @@ def download_sprites():
6470

6571
sprites_remote = [l for l in r.text.splitlines() if l.startswith('sprites/')]
6672

73+
changed = False
74+
6775
for sprite in sprites_remote:
6876
sprite_name = sprite.split('/')[1].replace('.tar.gz', '')
6977

@@ -81,3 +89,6 @@ def download_sprites():
8189
)
8290
local_file.unlink()
8391
print(f' downloaded sprite version: {sprite_name}')
92+
changed = True
93+
94+
return changed

modules/http_host/http_host_lib/sync.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ def full_sync(force=False):
1919
assert_sudo()
2020

2121
# start
22-
2322
versions_changed = fetch_version_files()
2423

25-
download_assets()
24+
assets_changed = download_assets()
2625

2726
btrfs_downloaded = False
2827

@@ -35,7 +34,7 @@ def full_sync(force=False):
3534
btrfs_downloaded += download_area_version(area='planet', version='latest')
3635
btrfs_downloaded += download_area_version(area='planet', version='deployed')
3736

38-
if btrfs_downloaded or versions_changed or force:
37+
if btrfs_downloaded or versions_changed or assets_changed or force:
3938
auto_clean_btrfs()
4039
auto_mount()
4140

0 commit comments

Comments
 (0)