cli: undo actions on exception
Deploy bin / deploy (push) Successful in 5s
Deploy, build and restart MASTER / deploy (push) Successful in 3s
Deploy agebd python package / deploy (push) Successful in 2s

This commit is contained in:
Benjamin Labrecque
2026-07-07 11:37:11 +02:00
parent 71e61f75a3
commit 989eab8ab2
+21 -19
View File
@@ -1,3 +1,6 @@
import shutil
from pathlib import Path
import copier
import git
@@ -32,14 +35,19 @@ class ServiceCreator:
assert_clean_repo(repo)
original_branch = repo.active_branch.name
# Keep old configs to revert in case of Exception
hla_names_old = MasterHLANames.read_from_config()
hla_names = MasterHLANames.read_from_config()
hla_names.add_hla_name(name)
registry_old = ServiceRegistry.read_from_config()
registry = ServiceRegistry.read_from_config()
service = registry.add_service(name)
branch_name = f"feature/add-service-{service.name_lower}"
delete_local_branch(repo, branch_name)
switch_branch(repo, branch_name)
try:
registry = ServiceRegistry.read_from_config()
service = registry.add_service(name)
branch_name = f"feature/add-service-{service.name_lower}"
delete_local_branch(repo, branch_name)
switch_branch(repo, branch_name)
self._render_new_service_templates(
service=service,
ioc_host=self.ioc_host,
@@ -47,21 +55,23 @@ class ServiceCreator:
user=self.user,
)
registry.write_to_config()
self._update_master_hla_names(name=service.name_upper)
hla_names.write_to_config()
# TODO: can't push if branch already exists in remote
service_dir_rel_path = f"services/{service.dir_name}/current"
git_push_changes(
repo=repo,
branch_name=branch_name,
service_dir_rel_path=service_dir_rel_path,
service_dir_rel_path=f"services/{service.dir_name}/current",
registry_file_rel_path="config/services_registry.yml",
# TODO: maybe assert/get correct master service dirname from registry
master_hla_names_rel_path=f"{service_dir_rel_path}/app/config/hla_names.yml",
master_hla_names_rel_path="services/000-master/current/app/config/hla_names.yml",
commit_msg=f"feature: add new service {service.name_lower}",
)
switch_branch(repo, original_branch)
except Exception as e:
shutil.rmtree(Path(SERVICE_DEST_DIR / service.dir_name), ignore_errors=True)
registry_old.write_to_config()
hla_names_old.write_to_config()
switch_branch(repo, original_branch)
raise e
@@ -88,11 +98,3 @@ class ServiceCreator:
"user": user,
},
)
def _update_master_hla_names(self, name: str):
"""
Add new HLA name to MASTER so it can monitor it
"""
hla_names = MasterHLANames.read_from_config()
hla_names.add_hla_name(name)
hla_names.write_to_config()