mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-25 07:50:40 +03:00
Add justfile for use with docker (#5621)
This commit is contained in:
parent
e4b00c26d7
commit
570763e7ce
|
@ -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
|
||||
------------------------------------------
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
38
{{cookiecutter.project_slug}}/justfile
Normal file
38
{{cookiecutter.project_slug}}/justfile
Normal file
|
@ -0,0 +1,38 @@
|
|||
export COMPOSE_FILE := "docker-compose.local.yml"
|
||||
|
||||
## 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…
Reference in New Issue
Block a user