-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
234 lines (191 loc) · 7.94 KB
/
Copy pathMakefile
File metadata and controls
234 lines (191 loc) · 7.94 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
.PHONY: help build run stop clean test bench dev logs shell db-backup db-restore release
# Load .env file if it exists (for SKIP_WEB, etc.)
-include .env
export
# Variables
GIT_VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "1.0.0-dev")
VERSION ?= $(GIT_VERSION)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
DEFAULT_SERVER_URL ?= http://localhost:8000
SKIP_WEB ?= 0
COMPOSE=docker compose -f docker/docker-compose.yml
COMPOSE_DEV=docker compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml
SERVER_BINARY=build/binaries/server
CLI_BINARY=build/binaries/datumctl
help: ## Show this help message
@echo "Datum IoT Platform - Makefile Commands"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# Docker commands
docker-build: ## Build all Docker images
docker compose -f docker/docker-compose.yml build
build: build-all ## Build all binaries (Server + CLI + Web)
release: ## Build release Docker image (usage: make release VERSION=1.2.3 DEFAULT_SERVER_URL=http://api.example.com)
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg DEFAULT_SERVER_URL=$(DEFAULT_SERVER_URL) \
-t datum-server:$(VERSION) \
-t datum-server:latest \
-f docker/Dockerfile .
run: ## Start all services
$(COMPOSE) up -d
@echo "✅ Services started"
stop: ## Stop all services
$(COMPOSE) down
restart: ## Restart all services
$(COMPOSE) restart
logs: ## Show logs (use SERVICE=datum-server to filter)
@if [ -z "$(SERVICE)" ]; then \
$(COMPOSE) logs -f; \
else \
$(COMPOSE) logs -f $(SERVICE); \
fi
ps: ## Show running containers
$(COMPOSE) ps
# Development commands
dev: ## Start services in development mode with hot reload
$(COMPOSE_DEV) up -d
@echo "🔧 Development mode active"
dev-logs: ## Show development logs
$(COMPOSE_DEV) logs -f
# Database commands
db-backup: ## Backup database and time-series data
@echo "📦 Creating backup..."
@mkdir -p backups
@tar -czf backups/backup-$$(date +%Y%m%d-%H%M%S).tar.gz data/
@echo "✅ Backup created in backups/"
db-restore: ## Restore database from backup (use BACKUP=filename)
@if [ -z "$(BACKUP)" ]; then \
echo "❌ Error: Please specify BACKUP=filename"; \
echo "Available backups:"; \
ls -1 backups/; \
exit 1; \
fi
@echo "🔄 Restoring from $(BACKUP)..."
@$(COMPOSE) down
@rm -rf data/
@tar -xzf backups/$(BACKUP)
@echo "✅ Restore completed"
db-clean: ## Clean all data (WARNING: destroys all data)
@echo "⚠️ This will delete all data!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
$(COMPOSE) down -v; \
rm -rf data/; \
echo "✅ Data cleaned"; \
fi
# Testing commands
test: ## Run all Go tests
@echo "🧪 Running Go tests..."
@mkdir -p build
@go test ./... -v
test-coverage: ## Run tests with coverage
@echo "🧪 Running tests with coverage..."
@mkdir -p build
@go test ./... -coverprofile=build/coverage.out
@go tool cover -html=build/coverage.out -o build/coverage.html
@echo "✅ Coverage report: build/coverage.html"
test-storage: ## Run storage tests with verbose output
@echo "🧪 Running storage tests..."
@go test ./internal/storage/... -v
test-auth: ## Run auth tests
@echo "🧪 Running auth tests..."
@go test ./internal/auth/... -v
bench: ## Run Go benchmarks
@echo "⚡ Running Go benchmarks..."
@go test ./... -bench=. -benchmem
test-load: ## Run HTTP load tests with Locust
@echo "⚡ Running HTTP load tests..."
@bash tests/run_load_test.sh
# Build commands
# Build commands
# Build commands
build-web: ## Build Web Dashboard (React) - Auto-detects npm or uses Docker
@echo "🎨 Building Web Dashboard..."
@if command -v npm >/dev/null 2>&1; then \
echo "Found npm locally. Building..."; \
cd web && npm install && npm run build; \
else \
echo "npm not found. Building using Docker (node:20-alpine)..."; \
docker run --rm -u $$(id -u):$$(id -g) -v $$(pwd):/app -w /app/web node:20-alpine sh -c "npm ci && npm run build"; \
fi
@if [ ! -f web/dist/index.html ]; then echo "❌ web/dist/index.html missing! Build failed."; exit 1; fi
@echo "✅ Web Dashboard built"
prepare-assets: ## Copy web assets to server directory (skip with SKIP_WEB=1)
@if [ "$(SKIP_WEB)" = "1" ]; then \
echo "⚠️ SKIP_WEB=1: Creating minimal placeholder for API-only build..."; \
rm -rf cmd/server/dist; \
mkdir -p cmd/server/dist; \
echo '<!DOCTYPE html><html><body><h1>API-Only Mode</h1><p>Web UI not included in this build.</p></body></html>' > cmd/server/dist/index.html; \
else \
$(MAKE) build-web; \
echo "📦 Copying web assets..."; \
rm -rf cmd/server/dist; \
cp -r web/dist cmd/server/dist; \
fi
build-server: prepare-assets ## Build Go server binary locally
@echo "🔨 Building Go server..."
@mkdir -p build/binaries
@go build -o $(SERVER_BINARY) ./cmd/server
@echo "✅ Binary created: $(SERVER_BINARY)"
build-api-only: ## Build server without web UI (API-only mode)
@echo "🔨 Building API-only server..."
@SKIP_WEB=1 $(MAKE) build-server
@echo "✅ API-only binary created: $(SERVER_BINARY)"
build-cli: ## Build datumctl CLI tool
@echo "🔨 Building datumctl..."
@mkdir -p build/binaries
@go build -ldflags "-X main.Version=$(VERSION) -X main.DefaultServerURL=$(DEFAULT_SERVER_URL)" -o $(CLI_BINARY) ./cmd/datumctl
@echo "✅ CLI tool created: $(CLI_BINARY)"
build-all: build-server build-cli ## Build server and CLI
# Cross-platform build targets
build-linux: prepare-assets ## Build Linux binaries (AMD64)
@echo "🔨 Building Linux binaries..."
@mkdir -p build/release
@GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION)" -o build/release/datum-server-linux-amd64 ./cmd/server
@GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION)" -o build/release/datumctl-linux-amd64 ./cmd/datumctl
@echo "✅ Linux binaries created in build/release/"
build-windows: prepare-assets ## Build Windows binaries (AMD64)
@echo "🔨 Building Windows binaries..."
@mkdir -p build/release
@GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION)" -o build/release/datum-server-windows-amd64.exe ./cmd/server
@GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION)" -o build/release/datumctl-windows-amd64.exe ./cmd/datumctl
@echo "✅ Windows binaries created in build/release/"
build-release: build-linux build-windows ## Build release binaries for all platforms
run-server: build-server ## Build and run server locally
@echo "🚀 Starting server..."
@./$(SERVER_BINARY)
# Code quality
fmt: ## Format Go code
@echo "🔧 Formatting Go code..."
@go fmt ./...
lint: ## Lint Go code
@echo "🔍 Linting Go code..."
@go vet ./...
fmt-python: ## Format Python test scripts
@echo "🔧 Formatting Python code..."
@cd tests && black *.py 2>/dev/null || echo "⚠️ Black not installed"
# Utility commands
shell-server: ## Open shell in server container
$(COMPOSE) exec datum-server sh
clean: ## Clean build artifacts and containers
$(COMPOSE) down -v
rm -rf build/
rm -f datumctl server # Remove binaries if built in root
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@echo "✅ Cleaned"
install-tools: ## Install development tools
@echo "📦 Installing development tools..."
@go install golang.org/x/tools/cmd/goimports@latest
@pip3 install locust black 2>/dev/null || echo "⚠️ pip3 not found (required for load tests)"
# Health checks
health: ## Check service health (Development)
@echo "🏥 Checking service health..."
@curl -s http://localhost:8000/health | python3 -m json.tool || echo "❌ Server not responding (ensure you are running in dev mode or port 8000 is exposed)"
# Documentation
docs: ## Open API documentation in browser (Development)
@echo "📖 Opening API docs..."
@xdg-open http://localhost:8000/docs 2>/dev/null || open http://localhost:8000/docs 2>/dev/null || echo "Open http://localhost:8000/docs in your browser"
.DEFAULT_GOAL := help