Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to pass service name to invoke cli #53

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/53.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the ability to pass service name to `invoke cli`
14 changes: 7 additions & 7 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def docker_compose(context, command, **kwargs):
return context.run(compose_command, env=build_env, **kwargs)


def run_command(context, command, **kwargs):
def run_command(context, command, service="nautobot", **kwargs):
"""Wrapper to run a command locally or inside the nautobot container."""
if is_truthy(context.nautobot_dev_example.local):
if "command_env" in kwargs:
Expand All @@ -159,7 +159,7 @@ def run_command(context, command, **kwargs):
}
return context.run(command, **kwargs)
else:
# Check if nautobot is running, no need to start another nautobot container to run a command
# Check if service is running, no need to start another container to run a command
docker_compose_status = "ps --services --filter status=running"
results = docker_compose(context, docker_compose_status, hide="out")

Expand All @@ -169,10 +169,10 @@ def run_command(context, command, **kwargs):
for key, value in command_env.items():
command_env_args += f' --env="{key}={value}"'

if "nautobot" in results.stdout:
compose_command = f"exec{command_env_args} nautobot {command}"
if service in results.stdout:
compose_command = f"exec{command_env_args} {service} {command}"
else:
compose_command = f"run{command_env_args} --rm --entrypoint='{command}' nautobot"
compose_command = f"run{command_env_args} --rm --entrypoint='{command}' {service}"

pty = kwargs.pop("pty", True)

Expand Down Expand Up @@ -412,9 +412,9 @@ def shell_plus(context):


@task
def cli(context):
def cli(context, service="nautobot"):
"""Launch a bash shell inside the Nautobot container."""
run_command(context, "bash")
run_command(context, "bash", service=service)


@task(
Expand Down