-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
152 lines (132 loc) · 5.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
UV := uv
PYTHON_VERSION := 3.11
UV_INSTALL_SCRIPT := https://astral.sh/uv/install.sh
PATH := $(HOME)/.local/bin:$(PATH)
.PHONY: check-uv
check-uv: ## Check and install uv if necessary
@if command -v $(UV) >/dev/null 2>&1; then \
echo "📦 uv is already installed."; \
else \
echo "📦 uv is not installed. Installing uv..."; \
curl -LsSf $(UV_INSTALL_SCRIPT) | sh; \
fi; \
if ! command -v $(UV) >/dev/null 2>&1; then \
echo "❌ uv is not in your PATH. Please add the uv installation directory to your PATH environment variable."; \
exit 1; \
fi
.PHONY: install-python
install-python: check-uv ## Install Python with uv
@echo "🐍 Installing Python $(PYTHON_VERSION) with uv"
@$(UV) python install $(PYTHON_VERSION)
@echo "🔧 Configuring Python $(PYTHON_VERSION) as the default Python version"
@$(UV) python pin $(PYTHON_VERSION)
.PHONY: install
install: install-python ## Install core dependencies
@echo "📦 Installing core dependencies with uv"
@$(UV) sync --group controller --group core
@echo "🔧 Installing pre-commit hooks"
@$(UV) run pre-commit install
@echo ""
@$(MAKE) update
@echo ""
@$(MAKE) shell
.PHONY: install-production
install-production: install ## Install production dependencies
@echo "🐳 Updating production docker images..."
@echo "🐳 Building nebula-waf"
@docker build -t nebula-waf -f nebula/addons/waf/Dockerfile-waf --build-arg USER=$(USER) nebula/addons/waf
@echo "🐳 Building nebula-loki"
@docker build -t nebula-waf-loki -f nebula/addons/waf/Dockerfile-loki nebula/addons/waf
@echo "🐳 Building nebula-promtail"
@docker build -t nebula-waf-promtail -f nebula/addons/waf/Dockerfile-promtail --build-arg USER=$(USER) nebula/addons/waf
@echo "🐳 Building nebula-grafana"
@docker build -t nebula-waf-grafana -f nebula/addons/waf/Dockerfile-grafana --build-arg USER=$(USER) nebula/addons/waf
echo "🐳 Docker images updated."
.PHONY: shell
shell: ## Start a shell in the uv environment
@echo "🐚 Starting a shell in the uv environment"
@if [ -n "$$VIRTUAL_ENV" ]; then \
echo "🐚 Already in a virtual environment: $$VIRTUAL_ENV"; \
elif [ ! -d ".venv" ]; then \
echo "❌ .venv directory not found. Running 'make install' to create it..."; \
$(MAKE) install; \
else \
echo "🐚 Run the following command to activate the virtual environment:"; \
echo ""; \
echo '[Linux/MacOS] \033[1;32msource .venv/bin/activate\033[0m'; \
echo '[Windows] \033[1;32m.venv\\bin\\activate\033[0m'; \
echo ""; \
echo "🚀 NEBULA is ready to use!"; \
echo "🚀 Created by \033[1;34mEnrique Tomás Martínez Beltrán\033[0m <\033[1;[email protected]\033[0m>"; \
fi
.PHONY: update
update: ## Update docker images
@echo "🐳 Updating docker images..."
@echo "🐳 Building nebula-frontend docker image. Do you want to continue (overrides existing image)? (y/n)"
@read ans; if [ "$${ans:-N}" = y ]; then \
docker build -t nebula-frontend -f nebula/frontend/Dockerfile .; \
else \
echo "Skipping nebula-frontend docker build."; \
fi
@echo ""
@echo "🐳 Building nebula-core docker image. Do you want to continue? (overrides existing image)? (y/n)"
@read ans; if [ "$${ans:-N}" = y ]; then \
docker build -t nebula-core .; \
else \
echo "Skipping nebula-core docker build."; \
fi
echo "🐳 Docker images updated."
.PHONY: lock
lock: ## Update the lock file
@echo "🔒 This will update the lock file. Do you want to continue? (y/n)"
@read ans && [ $${ans:-N} = y ] || { echo "Lock cancelled."; exit 1; }
@echo "🔒 Locking dependencies..."
@$(UV) lock
.PHONY: check
check: ## Run code quality tools
@echo "🛠️ Running code quality checks"
@$(UV) run pre-commit run -a
.PHONY: check-plus
check-plus: check ## Run additional code quality tools
@echo "🔍 Checking code formatting with black"
@$(UV) run black --check .
@echo "⚙️ Static type checking with mypy"
@$(UV) run mypy
@echo "🔎 Checking for obsolete dependencies"
@$(UV) run deptry .
.PHONY: build
build: clean-build ## Build the wheel file
@echo "🚀 Creating wheel file"
@$(UV) build
.PHONY: clean-build
clean-build: ## Clean build artifacts
@rm -rf dist
.PHONY: publish
publish: ## Publish a release to PyPI
@echo "🚀 Publishing...""
@$(UV) publish --token $(PYPI_TOKEN)
.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish the package
.PHONY: doc-install
full-install: install-python ## Install dependencies for documentation
@echo "📦 Installing doc dependencies with uv"
@$(UV) sync --group core --group docs
@$(MAKE) shell
.PHONY: doc-test
doc-test: ## Test if documentation can be built without errors
@$(UV) run mkdocs build -f docs/mkdocs.yml -d _build -s
.PHONY: doc-build
doc-build: ## Build the documentation
@$(UV) run mkdocs build -f docs/mkdocs.yml -d _build
.PHONY: doc-serve
doc-serve: ## Serve the documentation locally
@$(UV) run mkdocs serve -f docs/mkdocs.yml
.PHONY: clean
clean: clean-build ## Clean up build artifacts and caches
@echo "🧹 Cleaning up build artifacts and caches"
@rm -rf __pycache__ */__pycache__ .mypy_cache
.PHONY: help
help: ## Display available commands
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "💡 \033[36m%-20s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help