chore: extract service creator class
Deploy bin / deploy (push) Successful in 3s
Deploy service MASTER / deploy (push) Failing after 2s

This commit is contained in:
Benjamin Labrecque
2026-07-06 11:56:52 +02:00
parent 955b71f61b
commit 9c4f0a535d
8 changed files with 79 additions and 97 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
- name: Auto-provision new service pipeline
hosts: localhost
hosts: sls-lc
gather_facts: false
#TODO: docs?
+27 -3
View File
@@ -1,16 +1,19 @@
import re
from pathlib import Path
from typing import ClassVar
import yaml
from pydantic import BaseModel, field_validator
from core.enums import ServiceStatus
from core.utils import get_git_root
HERE_DIR = Path(__file__).parent
CONFIG_DIR = HERE_DIR / ".." / ".." / ".." / "config"
REPO_ROOT = get_git_root(__file__)
CONFIG_DIR = REPO_ROOT / "config"
SERVICE_REGISTRY_FILENAME = CONFIG_DIR / "services_registry.yml"
MASTER_SERVICE_DIR = REPO_ROOT / "services" / "000-master"
MASTER_SERVICE_CONFIG_DIR = MASTER_SERVICE_DIR / "app" / "config"
class Service(BaseModel):
id: int
@@ -75,3 +78,24 @@ class ServiceRegistry(BaseModel):
def write_to_config(self) -> None:
with open(self.config_path, "w") as f:
yaml.safe_dump(self.model_dump(), f)
class MasterHLANames(BaseModel):
config_path: ClassVar[str] = str(MASTER_SERVICE_CONFIG_DIR)
hla_apps: list[str]
@classmethod
def read_from_config(cls) -> "MasterHLANames":
with open(cls.config_path) as f:
d = yaml.safe_load(f)
hla_names = MasterHLANames.model_validate(d)
return hla_names
def add_hla_name(self, name: str):
self.hla_apps.append(name)
def write_to_config(self) -> None:
with open(self.config_path, "w") as f:
yaml.safe_dump(self.model_dump(), f)
-33
View File
@@ -1,33 +0,0 @@
import copier
from core.utils import get_git_root
REPO_ROOT = get_git_root(__file__)
SERVICE_TEMPLATES_DIR = REPO_ROOT / "templates" / "service"
SERVICE_DEST_DIR = REPO_ROOT / "services"
def render_new_service_templates(
service_id: str,
service_name_upper: str,
service_name_lower: str,
ioc_host: str,
ioc_port: int,
user: str,
):
"""
Render template files for a new service
"""
copier.run_copy(
src_path=str(SERVICE_TEMPLATES_DIR),
dst_path=str(SERVICE_DEST_DIR),
data={
"service_id": service_id,
"service_name_upper": service_name_upper,
"service_name_lower": service_name_lower,
# TODO: restrict this, use enum
"ioc_host": ioc_host,
"ioc_port": ioc_port,
"user": user,
},
)
+4 -29
View File
@@ -1,9 +1,7 @@
import git
import typer
from core.git import assert_clean_repo, git_push_changes, switch_branch
from core.models import ServiceRegistry
from core.render_templates import render_new_service_templates
from core.service_creator import ServiceCreator
from core.utils import get_git_root, init_logging
service = typer.Typer(no_args_is_help=True)
@@ -16,35 +14,12 @@ def add(
name: str = typer.Option(..., "--name", "-n"),
):
init_logging()
registry = ServiceRegistry.read_from_config()
service = registry.add_service(name)
repo = git.Repo(REPO_ROOT)
assert_clean_repo(repo)
original_branch = repo.active_branch.name
branch_name = f"feature/add-service-{service.name_lower}"
switch_branch(repo, branch_name)
render_new_service_templates(
service_id=service.id_str,
service_name_upper=service.name_upper,
service_name_lower=service.name_lower,
# TODO: Maybe create a GitPusher context manager
ServiceCreator(
ioc_host="ex-host", # TODO
ioc_port=9999, # TODO
user="user", # TODO
)
registry.write_to_config()
git_push_changes(
repo=repo,
branch_name=f"feature/add-service-{service.name_lower}",
service_dir_rel_path=f"services/{service.dir_name}",
registry_file_rel_path="config/services_registry.yml",
commit_msg=f"feature: add new service {service.name_lower}",
)
switch_branch(repo, original_branch)
).add_service(name=name)
@service.command()
+16
View File
@@ -33,3 +33,19 @@ Result: on ioc host, e.g. `sls-vserv-bd-01-dev`
```shell
vim /etc/shellbox/<port-number>
```
## Check PVs of installed IOC
```shell
ioc shell AGEBD-CPCL-MASTER-DEV
```
```shell
> dbl
```
Exit:
```shell
Ctrl + d
```
@@ -1,6 +1,6 @@
cpu_architecture: x86_64
epics_version: 7.0.8
ioc_host: sls-vserv-bd-01-dev
ioc_port: 50000
ioc_port: 50011
os: RHEL8
os_id: rhel
@@ -1,33 +1,33 @@
file MASTER.template {
pattern { SUFFIX SERVICE STARTON AUTOOFF }
{ "-DEV", "MASTER" , "0", "30" }
{ "-DEV", "NTURNS" , "0", "0" }
{ "-DEV", "DBPM3CURR" , "1", "0" }
{ "-DEV", "TAUBPM" , "1", "0" }
{ "-DEV", "TAUPCT" , "1", "0" }
{ "-DEV", "SCRUBBING" , "1", "0" }
{ "-DEV", "TIMING" , "0", "0" }
{ "-DEV", "TUNE" , "1", "0" }
{ "-DEV", "INJECTIONGUARD" , "1", "0" }
{ "-DEV", "POSTMORTEMLOG" , "1", "0" }
{ "-DEV", "TUNEBUMP" , "1", "0" }
{ "-DEV", "PLOTS" , "0", "0" }
{ "-DEV", "ORBITBUMP" , "0", "0" }
{ "-DEV", "TOPUPTOOL" , "0", "0" }
{ "-DEV", "SHIFTTOOL" , "1", "0" }
{ "-DEV", "BEAMTRANSFERCHECKS" , "0", "0" }
{ "-DEV", "TUNEFBX" , "0", "0" }
{ "-DEV", "TUNEFBY" , "0", "0" }
{ "-DEV", "OPTICSFF-X02S" , "0", "0" } # I-TOMCAT
{ "-DEV", "OPTICSFF-X03M" , "0", "0" } # ADRESS
{ "-DEV", "OPTICSFF-X04S" , "0", "0" } # ADDAMS
{ "-DEV", "OPTICSFF-X05L" , "0", "0" } # QUEST
{ "-DEV", "OPTICSFF-X06S" , "0", "0" } # PXI
{ "-DEV", "OPTICSFF-X07M" , "0", "0" } # PHOENIX/XTREME
{ "-DEV", "OPTICSFF-X08S" , "0", "0" } # MicroXAS
{ "-DEV", "OPTICSFF-X09L" , "0", "0" } # OPERA
{ "-DEV", "OPTICSFF-X10S" , "0", "0" } # PXII
{ "-DEV", "OPTICSFF-X11M" , "0", "0" } # SIM
{ "-DEV", "OPTICSFF-X12S" , "0", "0" } # cSAXS
{ "", "MASTER" , "0", "30" }
{ "", "NTURNS" , "0", "0" }
{ "", "DBPM3CURR" , "1", "0" }
{ "", "TAUBPM" , "1", "0" }
{ "", "TAUPCT" , "1", "0" }
{ "", "SCRUBBING" , "1", "0" }
{ "", "TIMING" , "0", "0" }
{ "", "TUNE" , "1", "0" }
{ "", "INJECTIONGUARD" , "1", "0" }
{ "", "POSTMORTEMLOG" , "1", "0" }
{ "", "TUNEBUMP" , "1", "0" }
{ "", "PLOTS" , "0", "0" }
{ "", "ORBITBUMP" , "0", "0" }
{ "", "TOPUPTOOL" , "0", "0" }
{ "", "SHIFTTOOL" , "1", "0" }
{ "", "BEAMTRANSFERCHECKS" , "0", "0" }
{ "", "TUNEFBX" , "0", "0" }
{ "", "TUNEFBY" , "0", "0" }
{ "", "OPTICSFF-X02S" , "0", "0" } # I-TOMCAT
{ "", "OPTICSFF-X03M" , "0", "0" } # ADRESS
{ "", "OPTICSFF-X04S" , "0", "0" } # ADDAMS
{ "", "OPTICSFF-X05L" , "0", "0" } # QUEST
{ "", "OPTICSFF-X06S" , "0", "0" } # PXI
{ "", "OPTICSFF-X07M" , "0", "0" } # PHOENIX/XTREME
{ "", "OPTICSFF-X08S" , "0", "0" } # MicroXAS
{ "", "OPTICSFF-X09L" , "0", "0" } # OPERA
{ "", "OPTICSFF-X10S" , "0", "0" } # PXII
{ "", "OPTICSFF-X11M" , "0", "0" } # SIM
{ "", "OPTICSFF-X12S" , "0", "0" } # cSAXS
}
@@ -1,6 +1,6 @@
cpu_architecture: x86_64
epics_version: 7.0.8
ioc_host: sls-vserv-bd-01-dev
ioc_port: 50000
ioc_port: 50011
os: RHEL8
os_id: rhel