|
| 1 | +include .env |
| 2 | + |
| 3 | +COMPOSE_FILE=docker-compose.yml |
| 4 | +DOCKER_COMPOSE=docker compose -f $(COMPOSE_FILE) |
| 5 | + |
| 6 | +BLACK := $(shell tput -Txterm setaf 0) |
| 7 | +RED := $(shell tput -Txterm setaf 1) |
| 8 | +GREEN := $(shell tput -Txterm setaf 2) |
| 9 | +YELLOW := $(shell tput -Txterm setaf 3) |
| 10 | +LIGHTPURPLE := $(shell tput -Txterm setaf 4) |
| 11 | +PURPLE := $(shell tput -Txterm setaf 5) |
| 12 | +BLUE := $(shell tput -Txterm setaf 6) |
| 13 | +WHITE := $(shell tput -Txterm setaf 7) |
| 14 | +RESET := $(shell tput -Txterm sgr0) |
| 15 | + |
| 16 | +default: build |
| 17 | + |
| 18 | +#============================================== |
| 19 | +# Building and cleaning the Docker environment |
| 20 | +#============================================== |
| 21 | +build: ## Build all Docker images |
| 22 | + @echo "Building Quiz Extensions LTI Docker images" |
| 23 | + @$(DOCKER_COMPOSE) build |
| 24 | + |
| 25 | +clean: ## Stops and removes existing existing containers and volumes |
| 26 | + @echo "${YELLOW}Stopping running containers and purging existing volumes${RESET}" |
| 27 | + $(DOCKER_COMPOSE) down -v |
| 28 | + @echo "Rebuilding images" |
| 29 | + |
| 30 | +#================================================================================ |
| 31 | +# Managing the Docker environment (e.g. starting, stopping, deleting containers) |
| 32 | +#================================================================================ |
| 33 | + |
| 34 | +start: start-daemon ## Start Quiz Extensions LTI (default: daemon mode) |
| 35 | + |
| 36 | +start-attached: ## Start Quiz Extensions LTI in attached mode |
| 37 | + @echo "${GREEN}Starting Quiz Extensions LTI in attached mode${RESET}" |
| 38 | + $(DOCKER_COMPOSE) up |
| 39 | + |
| 40 | +start-daemon: ## Start Quiz Extensions LTI in daemon mode |
| 41 | + @echo "${GREEN}Starting Quiz Extensions LTI in daemon mode${RESET}" |
| 42 | + @echo "Run \`make start-attached\` to run in attached mode, or view container logs with \`make logs\`" |
| 43 | + $(DOCKER_COMPOSE) up -d |
| 44 | + |
| 45 | +stop: ## Stop all containers |
| 46 | + @echo "${YELLOW}Stopping all containers${RESET}" |
| 47 | + $(DOCKER_COMPOSE) stop |
| 48 | + |
| 49 | +logs: ## View container logs (optionally specifying a service name, like `quiz_extensions` or `quiz_db`) |
| 50 | + $(DOCKER_COMPOSE) logs --tail 10 -f $(filter-out $@,$(MAKECMDGOALS)) |
| 51 | + |
| 52 | +#============================================== |
| 53 | +# Application management commands |
| 54 | +#============================================== |
| 55 | + |
| 56 | +test-all: ## Run all unit tests |
| 57 | + $(DOCKER_COMPOSE) run --rm quiz_extensions python -m unittest |
| 58 | + |
| 59 | +lint: ## Run Python linter (flake8) |
| 60 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flake8 . |
| 61 | + |
| 62 | +format: ## Run Python code formatter (black) and import sorter (isort). Will fix formatting errors. |
| 63 | + ${DOCKER_COMPOSE} run --rm quiz_extensions sh -c "black . && isort ." |
| 64 | + |
| 65 | +format-check: ## Run Python code formatter (black) and import sorter (isort) in check mode. Will not alter files. |
| 66 | + ${DOCKER_COMPOSE} run --rm quiz_extensions sh -c "black . --check && isort . --check-only" |
| 67 | + |
| 68 | +lint-format: ## Run Python code formatter (black), import sorter (isort), and linter (flake8). Will fix formatting errors but not linting errors. |
| 69 | + ${DOCKER_COMPOSE} run --rm quiz_extensions sh -c "black . && isort . && flake8 ." |
| 70 | + |
| 71 | +lint-format-check: ## Run Python code formatter (black) and import sorter (isort) in check mode, and linter (flake8). Will not alter files. |
| 72 | + ${DOCKER_COMPOSE} run --rm quiz_extensions sh -c "black . --check && isort . --check-only && flake8 ." |
| 73 | + |
| 74 | +migrate-create: ## Create a new DB migration |
| 75 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask db migrate |
| 76 | + |
| 77 | +migrate-run: ## Run an existing DB migration |
| 78 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask db upgrade |
| 79 | + |
| 80 | +shell: ## Run shell in Flask context |
| 81 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask shell |
| 82 | + |
| 83 | +generate-keys: ## Create new public and private keys and assign them to a keyset |
| 84 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask generate_keys |
| 85 | + |
| 86 | +register: ## Add a new registration for Quiz Extensions in a platform |
| 87 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask register |
| 88 | + |
| 89 | +deploy: ## Add a new deployment for Quiz Extensions to an existing registration |
| 90 | + ${DOCKER_COMPOSE} run --rm quiz_extensions flask deploy |
| 91 | + |
| 92 | +.PHONY: help |
| 93 | +help: |
| 94 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
0 commit comments