From 6a0a752e2e2e0cbff1ea70a04dacc5607a434cfc Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 31 Jul 2023 22:10:37 -0600 Subject: [PATCH] Add support for logs command args (#478) --- app/deploy.py | 14 +++++++++----- app/deployment.py | 6 ++++-- tests/deploy/run-deploy-test.sh | 8 ++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/deploy.py b/app/deploy.py index 64b3f11c..075dceea 100644 --- a/app/deploy.py +++ b/app/deploy.py @@ -144,14 +144,16 @@ def exec_operation(ctx, extra_args): print(f"container command returned error exit status") -def logs_operation(ctx, extra_args): +def logs_operation(ctx, tail: int, follow: bool, extra_args: str): global_context = ctx.parent.parent.obj extra_args_list = list(extra_args) or None if not global_context.dry_run: if global_context.verbose: print("Running compose logs") - logs_output = ctx.obj.docker.compose.logs(services=extra_args_list if extra_args_list is not None else []) - print(logs_output) + services_list = extra_args_list if extra_args_list is not None else [] + logs_stream = ctx.obj.docker.compose.logs(services=services_list, tail=tail, follow=follow, stream=True) + for stream_type, stream_content in logs_stream: + print(f"Stream type: {stream_type}, stream content: {stream_content}") @command.command() @@ -192,10 +194,12 @@ def exec(ctx, extra_args): @command.command() +@click.option("--tail", "-n", default=None, help="number of lines to display") +@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output") @click.argument('extra_args', nargs=-1) # help: command: logs @click.pass_context -def logs(ctx, extra_args): - logs_operation(ctx, extra_args) +def logs(ctx, tail, follow, extra_args): + logs_operation(ctx, tail, follow, extra_args) def get_stack_status(ctx, stack): diff --git a/app/deployment.py b/app/deployment.py index 132568ca..39a4ed1c 100644 --- a/app/deployment.py +++ b/app/deployment.py @@ -119,11 +119,13 @@ def exec(ctx, extra_args): @command.command() +@click.option("--tail", "-n", default=None, help="number of lines to display") +@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output") @click.argument('extra_args', nargs=-1) # help: command: logs @click.pass_context -def logs(ctx, extra_args): +def logs(ctx, tail, follow, extra_args): ctx.obj = make_deploy_context(ctx) - logs_operation(ctx, extra_args) + logs_operation(ctx, tail, follow, extra_args) @command.command() diff --git a/tests/deploy/run-deploy-test.sh b/tests/deploy/run-deploy-test.sh index 11b37b2f..0ebb215f 100755 --- a/tests/deploy/run-deploy-test.sh +++ b/tests/deploy/run-deploy-test.sh @@ -109,6 +109,14 @@ fi echo "deploy create output file test: passed" # Try to start the deployment $TEST_TARGET_SO deployment --dir $test_deployment_dir start +# Check logs command works +log_output_2=$( $TEST_TARGET_SO deployment --dir $test_deployment_dir logs ) +if [[ "$log_output_2" == *"Filesystem is fresh"* ]]; then + echo "deployment logs test: passed" +else + echo "deployment logs test: FAILED" + exit 1 +fi # Stop and clean up $TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes echo "Test passed"