-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
289 lines (227 loc) · 10.4 KB
/
Makefile
File metadata and controls
289 lines (227 loc) · 10.4 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Eos Makefile
# Last Updated: 2025-10-23
.PHONY: all build test lint lint-fix clean install help \
ci-preflight ci-lint ci-unit ci-integration ci-e2e-smoke ci-fuzz ci-coverage-delta \
ci-debug ci-verify-parity governance-check submodule-freshness
# Build configuration
BINARY_NAME := eos
BUILD_DIR := /tmp
INSTALL_DIR := /usr/local/bin
# CGO configuration for Ceph and libvirt support
CGO_ENABLED := 1
export CGO_ENABLED
# Go build flags
BUILD_FLAGS := -v
LDFLAGS := -s -w
# Linting configuration
GOLANGCI_LINT := golangci-lint
GOLANGCI_LINT_VERSION := v1.61.0
##@ General
all: lint test build ## Run lint, test, and build
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
build: ## Build Eos binary with CGO support
@echo "[INFO] Building Eos with libvirt and Ceph support..."
@echo "[INFO] CGO_ENABLED=$(CGO_ENABLED)"
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) .
build-debug: ## Build with debug symbols and race detector
@echo "[INFO] Building Eos with debug symbols..."
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -race -o $(BUILD_DIR)/$(BINARY_NAME)-debug .
install: build ## Build and install Eos to /usr/local/bin
@echo "[INFO] Installing Eos to $(INSTALL_DIR)..."
@if [ -f "$(INSTALL_DIR)/$(BINARY_NAME)" ]; then \
backup="$(INSTALL_DIR)/$(BINARY_NAME).backup.$$(date +%Y%m%d-%H%M%S)"; \
echo "[INFO] Backing up existing binary to $$backup"; \
sudo mv "$(INSTALL_DIR)/$(BINARY_NAME)" "$$backup"; \
fi
sudo cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/$(BINARY_NAME)
sudo chmod +x $(INSTALL_DIR)/$(BINARY_NAME)
@echo "[INFO] Installation complete"
##@ Testing
test: ## Run all tests
@echo "[INFO] Running tests..."
go test -v -race -timeout=5m ./pkg/...
test-coverage: ## Run tests with coverage report
@echo "[INFO] Running tests with coverage..."
go test -v -race -coverprofile=coverage.out -covermode=atomic ./pkg/...
go tool cover -html=coverage.out -o coverage.html
@echo "[INFO] Coverage report generated: coverage.html"
test-cgo: ## Run tests for CGO-enabled packages (cephfs, kvm)
@echo "[INFO] Running CGO-enabled tests..."
CGO_ENABLED=1 go test -v -race -tags=integration ./pkg/cephfs/...
CGO_ENABLED=1 go test -v -race -tags=integration ./pkg/kvm/...
test-e2e-smoke: ## Run E2E smoke tests (fast, non-destructive)
@echo "[INFO] Running E2E smoke tests..."
@echo "[INFO] These tests verify command structure without modifying the system"
go test -v -tags=e2e_smoke -timeout=5m ./test/e2e/smoke/...
test-e2e-full: ## Run full E2E tests (slow, DESTRUCTIVE - requires isolated test environment)
@echo "[WARN] ==================================================================="
@echo "[WARN] Running FULL E2E tests - these MODIFY the system!"
@echo "[WARN] Only run in isolated test environment (VM or container)"
@echo "[WARN] ==================================================================="
@if [ "$$EOS_E2E_FULL_APPROVED" != "true" ]; then \
echo "[ERROR] Full E2E tests not approved"; \
echo "[ERROR] Set EOS_E2E_FULL_APPROVED=true to run destructive tests"; \
exit 1; \
fi
@echo "[INFO] Running full E2E tests..."
sudo -E go test -v -tags=e2e_full -timeout=60m ./test/e2e/full/...
##@ Linting
lint-install: ## Install golangci-lint
@echo "[INFO] Checking for golangci-lint..."
@if ! command -v $(GOLANGCI_LINT) >/dev/null 2>&1; then \
echo "[INFO] Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION); \
else \
echo "[INFO] golangci-lint already installed: $$($(GOLANGCI_LINT) --version)"; \
fi
lint: lint-install ## Run golangci-lint (all packages including CGO)
@echo "[INFO] Running golangci-lint with CGO support..."
CGO_ENABLED=1 $(GOLANGCI_LINT) run --config .golangci.yml ./...
lint-fix: lint-install ## Run golangci-lint with auto-fix
@echo "[INFO] Running golangci-lint with auto-fix..."
CGO_ENABLED=1 $(GOLANGCI_LINT) run --config .golangci.yml --fix ./...
lint-cgo: lint-install ## Run golangci-lint on CGO packages only (cephfs, kvm)
@echo "[INFO] Linting CGO-enabled packages..."
CGO_ENABLED=1 $(GOLANGCI_LINT) run --config .golangci.yml ./pkg/cephfs/...
CGO_ENABLED=1 $(GOLANGCI_LINT) run --config .golangci.yml ./pkg/kvm/...
lint-verbose: lint-install ## Run golangci-lint with verbose output
@echo "[INFO] Running golangci-lint (verbose)..."
CGO_ENABLED=1 $(GOLANGCI_LINT) run --config .golangci.yml -v ./...
##@ Code Quality
fmt: ## Run gofmt on all files
@echo "[INFO] Running gofmt..."
@gofmt -l -s -w .
fmt-check: ## Check if code is formatted (CI-friendly)
@echo "[INFO] Checking code formatting..."
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
echo "[ERROR] The following files are not formatted:"; \
echo "$$unformatted"; \
exit 1; \
else \
echo "[INFO] All files are properly formatted"; \
fi
vet: ## Run go vet
@echo "[INFO] Running go vet..."
CGO_ENABLED=1 go vet ./...
vet-cgo: ## Run go vet on CGO packages
@echo "[INFO] Running go vet on CGO packages..."
CGO_ENABLED=1 go vet ./pkg/cephfs/...
CGO_ENABLED=1 go vet ./pkg/kvm/...
imports: ## Fix import formatting
@echo "[INFO] Fixing imports..."
@if ! command -v goimports >/dev/null 2>&1; then \
echo "[INFO] Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
fi
goimports -local github.com/CodeMonkeyCybersecurity/eos -w .
##@ Pre-commit
pre-commit: fmt-check vet lint test ## Run all pre-commit checks
@echo "[INFO] All pre-commit checks passed"
pre-commit-cgo: fmt-check vet-cgo lint-cgo test-cgo ## Run pre-commit checks for CGO packages
@echo "[INFO] All CGO pre-commit checks passed"
##@ Cleanup
clean: ## Remove build artifacts
@echo "[INFO] Cleaning build artifacts..."
@rm -f $(BUILD_DIR)/$(BINARY_NAME)
@rm -f $(BUILD_DIR)/$(BINARY_NAME)-debug
@rm -f coverage.out coverage.html
@echo "[INFO] Clean complete"
clean-all: clean ## Remove all generated files including vendor
@echo "[INFO] Removing vendor directory..."
@rm -rf vendor/
@echo "[INFO] Deep clean complete"
##@ Development
deps: ## Download and verify dependencies
@echo "[INFO] Downloading dependencies..."
go mod download
go mod verify
@echo "[INFO] Dependencies verified"
deps-update: ## Update dependencies
@echo "[INFO] Updating dependencies..."
go get -u ./...
go mod tidy
@echo "[INFO] Dependencies updated"
deps-vendor: ## Vendor dependencies
@echo "[INFO] Vendoring dependencies..."
go mod vendor
@echo "[INFO] Dependencies vendored"
##@ CI/CD
ci: deps fmt-check vet lint test build ## CI pipeline (no auto-fix)
@echo "[INFO] CI pipeline complete"
ci-cgo: deps fmt-check vet-cgo lint-cgo test-cgo build ## CI pipeline for CGO packages
@echo "[INFO] CGO CI pipeline complete"
ci-preflight: ## Run CI preflight checks
@echo "[INFO] Running CI preflight..."
@scripts/ci/preflight.sh
ci-lint: ## Run CI lint lane entrypoint
@echo "[INFO] Running CI lint lane..."
@scripts/ci/lint.sh all
ci-unit: ## Run CI unit lane entrypoint
@echo "[INFO] Running CI unit lane..."
@scripts/ci/test.sh unit
ci-integration: ## Run CI integration lane entrypoint
@echo "[INFO] Running CI integration lane..."
@scripts/ci/test.sh integration
ci-e2e-smoke: ## Run CI smoke E2E lane entrypoint
@echo "[INFO] Running CI e2e smoke lane..."
@scripts/ci/test.sh e2e-smoke
ci-fuzz: ## Run CI fuzz lane entrypoint
@echo "[INFO] Running CI fuzz lane..."
@scripts/ci/test.sh fuzz
ci-coverage-delta: ## Run CI coverage delta check (PR context)
@echo "[INFO] Running CI coverage delta..."
@scripts/ci/coverage-delta.sh coverage.out
ci-debug: ## Run local CI parity lane (same command as pre-commit and CI debug job)
@echo "[INFO] Running CI debug parity lane..."
@./magew ci:debug
ci-verify-parity: ## Verify pre-commit, mage, and workflow ci:debug parity contract
@echo "[INFO] Verifying ci:debug parity contract..."
@bash scripts/ci/verify-parity.sh
governance-check: ## Run governance wiring checks from prompts submodule
@echo "[INFO] Running governance checks..."
@scripts/check-governance.sh
submodule-freshness: ## Verify prompts submodule is current with upstream main
@echo "[INFO] Checking prompts submodule freshness..."
@scripts/prompts-submodule-freshness.sh
test-submodule-freshness: ## Run submodule freshness test pyramid (unit/integration/e2e)
@echo "[INFO] Running submodule freshness test pyramid..."
@bash test/ci/test-submodule-freshness.sh
test-governance-check: ## Run governance wrapper tests
@echo "[INFO] Running governance wrapper tests..."
@bash test/ci/test-governance-check.sh
##@ Deployment
DEPLOY_SERVERS ?= vhost2
REMOTE_INSTALL_PATH := /usr/local/bin/eos
deploy: test build ## Deploy to servers (set DEPLOY_SERVERS="host1 host2")
@echo "[INFO] Deploying Eos to servers: $(DEPLOY_SERVERS)"
@for server in $(DEPLOY_SERVERS); do \
echo "[INFO] → Deploying to $$server..."; \
scp $(BUILD_DIR)/$(BINARY_NAME) $$server:/tmp/eos-new || exit 1; \
ssh $$server "sudo mv /tmp/eos-new $(REMOTE_INSTALL_PATH) && sudo chmod +x $(REMOTE_INSTALL_PATH)" || exit 1; \
version=$$(ssh $$server "$(REMOTE_INSTALL_PATH) --version 2>/dev/null || echo 'unknown'"); \
echo "[INFO] ✓ Deployed to $$server (version: $$version)"; \
done
@echo "[INFO] Deployment complete!"
deploy-check: ## Verify deployment on all servers
@echo "[INFO] Checking Eos version on servers..."
@for server in $(DEPLOY_SERVERS); do \
echo "[INFO] → Checking $$server..."; \
ssh $$server "$(REMOTE_INSTALL_PATH) --version" || echo "[ERROR] Failed to get version from $$server"; \
done
deploy-all: test build ## Deploy to all production servers
@$(MAKE) deploy DEPLOY_SERVERS="vhost2 vhost3 vhost4"
deploy-rollback: ## Rollback to previous version (if backup exists)
@echo "[INFO] Rolling back Eos on servers: $(DEPLOY_SERVERS)"
@for server in $(DEPLOY_SERVERS); do \
echo "[INFO] → Rolling back $$server..."; \
backup=$$(ssh $$server "ls -t $(REMOTE_INSTALL_PATH).backup.* 2>/dev/null | head -1"); \
if [ -z "$$backup" ]; then \
echo "[ERROR] No backup found on $$server"; \
exit 1; \
fi; \
ssh $$server "sudo cp $$backup $(REMOTE_INSTALL_PATH) && sudo chmod +x $(REMOTE_INSTALL_PATH)"; \
echo "[INFO] ✓ Rolled back to $$backup"; \
done