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

Added the ability to pass service name to invoke cli. #188

Merged
merged 3 commits into from
Oct 18, 2024
Merged
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
22 changes: 13 additions & 9 deletions nautobot-app/{{ cookiecutter.project_slug }}/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.{{ cookiecutter.app_name }}.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,10 +412,14 @@ def shell_plus(context):
run_command(context, command)


@task
def cli(context):
"""Launch a bash shell inside the Nautobot container."""
run_command(context, "bash")
@task(
help={
"service": "Docker compose service name to launch cli in (default: nautobot).",
}
)
def cli(context, service="nautobot"):
"""Launch a bash shell inside the container."""
run_command(context, "bash", service=service)


@task(
Expand Down
Loading