forked from moritz/alakazam
add --chaos flag to cmd
This commit is contained in:
14
alakazam.py
14
alakazam.py
@ -737,7 +737,7 @@ def replace_domains(path: Path, old_domain: str, new_domain: str) -> None:
|
||||
file.write(content)
|
||||
|
||||
|
||||
def execute_cmds(app_config: Dict[str, Any], commands: Tuple[str] = tuple(), initial: bool = False, deploy: bool = False, upgrade: bool = False, dry_run: bool = False) -> None:
|
||||
def execute_cmds(app_config: Dict[str, Any], commands: Tuple[str] = tuple(), initial: bool = False, deploy: bool = False, upgrade: bool = False, dry_run: bool = False, chaos: bool = False) -> None:
|
||||
"""
|
||||
Execute post-deployment commands for an application based on the provided configuration.
|
||||
This can include running scripts or commands inside the application's environment.
|
||||
@ -764,6 +764,9 @@ def execute_cmds(app_config: Dict[str, Any], commands: Tuple[str] = tuple(), ini
|
||||
all_cmds = all_cmds + upgrade_hooks
|
||||
if commands:
|
||||
all_cmds = all_cmds + list(commands)
|
||||
chaos_flag = ""
|
||||
if chaos:
|
||||
chaos_flag = "-C"
|
||||
for cmd in all_cmds:
|
||||
container = cmd.split()[0]
|
||||
cmd = cmd.split()[1:]
|
||||
@ -771,9 +774,9 @@ def execute_cmds(app_config: Dict[str, Any], commands: Tuple[str] = tuple(), ini
|
||||
if dry_run:
|
||||
continue
|
||||
if container == "local":
|
||||
print(abra("app", "cmd", "--local", domain, *cmd, ignore_error=True))
|
||||
print(abra("app", "cmd", "--local", chaos_flag, domain, *cmd, ignore_error=True))
|
||||
else:
|
||||
print(abra("app", "cmd", domain, container, *cmd, ignore_error=True))
|
||||
print(abra("app", "cmd", chaos_flag, domain, container, *cmd, ignore_error=True))
|
||||
|
||||
|
||||
@click.group(context_settings={"help_option_names": ['-h', '--help']})
|
||||
@ -1039,7 +1042,8 @@ def undeploy(recipes: Tuple[str]) -> None:
|
||||
@click.option('-d', '--deploy', is_flag=True, help='execute deploy-hooks from config')
|
||||
@click.option('-u', '--upgrade', is_flag=True, help='execute upgrade-hooks from config')
|
||||
@click.option('-l', '--list-cmds', is_flag=True, help="only show cmds, don't execute them")
|
||||
def cmd(recipes: Tuple[str], commands: Tuple[str], initial: bool, deploy: bool, upgrade: bool, list_cmds: bool = False) -> None:
|
||||
@click.option('-C', '--chaos', is_flag=True, help="execute in chaos mode")
|
||||
def cmd(recipes: Tuple[str], commands: Tuple[str], initial: bool, deploy: bool, upgrade: bool, list_cmds: bool = False, chaos: bool = False) -> None:
|
||||
"""
|
||||
Execute commands for all specified applications based on the provided configuration.
|
||||
"""
|
||||
@ -1056,7 +1060,7 @@ def cmd(recipes: Tuple[str], commands: Tuple[str], initial: bool, deploy: bool,
|
||||
print(f"{domain} is not deployed")
|
||||
continue
|
||||
logging.info(f'execute commands for {domain}')
|
||||
execute_cmds(app_config, commands, initial, deploy, upgrade, list_cmds)
|
||||
execute_cmds(app_config, commands, initial, deploy, upgrade, list_cmds, chaos)
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
||||
Reference in New Issue
Block a user