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 justfile for use with docker #5621

Merged
merged 7 commits into from
Jan 6, 2025
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
35 changes: 35 additions & 0 deletions docs/2-local-development/developing-locally-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ The stack comes with a dedicated node service to build the static assets, watch
.. _Sass: https://sass-lang.com/
.. _live reloading: https://browsersync.io


Using Just for Docker Commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We have included a ``justfile`` to simplify the use of frequent Docker commands for local development.

.. warning::
Currently, "Just" does not reliably handle signals or forward them to its subprocesses. As a result,
pressing CTRL+C (or sending other signals like SIGTERM, SIGINT, or SIGHUP) may only interrupt
"Just" itself rather than its subprocesses.
For more information, see `this GitHub issue <https://github.com/casey/just/issues/2473>`_.

First, install Just using one of the methods described in the `official documentation <https://just.systems/man/en/packages.html>`_.

Here are the available commands:

- ``just build``
Builds the Python image using the local Docker Compose file.

- ``just up``
Starts the containers in detached mode and removes orphaned containers.

- ``just down``
Stops the running containers.

- ``just prune``
Stops and removes containers along with their volumes. You can optionally pass an argument with the service name to prune a single container.

- ``just logs``
Shows container logs. You can optionally pass an argument with the service name to view logs for a specific service.

- ``just manage <command>``
Runs Django management commands within the container. Replace ``<command>`` with any valid Django management command, such as ``migrate``, ``createsuperuser``, or ``shell``.


(Optionally) Developing locally with HTTPS
------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def remove_docker_files():
"docker-compose.local.yml",
"docker-compose.production.yml",
".dockerignore",
"justfile",
]
for file_name in file_names:
os.remove(file_name)
Expand Down
38 changes: 38 additions & 0 deletions {{cookiecutter.project_slug}}/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export COMPOSE_FILE := "docker-compose.local.yml"

earthcomfy marked this conversation as resolved.
Show resolved Hide resolved
## Just does not yet manage signals for subprocesses reliably, which can lead to unexpected behavior.
## Exercise caution before expanding its usage in production environments.
## For more information, see https://github.com/casey/just/issues/2473 .


# Default command to list all available commands.
default:
@just --list

# build: Build python image.
build:
@echo "Building python image..."
@docker compose build

# up: Start up containers.
up:
@echo "Starting up containers..."
@docker compose up -d --remove-orphans

# down: Stop containers.
down:
@echo "Stopping containers..."
@docker compose down

# prune: Remove containers and their volumes.
prune *args:
@echo "Killing containers and removing volumes..."
@docker compose down -v {{ "{{args}}" }}

# logs: View container logs
logs *args:
@docker compose logs -f {{ "{{args}}" }}

# manage: Executes `manage.py` command.
manage +args:
@docker compose run --rm django python ./manage.py {{ "{{args}}" }}
Loading