-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
128 lines (108 loc) · 3.74 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
# Variables
SHELL := /bin/bash
PROJECT := sensorpush
VERSION := 0.1.0
IMAGE_NAME := sensorpush-python
COMPOSE_FILE := compose.yml
GIT_HASH := $(shell git log --format="%h" -n 1)
VENV := .venv
UV_PYTHON := uv run python
UV_PIP := uv pip
UV_PIP_SYNC := uv pip sync
UV_PIP_COMPILE := uv pip compile
UV_SYNC := uv sync
DOCKER_COMPOSE := docker compose -f $(COMPOSE_FILE) -p $(PROJECT)
# Colors
GREEN := $(shell tput setaf 2)
CYAN := $(shell tput setaf 6)
RESET := $(shell tput sgr0)
# Directories
TEST_DIR := ./app/tests
SRC_DIR := ./app
# Default Target
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display help information about available rules
@echo "$(GREEN)Available rules:$(RESET)"
@grep -E '^[a-zA-Z0-9_-]+:.*##' $(MAKEFILE_LIST) | \
awk -v cyan="$(CYAN)" -v reset="$(RESET)" 'BEGIN {FS = ":.*##"}; {printf "%s%-25s%s %s\n", cyan, $$1, reset, $$2}'
.PHONY: check-require
check-require: ## Verify required tools are installed
@echo "Checking required tools..."
@uv run python --version >/dev/null || (echo "ERROR: uv Python not found!" && exit 1)
@uv --version >/dev/null || (echo "ERROR: uv is required!" && exit 1)
@uvx --version >/dev/null || (echo "ERROR: uvx is required!" && exit 1)
@uvx ruff --version >/dev/null || (echo "ERROR: ruff is required!" && exit 1)
@echo "All required tools are installed."
.PHONY: init
init: check-require ## Initialize virtual environment using uv
@if [ ! -d $(VENV) ]; then \
echo "Creating virtual environment with uv..."; \
uv venv $(VENV); \
fi
@$(MAKE) sync
@echo "Virtual environment initialized."
.PHONY: sync
sync: ## Synchronize Python dependencies
@echo "Synchronizing Python dependencies with uv sync..."
@$(UV_SYNC)
.PHONY: test
test: ## Run tests with pytest
@echo "Running tests..."
@$(UV_PYTHON) -m pytest $(TEST_DIR)
.PHONY: lint
lint: ## Run linting with ruff
@echo "Linting code..."
@uvx ruff check
.PHONY: format
format: ## Format code with ruff
@echo "Formatting code..."
@uvx ruff format
.PHONY: build
build: init ## Build the Docker image
@echo "Building Docker image..."
@docker build -t $(IMAGE_NAME) -f Dockerfile .
.PHONY: run
run: ## Run the application locally
@echo "Running application..."
@$(UV_PYTHON) main.py
.PHONY: up
up: ## Start Docker Compose services
@echo "Starting Docker Compose services..."
@$(DOCKER_COMPOSE) up -d
.PHONY: start
start: ## Start Docker Compose services without recreating containers
@echo "Starting existing Docker Compose services..."
@$(DOCKER_COMPOSE) start
.PHONY: stop
stop: ## Stop Docker Compose services without removing containers
@echo "Stopping Docker Compose services..."
@$(DOCKER_COMPOSE) stop
.PHONY: down
down: ## Stop and remove Docker Compose services
@echo "Stopping and removing Docker Compose services..."
@$(DOCKER_COMPOSE) down
.PHONY: clean
clean: ## Clean up virtual environment and other generated files
@echo "Cleaning up environment..."
@if [ -d $(VENV) ]; then \
echo "Removing virtual environment..."; \
rm -rf $(VENV); \
fi
@find . -type d -name '__pycache__' -exec rm -rf {} +
@find . -type f -name '*.pyc' -delete
@find . -type f -name '*.pyo' -delete
@find . -type f -name '*.log' -delete
@find . -type f -name '*.egg-info' -exec rm -rf {} +
@find . -type f -name '*.dist-info' -exec rm -rf {} +
@echo "Clean-up complete."
.PHONY: create-k8s-deployment
create-k8s-deployment: ## Create Kubernetes deployment
@echo "Creating Kubernetes deployment..."
@$(UV_PYTHON) annotate-elastic-apm.py -m "Created application deployment"
# kubectl apply -f sensorpush_deployment.yaml
.PHONY: delete-k8s-deployment
delete-k8s-deployment: ## Delete Kubernetes deployment
@echo "Deleting Kubernetes deployment..."
@$(UV_PYTHON) annotate-elastic-apm.py -m "Deleted application deployment"
# kubectl delete -f sensorpush_deployment.yaml