-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
236 lines (202 loc) · 8.24 KB
/
Makefile
File metadata and controls
236 lines (202 loc) · 8.24 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
# FL-Go Makefile
# A Go implementation of OpenFL - An Open Framework for Federated Learning
.PHONY: help build clean test run-aggregator run-collaborator run-demo workspace-init workspace-clean deps proto lint format docker-build docker-run
# Variables
BINARY_NAME=fx
BUILD_DIR=build
WORKSPACE_NAME=fl_workspace
DOCKER_IMAGE=fl-go
DOCKER_TAG=latest
# Default target
help: ## Show this help message
@echo "FL-Go - A Go implementation of OpenFL"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Examples:"
@echo " make build # Build the fx binary"
@echo " make workspace-init # Initialize a new FL workspace"
@echo " make run-demo # Run a complete FL demo"
@echo " make clean # Clean build artifacts"
# Build targets
build: ## Build the fx binary
@echo "🔨 Building FL-Go binary..."
@mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR)/$(BINARY_NAME) cmd/fx/main.go
@echo "✅ Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-race: ## Build with race detection
@echo "🔨 Building with race detection..."
@mkdir -p $(BUILD_DIR)
go build -race -o $(BUILD_DIR)/$(BINARY_NAME) cmd/fx/main.go
@echo "✅ Binary built with race detection"
build-debug: ## Build with debug symbols
@echo "🔨 Building with debug symbols..."
@mkdir -p $(BUILD_DIR)
go build -gcflags="all=-N -l" -o $(BUILD_DIR)/$(BINARY_NAME) cmd/fx/main.go
@echo "✅ Binary built with debug symbols"
# Clean targets
clean: ## Clean build artifacts
@echo "🧹 Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@go clean
@echo "✅ Cleaned build artifacts"
workspace-clean: ## Clean workspace directories
@echo "🧹 Cleaning workspace directories..."
@rm -rf $(WORKSPACE_NAME) large_model_test test_workspace
@echo "✅ Cleaned workspace directories"
clean-all: clean workspace-clean ## Clean everything
@echo "✅ Cleaned everything"
# Development targets
deps: ## Install dependencies
@echo "📦 Installing dependencies..."
go mod download
go mod tidy
@echo "✅ Dependencies installed"
proto: ## Generate protobuf code
@echo "🔧 Generating protobuf code..."
@if ! command -v protoc > /dev/null; then \
echo "❌ protoc not found. Please install Protocol Buffers compiler."; \
exit 1; \
fi
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
api/federation.proto
@echo "✅ Protobuf code generated"
lint: ## Run linter
@echo "🔍 Running linter..."
@if ! command -v golangci-lint > /dev/null; then \
echo "❌ golangci-lint not found. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
golangci-lint run
@echo "✅ Linting completed"
format: ## Format code
@echo "🎨 Formatting code..."
go fmt ./...
@echo "✅ Code formatted"
# Workspace management
workspace-init: build ## Initialize a new FL workspace
@echo "🚀 Initializing new FL workspace..."
./$(BUILD_DIR)/$(BINARY_NAME) plan init --name $(WORKSPACE_NAME)
@echo "✅ Workspace initialized: $(WORKSPACE_NAME)"
workspace-init-large: build ## Initialize workspace with large model
@echo "🚀 Initializing workspace with large model..."
./$(BUILD_DIR)/$(BINARY_NAME) plan init --name large_model_test
@echo "✅ Large model workspace initialized: large_model_test"
# Run targets
run-aggregator: build ## Run aggregator (requires workspace)
@echo "🎯 Starting aggregator..."
@if [ ! -f "plan.yaml" ]; then \
echo "❌ No plan.yaml found. Run 'make workspace-init' first."; \
exit 1; \
fi
./$(BUILD_DIR)/$(BINARY_NAME) aggregator start
run-collaborator: build ## Run collaborator (requires workspace and collaborator name)
@echo "🤝 Starting collaborator..."
@if [ ! -f "plan.yaml" ]; then \
echo "❌ No plan.yaml found. Run 'make workspace-init' first."; \
exit 1; \
fi
@if [ -z "$(COLLAB_ID)" ]; then \
echo "❌ Please specify COLLAB_ID. Example: make run-collaborator COLLAB_ID=collaborator1"; \
exit 1; \
fi
./$(BUILD_DIR)/$(BINARY_NAME) collaborator start $(COLLAB_ID)
# Demo targets
run-demo: build workspace-init ## Run a complete FL demo
@echo "🎬 Starting FL-Go demo..."
@cd $(WORKSPACE_NAME) && \
echo "🚀 Starting aggregator..." && \
../$(BUILD_DIR)/$(BINARY_NAME) aggregator start > aggregator.log 2>&1 & \
AGG_PID=$$! && \
sleep 3 && \
echo "🤝 Starting collaborator 1..." && \
../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator1 > collab1.log 2>&1 & \
COLLAB1_PID=$$! && \
sleep 2 && \
echo "🤝 Starting collaborator 2..." && \
../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator2 > collab2.log 2>&1 & \
COLLAB2_PID=$$! && \
echo "⏳ Waiting for training to complete..." && \
wait $$COLLAB1_PID $$COLLAB2_PID && \
kill $$AGG_PID 2>/dev/null || true && \
echo "✅ Demo completed! Check logs in $(WORKSPACE_NAME)/"
run-demo-large: build workspace-init-large ## Run demo with large model
@echo "🎬 Starting FL-Go large model demo..."
@cd large_model_test && \
echo "🚀 Starting aggregator..." && \
../$(BUILD_DIR)/$(BINARY_NAME) aggregator start > aggregator.log 2>&1 & \
AGG_PID=$$! && \
sleep 3 && \
echo "🤝 Starting collaborator 1..." && \
../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator1 > collab1.log 2>&1 & \
COLLAB1_PID=$$! && \
sleep 2 && \
echo "🤝 Starting collaborator 2..." && \
../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator2 > collab2.log 2>&1 & \
COLLAB2_PID=$$! && \
echo "⏳ Waiting for training to complete..." && \
wait $$COLLAB1_PID $$COLLAB2_PID && \
kill $$AGG_PID 2>/dev/null || true && \
echo "✅ Large model demo completed! Check logs in large_model_test/"
# Test targets
test: ## Run tests
@echo "🧪 Running tests..."
go test -v ./...
@echo "✅ Tests completed"
test-race: ## Run tests with race detection
@echo "🧪 Running tests with race detection..."
go test -race -v ./...
@echo "✅ Tests with race detection completed"
test-coverage: ## Run tests with coverage
@echo "🧪 Running tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "✅ Coverage report generated: coverage.html"
# Docker targets
docker-build: ## Build Docker image
@echo "🐳 Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
@echo "✅ Docker image built: $(DOCKER_IMAGE):$(DOCKER_TAG)"
docker-run: docker-build ## Run in Docker
@echo "🐳 Running in Docker..."
docker run -it --rm $(DOCKER_IMAGE):$(DOCKER_TAG)
docker-compose-up: ## Start FL-Go with Docker Compose
@echo "🐳 Starting FL-Go with Docker Compose..."
docker-compose up --build
docker-compose-down: ## Stop Docker Compose services
@echo "🐳 Stopping Docker Compose services..."
docker-compose down
docker-compose-logs: ## Show Docker Compose logs
@echo "🐳 Showing Docker Compose logs..."
docker-compose logs -f
docker-shell: ## Start development shell in Docker
@echo "🐳 Starting development shell in Docker..."
docker-compose run --rm dev-shell
# Utility targets
install: build ## Install binary to system
@echo "📦 Installing binary..."
@sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
@echo "✅ Binary installed to /usr/local/bin/$(BINARY_NAME)"
uninstall: ## Uninstall binary
@echo "🗑️ Uninstalling binary..."
@sudo rm -f /usr/local/bin/$(BINARY_NAME)
@echo "✅ Binary uninstalled"
version: ## Show version information
@echo "FL-Go version information:"
@echo " Go version: $(shell go version)"
@echo " Git commit: $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
@echo " Build time: $(shell date)"
# Development workflow
dev-setup: deps proto lint format ## Setup development environment
@echo "✅ Development environment setup complete"
dev-build: dev-setup build ## Build with all development checks
@echo "✅ Development build complete"
# Quick commands
demo: run-demo ## Alias for run-demo
demo-large: run-demo-large ## Alias for run-demo-large
collab1: build ## Quick start collaborator1
@cd $(WORKSPACE_NAME) && ../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator1
collab2: build ## Quick start collaborator2
@cd $(WORKSPACE_NAME) && ../$(BUILD_DIR)/$(BINARY_NAME) collaborator start collaborator2