diff --git a/gitops/core.py b/gitops/core.py index cea02b7..0677036 100644 --- a/gitops/core.py +++ b/gitops/core.py @@ -134,6 +134,54 @@ def bump( # noqa: C901 print(success("Done!")) +@task +def redeploy( + ctx: Any, + filter: str, + exclude: str = "", + autoexclude_inactive: bool = True, + interactive: bool = True, + push: bool = False, + skip_migrations: bool = False, +) -> None: + """Force redeploy selected app(s) without changing their image tag. + Updates a UUID bump field to trigger a new deployment. + Provide `push` to automatically push the commit (and retry on conflict.) + Provide `skip_migrations` to disable running migrations via helm hooks. + """ + try: + apps = get_apps( + filter=filter, + exclude=exclude, + autoexclude_inactive=autoexclude_inactive, + message=f"{colourise('The following apps will be redeployed:', Fore.LIGHTBLUE_EX)}", + load_secrets=False, + mode="PROMPT" if interactive else "SILENT", + ) + except AppOperationAborted: + print(success_negative("Aborted.")) + return + + if push: + run(f"cd {get_apps_directory()}; git pull") + + for app in apps: + print(f"Redeploying {colourise(app.name, Fore.LIGHTGREEN_EX)}") + update_app(app.name, **{"bump": str(uuid.uuid4())}) + + commit_message = f"Redeploying {filter}" + if exclude: + commit_message += f" (except {exclude})" + if skip_migrations: + commit_message += " --skip-migrations" + run(f'cd {get_apps_directory()}; git commit -am "{commit_message}."') + + if push: + git_push(get_apps_directory()) + + print(success("Done!")) + + @task def command( ctx: Any,