56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import sys
|
|
|
|
import ansible_runner
|
|
import typer
|
|
|
|
from core.ansible import run_playbook
|
|
from core.utils import get_git_root
|
|
|
|
ioc = typer.Typer(no_args_is_help=True)
|
|
|
|
REPO_ROOT = get_git_root(__file__)
|
|
|
|
ANSIBLE_PLAYBOOKS_DIR = REPO_ROOT / "ansible" / "playbooks"
|
|
IOC_PLAYBOOK_INSTALL = ANSIBLE_PLAYBOOKS_DIR / "ioc-install.yml"
|
|
IOC_PLAYBOOK_RESTART = ANSIBLE_PLAYBOOKS_DIR / "ioc-restart.yml"
|
|
IOC_PLAYBOOK_START = ANSIBLE_PLAYBOOKS_DIR / "ioc-start.yml"
|
|
|
|
|
|
@ioc.command(no_args_is_help=True)
|
|
def install(
|
|
env: str = typer.Option(..., "--env"),
|
|
service_name_lower: str = typer.Option(..., "--service-name", "-s"),
|
|
branch_name: str | None = typer.Option(None, "--branch-name", "-b"),
|
|
):
|
|
env_var = f"agebd_env={env}"
|
|
if branch_name is None:
|
|
branch_name = f"feature/add-service-{service_name_lower}"
|
|
branch_var = f"branch_name={branch_name}"
|
|
service_name_var = f"service_name_lower={service_name_lower}"
|
|
|
|
run_playbook(playbook=str(IOC_PLAYBOOK_INSTALL), vars=[env_var, branch_var, service_name_var])
|
|
|
|
|
|
@ioc.command(no_args_is_help=True)
|
|
def restart(
|
|
env: str = typer.Option(..., "--env"),
|
|
service_name_lower: str = typer.Option(..., "--service-name", "-s"),
|
|
branch_name: str | None = typer.Option(None, "--branch-name", "-b"),
|
|
):
|
|
env_var = f"agebd_env={env}"
|
|
if branch_name is None:
|
|
branch_name = f"feature/add-service-{service_name_lower}"
|
|
branch_var = f"branch_name={branch_name}"
|
|
service_name_var = f"service_name_lower={service_name_lower}"
|
|
|
|
run_playbook(playbook=str(IOC_PLAYBOOK_RESTART), vars=[env_var, branch_var, service_name_var])
|
|
|
|
|
|
@ioc.command(no_args_is_help=True)
|
|
def start(
|
|
ioc_port: int = typer.Option(..., "--port", "-p"),
|
|
):
|
|
ioc_port_var = f"ioc_port={ioc_port}"
|
|
|
|
run_playbook(playbook=str(IOC_PLAYBOOK_START), vars=[ioc_port_var])
|