Skip to content
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
64 changes: 38 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
help:
@echo "Call a specific subcommand:"
@echo
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo
.DEFAULT_GOAL := help
Comment thread
JacobCoffee marked this conversation as resolved.

default: help
help: ## Display this help text
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

# =============================================================================
# Docker State
# =============================================================================

.state/docker-build-web: Dockerfile pyproject.toml
# Build web container for this project
docker compose build --force-rm web

# Mark the state so we don't rebuild this needlessly.
mkdir -p .state && touch .state/docker-build-web

.state/db-migrated:
# Call migrate target
make migrate

# Mark the state so we don't rebuild this needlessly.
make migrate
mkdir -p .state && touch .state/db-migrated

.state/db-initialized: .state/docker-build-web .state/db-migrated
# Load all fixtures
docker compose run --rm web ./manage.py loaddata fixtures/*.json

# Mark the state so we don't rebuild this needlessly.
mkdir -p .state && touch .state/db-initialized

# =============================================================================
# Development
# =============================================================================

##@ Development

serve: .state/db-initialized ## Start the application
docker compose up --remove-orphans

migrations: .state/db-initialized ## Generate migrations from models
docker compose run --rm web ./manage.py makemigrations
docker compose run --rm web ./manage.py makemigrations

migrate: .state/docker-build-web ## Run Django migrate
docker compose run --rm web ./manage.py migrate
docker compose run --rm web ./manage.py migrate

manage: .state/db-initialized ## Run Django manage to accept arbitrary arguments
manage: .state/db-initialized ## Run arbitrary manage.py commands
docker compose run --rm web ./manage.py $(filter-out $@,$(MAKECMDGOALS))

shell: .state/db-initialized ## Open Django interactive shell
docker compose run --rm web ./manage.py shell

docker_shell: .state/db-initialized ## Open bash in web container
docker compose run --rm web /bin/bash

clean: ## Clean up the environment
docker compose down -v
rm -f .state/docker-build-web .state/db-initialized .state/db-migrated
rm -f .state/docker-build-web .state/db-initialized .state/db-migrated

# =============================================================================
# Code Quality
# =============================================================================

##@ Code Quality

test: .state/db-initialized ## Run tests
lint: ## Run ruff linter (--fix enabled)
@if command -v ruff >/dev/null 2>&1; then ruff check --fix .; else docker compose run --rm web ruff check --fix .; fi

fmt: ## Run ruff formatter
@if command -v ruff >/dev/null 2>&1; then ruff format .; else docker compose run --rm web ruff format .; fi

test: .state/db-initialized ## Run test suite
docker compose run --rm web ./manage.py test

docker_shell: .state/db-initialized ## Open a bash shell in the web container
docker compose run --rm web /bin/bash
ci: lint fmt test ## Run lint, fmt, then tests
Comment thread
JacobCoffee marked this conversation as resolved.

.PHONY: help serve migrations migrate manage shell clean test docker_shell
.PHONY: help serve migrations migrate manage shell docker_shell clean
.PHONY: lint fmt test ci