Skip to content

Commit

Permalink
Adds invoke logs for easily viewing container logs (#6680)
Browse files Browse the repository at this point in the history
* Adds invoke logs

* Removes whitespace

* Updates dev getting started documentation

---------

Co-authored-by: Hanlin Miao <[email protected]>
  • Loading branch information
joewesch and HanlinMiao authored Dec 19, 2024
1 parent d351e82 commit e0de1fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/6679.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `logs` task to `tasks.py` to view the logs of a docker compose service.
11 changes: 7 additions & 4 deletions nautobot/docs/development/core/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,25 @@ Available tasks:
hadolint Check Dockerfile for hadolint compliance and other style issues.
integration-test Run Nautobot integration tests.
loaddata Load data from file.
logs View the logs of a docker compose service.
makemigrations Perform makemigrations operation in Django.
migration-test Test database migration from a given dataset to latest Nautobot schema.
markdownlint Lint Markdown files.
migrate Perform migrate operation in Django.
migration-test Test database migration from a given dataset to latest Nautobot schema.
nbshell Launch an interactive Nautobot shell.
performance-test Run Nautobot performance tests.
post-upgrade Performs Nautobot common post-upgrade operations using a single entrypoint.
pylint Perform static analysis of Nautobot code.
restart Gracefully restart containers.
ruff Run ruff to perform code formatting and/or linting.
serve-docs Runs local instance of mkdocs serve (ctrl-c to stop).
ruff Run ruff to perform code formatting and linting.
serve-docs Runs local instance of mkdocs serve on port 8001 (ctrl-c to stop).
showmigrations Perform showmigrations operation in Django.
start Start Nautobot and its dependencies in detached mode.
stop Stop Nautobot and its dependencies.
tests Run all linters and unit tests.
unittest Run Nautobot unit tests.
unittest-coverage Report on code test coverage as measured by 'invoke unittest'.
version Show the version of Nautobot Python and NPM packages or bump them when a valid bump rule is provided.
version Show the version of Nautobot Python package or bump it when a valid bump rule is provided.
vscode Launch Visual Studio Code with the appropriate Environment variables to run in a container.
yamllint Run yamllint to validate formatting applies to YAML standards.
```
Expand All @@ -233,6 +235,7 @@ A development environment can be easily started up from the root of the project
Additional useful commands for the development environment:

* `invoke start [-s servicename]` - Starts Docker containers for Nautobot, PostgreSQL, Redis, NGINX, Celery, and Celery Beat (or a specific container/service, such as `invoke start -s redis`) to run in the background
* `invoke logs [-s servicename]` - View the logs of the containers (or a specific container/service, such as `invoke logs -s nautobot`)
* `invoke nbshell` - Launches a Nautobot Python shell inside the Nautobot container
* `invoke cli [-s servicename]` - Launches a `bash` shell inside the specified service container (if none is specified, defaults to the Nautobot container)
* `invoke stop [-s servicename]` - Stops all containers (or a specific container/service) created by `invoke start`
Expand Down
19 changes: 19 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@ def vscode(context):
context.run(command, env={"PYTHON_VER": context.nautobot.python_ver})


@task(
help={
"service": "If specified, only display logs for this service (default: all)",
"follow": "Flag to follow logs (default: False)",
"tail": "Tail N number of lines (default: all)",
}
)
def logs(context, service="", follow=False, tail=0):
"""View the logs of a docker compose service."""
command = "logs"

if follow:
command += " --follow"
if tail:
command += f" --tail={tail}"

docker_compose(context, command, service=service)


# ------------------------------------------------------------------------------
# ACTIONS
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit e0de1fe

Please sign in to comment.