From 2fd83eaf55b664e7a92167a91b5b7a0730ca02de Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 10 Aug 2025 12:01:34 +0200 Subject: [PATCH] Keep logs during deploy cleanup --- Makefile | 4 ++++ cli/deploy.py | 16 ++++++++++++---- main.py | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fe5c4fcf..6279a75f 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,10 @@ EXTRA_USERS := $(shell \ .PHONY: build install test +clean-keep-logs: + @echo "🧹 Cleaning ignored files but keeping logs/…" + git clean -fdX -- ':!logs' ':!logs/**' + clean: @echo "Removing ignored git files" git clean -fdX diff --git a/cli/deploy.py b/cli/deploy.py index d177256e..493bbfa7 100644 --- a/cli/deploy.py +++ b/cli/deploy.py @@ -16,14 +16,16 @@ def run_ansible_playbook( skip_tests=False, skip_validation=False, skip_build=False, - cleanup=False + cleanup=False, + logs=False ): start_time = datetime.datetime.now() print(f"\n▶️ Script started at: {start_time.isoformat()}\n") if cleanup: - print("\n🧹 Cleaning up project (make clean)...\n") - subprocess.run(["make", "clean"], check=True) + cleanup_command = ["make", "clean-keep-logs"] if logs else ["make", "clean"] + print("\n🧹 Cleaning up project (" + " ".join(cleanup_command) +")...\n") + subprocess.run(cleanup_command, check=True) else: print("\n⚠️ Skipping build as requested.\n") @@ -180,6 +182,10 @@ def main(): "-v", "--verbose", action="count", default=0, help="Increase verbosity level. Multiple -v flags increase detail (e.g., -vvv for maximum log output)." ) + parser.add_argument( + "--logs", action="store_true", + help="Keep the CLI logs during cleanup command" + ) args = parser.parse_args() validate_application_ids(args.inventory, args.id) @@ -190,6 +196,7 @@ def main(): "mode_update": args.update, "mode_backup": args.backup, "mode_cleanup": args.cleanup, + "mode_logs": args.logs, "enable_debug": args.debug, "host_type": args.host_type } @@ -204,7 +211,8 @@ def main(): skip_tests=args.skip_tests, skip_validation=args.skip_validation, skip_build=args.skip_build, - cleanup=args.cleanup + cleanup=args.cleanup, + logs=args.logs ) diff --git a/main.py b/main.py index c38b2980..0da55b7a 100755 --- a/main.py +++ b/main.py @@ -123,7 +123,10 @@ if __name__ == "__main__": # Parse flags sound_enabled = '--sound' in sys.argv and (sys.argv.remove('--sound') or True) no_signal = '--no-signal' in sys.argv and (sys.argv.remove('--no-signal') or True) - log_enabled = '--log' in sys.argv and (sys.argv.remove('--log') or True) + # Guaranty that --log is passed to deploy command + log_enabled = '--log' in sys.argv + if log_enabled and (len(sys.argv) < 2 or sys.argv[1] != 'deploy'): + sys.argv.remove('--log') git_clean = '--git-clean' in sys.argv and (sys.argv.remove('--git-clean') or True) infinite = '--infinite' in sys.argv and (sys.argv.remove('--infinite') or True) alarm_timeout = 60