Add support for logs command args (#478)
This commit is contained in:
		
							parent
							
								
									5afe7a29ae
								
							
						
					
					
						commit
						6a0a752e2e
					
				| @ -144,14 +144,16 @@ def exec_operation(ctx, extra_args): | |||||||
|             print(f"container command returned error exit status") |             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 |     global_context = ctx.parent.parent.obj | ||||||
|     extra_args_list = list(extra_args) or None |     extra_args_list = list(extra_args) or None | ||||||
|     if not global_context.dry_run: |     if not global_context.dry_run: | ||||||
|         if global_context.verbose: |         if global_context.verbose: | ||||||
|             print("Running compose logs") |             print("Running compose logs") | ||||||
|         logs_output = ctx.obj.docker.compose.logs(services=extra_args_list if extra_args_list is not None else []) |         services_list = extra_args_list if extra_args_list is not None else [] | ||||||
|         print(logs_output) |         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() | @command.command() | ||||||
| @ -192,10 +194,12 @@ def exec(ctx, extra_args): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @command.command() | @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 <service1> <service2> | @click.argument('extra_args', nargs=-1)  # help: command: logs <service1> <service2> | ||||||
| @click.pass_context | @click.pass_context | ||||||
| def logs(ctx, extra_args): | def logs(ctx, tail, follow, extra_args): | ||||||
|     logs_operation(ctx, extra_args) |     logs_operation(ctx, tail, follow, extra_args) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def get_stack_status(ctx, stack): | def get_stack_status(ctx, stack): | ||||||
|  | |||||||
| @ -119,11 +119,13 @@ def exec(ctx, extra_args): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @command.command() | @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 <service1> <service2> | @click.argument('extra_args', nargs=-1)  # help: command: logs <service1> <service2> | ||||||
| @click.pass_context | @click.pass_context | ||||||
| def logs(ctx, extra_args): | def logs(ctx, tail, follow, extra_args): | ||||||
|     ctx.obj = make_deploy_context(ctx) |     ctx.obj = make_deploy_context(ctx) | ||||||
|     logs_operation(ctx, extra_args) |     logs_operation(ctx, tail, follow, extra_args) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @command.command() | @command.command() | ||||||
|  | |||||||
| @ -109,6 +109,14 @@ fi | |||||||
| echo "deploy create output file test: passed" | echo "deploy create output file test: passed" | ||||||
| # Try to start the deployment | # Try to start the deployment | ||||||
| $TEST_TARGET_SO deployment --dir $test_deployment_dir start | $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 | # Stop and clean up | ||||||
| $TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes | $TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes | ||||||
| echo "Test passed" | echo "Test passed" | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user