183 lines
5.3 KiB
Makefile
183 lines
5.3 KiB
Makefile
.DEFAULT_GOAL := help
|
|
|
|
# --- Load Config from pyproject.toml ---
|
|
-include .env.make
|
|
|
|
# --- Profiles management ---
|
|
# Usage: make up p=rag,meili
|
|
p ?= core
|
|
PROFILES_PARAM := COMPOSE_PROFILES=$(p)
|
|
|
|
# --- Commands ---
|
|
DOCKER_COMPOSE := docker compose
|
|
DOCKER_BUILD := docker build --no-cache \
|
|
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
|
|
--build-arg PYTHON_VERSION_SHORT=$(PYTHON_VERSION_SHORT) \
|
|
--build-arg RUNNER=$(RUNNER)
|
|
|
|
# --- Phony ---
|
|
.PHONY: .env up down restart logs ps shell build build-test install update \
|
|
install-hooks test coverage lint format clean major minor patch help
|
|
|
|
# --- Setup ---
|
|
.env .env.make:
|
|
@echo "Initializing environment..."
|
|
@python scripts/bootstrap.py \
|
|
&& echo "✓ Environment ready" \
|
|
|| (echo "✗ Environment setup failed" && exit 1)
|
|
|
|
bootstrap: .env .env.make
|
|
|
|
# --- Docker ---
|
|
up: .env
|
|
@echo "Starting containers with profiles: [$(p)]..."
|
|
@$(PROFILES_PARAM) $(DOCKER_COMPOSE) up -d --remove-orphans \
|
|
&& echo "✓ Containers started" \
|
|
|| (echo "✗ Failed to start containers" && exit 1)
|
|
|
|
down:
|
|
@echo "Stopping containers..."
|
|
@$(DOCKER_COMPOSE) down \
|
|
&& echo "✓ Containers stopped" \
|
|
|| (echo "✗ Failed to stop containers" && exit 1)
|
|
|
|
restart:
|
|
@echo "Restarting containers..."
|
|
@$(PROFILES_PARAM) $(DOCKER_COMPOSE) restart \
|
|
&& echo "✓ Containers restarted" \
|
|
|| (echo "✗ Failed to restart containers" && exit 1)
|
|
|
|
logs:
|
|
@echo "Following logs (Ctrl+C to exit)..."
|
|
@$(PROFILES_PARAM) $(DOCKER_COMPOSE) logs -f
|
|
|
|
ps:
|
|
@echo "Container status:"
|
|
@$(PROFILES_PARAM) $(DOCKER_COMPOSE) ps
|
|
|
|
shell:
|
|
@echo "Opening shell in $(SERVICE_NAME)..."
|
|
@$(DOCKER_COMPOSE) exec $(SERVICE_NAME) /bin/bash
|
|
|
|
# --- Build ---
|
|
build: .env.make
|
|
@echo "Building image $(IMAGE_NAME):latest ..."
|
|
@$(DOCKER_BUILD) -t $(IMAGE_NAME):latest . \
|
|
&& echo "✓ Build complete" \
|
|
|| (echo "✗ Build failed" && exit 1)
|
|
|
|
build-test: .env.make
|
|
@echo "Building test image $(IMAGE_NAME):test..."
|
|
@$(DOCKER_BUILD) --target test -t $(IMAGE_NAME):test . \
|
|
&& echo "✓ Test image built" \
|
|
|| (echo "✗ Build failed" && exit 1)
|
|
|
|
# --- Dependencies ---
|
|
install:
|
|
@echo "Installing dependencies with $(RUNNER)..."
|
|
@$(RUNNER) install \
|
|
&& echo "✓ Dependencies installed" \
|
|
|| (echo "✗ Installation failed" && exit 1)
|
|
|
|
install-hooks:
|
|
@echo "Installing pre-commit hooks..."
|
|
@$(RUNNER) run pre-commit install \
|
|
&& echo "✓ Hooks installed" \
|
|
|| (echo "✗ Hook installation failed" && exit 1)
|
|
|
|
update:
|
|
@echo "Updating dependencies with $(RUNNER)..."
|
|
@$(RUNNER) update \
|
|
&& echo "✓ Dependencies updated" \
|
|
|| (echo "✗ Update failed" && exit 1)
|
|
|
|
# --- Quality ---
|
|
test:
|
|
@echo "Running tests..."
|
|
@$(RUNNER) run pytest \
|
|
&& echo "✓ Tests passed" \
|
|
|| (echo "✗ Tests failed" && exit 1)
|
|
|
|
coverage:
|
|
@echo "Running tests with coverage..."
|
|
@$(RUNNER) run pytest --cov=. --cov-report=html --cov-report=term \
|
|
&& echo "✓ Coverage report generated" \
|
|
|| (echo "✗ Coverage failed" && exit 1)
|
|
|
|
lint:
|
|
@echo "Linting code..."
|
|
@$(RUNNER) run ruff check --fix . \
|
|
&& echo "✓ Linting complete" \
|
|
|| (echo "✗ Linting failed" && exit 1)
|
|
|
|
format:
|
|
@echo "Formatting code..."
|
|
@$(RUNNER) run ruff format . && $(RUNNER) run ruff check --fix . \
|
|
&& echo "✓ Code formatted" \
|
|
|| (echo "✗ Formatting failed" && exit 1)
|
|
|
|
clean:
|
|
@echo "Cleaning build artifacts..."
|
|
@rm -rf .ruff_cache __pycache__ .pytest_cache htmlcov .coverage
|
|
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
@echo "✓ Cleanup complete"
|
|
|
|
# --- Versioning ---
|
|
major minor patch: _check-main
|
|
@echo "Bumping $@ version..."
|
|
@$(RUNNER) run bump-my-version bump $@ \
|
|
&& echo "✓ Version bumped" \
|
|
|| (echo "✗ Version bump failed" && exit 1)
|
|
|
|
@echo "Pushing tags..."
|
|
@git push --tags \
|
|
&& echo "✓ Tags pushed" \
|
|
|| (echo "✗ Push failed" && exit 1)
|
|
|
|
# CI/CD helpers
|
|
_ci-dump-config:
|
|
@echo "image_name=$(IMAGE_NAME)"
|
|
@echo "python_version=$(PYTHON_VERSION)"
|
|
@echo "python_version_short=$(PYTHON_VERSION_SHORT)"
|
|
@echo "runner=$(RUNNER)"
|
|
@echo "service_name=$(SERVICE_NAME)"
|
|
|
|
_ci-run-tests:build-test
|
|
@echo "Running tests in Docker..."
|
|
docker run --rm \
|
|
-e DEEPSEEK_API_KEY \
|
|
-e TMDB_API_KEY \
|
|
-e QBITTORRENT_URL \
|
|
$(IMAGE_NAME):test pytest
|
|
@echo "✓ Tests passed."
|
|
|
|
_check-main:
|
|
@test "$$(git rev-parse --abbrev-ref HEAD)" = "main" \
|
|
|| (echo "✗ ERROR: Not on main branch" && exit 1)
|
|
|
|
# --- Help ---
|
|
help:
|
|
@echo "Cleverly Crafted Unawareness - Management Commands"
|
|
@echo ""
|
|
@echo "Usage: make [target] [p=profile1,profile2]"
|
|
@echo ""
|
|
@echo "Docker:"
|
|
@echo " up Start containers (default profile: core)"
|
|
@echo " Example: make up p=rag,meili"
|
|
@echo " down Stop all containers"
|
|
@echo " restart Restart containers (supports p=...)"
|
|
@echo " logs Follow logs (supports p=...)"
|
|
@echo " ps Status of containers"
|
|
@echo " shell Open bash in the core container"
|
|
@echo " build Build the production Docker image"
|
|
@echo ""
|
|
@echo "Dev & Quality:"
|
|
@echo " setup Bootstrap .env and security keys"
|
|
@echo " install Install dependencies via $(RUNNER)"
|
|
@echo " test Run pytest suite"
|
|
@echo " coverage Run tests and generate HTML report"
|
|
@echo " lint/format Quality and style checks"
|
|
@echo ""
|
|
@echo "Release:"
|
|
@echo " major|minor|patch Bump version and push tags (main branch only)"
|