Repository navigation
Expand file tree
/
Copy pathgo.Makefile
More file actions
255 lines (216 loc) · 9.19 KB
/
Copy pathgo.Makefile
File metadata and controls
255 lines (216 loc) · 9.19 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
# Common Go Makefile for Flyte services
# Include this file in service-specific Makefiles and set the required variables:
# SERVICE_NAME - Name of the service (e.g., "manager", "runs", "queue")
# CMD_PATH - Path to main.go relative to service directory (default: cmd/main.go)
# BIN_DIR - Directory for binaries (default: bin)
# Set defaults
CMD_PATH ?= cmd/main.go
BIN_DIR ?= bin
BIN_NAME ?= $(SERVICE_NAME)
GOLANGCI_LINT_VERSION ?= v2.14.0
LOCALBIN ?= $(shell pwd)/bin
APPLE_SILICON_PORT ?= 30090
APPLE_SILICON_DIR := $(HOME)/.flyte/apple-silicon
APPLE_SILICON_CONFIG := $(APPLE_SILICON_DIR)/$(SERVICE_NAME)-config.yaml
# Non-empty when APPLE_SILICON is "true", matched case-insensitively like FLYTE_DEV.
APPLE_SILICON_ENABLED = $(filter true,$(shell echo '$(APPLE_SILICON)' | tr '[:upper:]' '[:lower:]'))
# ANSI color codes for prettier output
COLOR_RESET := \033[0m
COLOR_BOLD := \033[1m
COLOR_GREEN := \033[32m
COLOR_YELLOW := \033[33m
COLOR_BLUE := \033[36m
##@ General
.PHONY: help
help: ## Display this help message
@echo ''
@echo '$(COLOR_BOLD)Usage:$(COLOR_RESET)'
@echo ' make $(COLOR_BLUE)<target>$(COLOR_RESET)'
@echo ''
@echo '$(COLOR_BOLD)Available targets:$(COLOR_RESET)'
@awk 'BEGIN {FS = ":.*##"; printf ""} \
/^[a-zA-Z_0-9-]+:.*?##/ { printf " $(COLOR_BLUE)%-20s$(COLOR_RESET) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(COLOR_BOLD)%s$(COLOR_RESET)\n", substr($$0, 5) } ' \
$(MAKEFILE_LIST)
##@ Development
.PHONY: fmt
fmt: ## Run go fmt to format code
@echo "$(COLOR_GREEN)Formatting Go code...$(COLOR_RESET)"
@go fmt ./...
.PHONY: vet
vet: ## Run go vet to examine code
@echo "$(COLOR_GREEN)Running go vet...$(COLOR_RESET)"
@go vet ./...
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter (skips *_test.go files)
@echo "$(COLOR_GREEN)Running golangci-lint (skipping tests)...$(COLOR_RESET)"
@$(GOLANGCI_LINT) run --tests=false
.PHONY: lint-all
lint-all: golangci-lint ## Run golangci-lint linter (includes all files)
@echo "$(COLOR_GREEN)Running golangci-lint (including tests)...$(COLOR_RESET)"
@$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint and automatically fix issues (skips *_test.go files)
@echo "$(COLOR_GREEN)Running golangci-lint with auto-fix (skipping tests)...$(COLOR_RESET)"
@$(GOLANGCI_LINT) run --fix --tests=false
.PHONY: tidy
tidy: ## Run go mod tidy to clean up dependencies
@echo "$(COLOR_GREEN)Tidying Go modules...$(COLOR_RESET)"
@go mod tidy
.PHONY: verify
verify: fmt vet ## Run fmt and vet
@echo "$(COLOR_GREEN)Code verification complete$(COLOR_RESET)"
##@ Build
.PHONY: build
build: verify ## Build the service binary
@echo "$(COLOR_GREEN)Building $(SERVICE_NAME)...$(COLOR_RESET)"
@mkdir -p $(BIN_DIR)
@go build -o $(BIN_DIR)/$(BIN_NAME) $(CMD_PATH)
@echo "$(COLOR_GREEN)Built: $(BIN_DIR)/$(BIN_NAME)$(COLOR_RESET)"
.PHONY: build-fast
build-fast: ## Build without verification (faster)
@echo "$(COLOR_GREEN)Building $(SERVICE_NAME) (fast mode)...$(COLOR_RESET)"
@mkdir -p $(BIN_DIR)
@go build -o $(BIN_DIR)/$(BIN_NAME) $(CMD_PATH)
@echo "$(COLOR_GREEN)Built: $(BIN_DIR)/$(BIN_NAME)$(COLOR_RESET)"
.PHONY: install
install: build ## Build and install binary to $GOPATH/bin
@echo "$(COLOR_GREEN)Installing $(SERVICE_NAME)...$(COLOR_RESET)"
@go install $(CMD_PATH)
##@ Testing
.PHONY: test
test: ## Run unit tests
@echo "$(COLOR_GREEN)Running tests...$(COLOR_RESET)"
@go test -v -race -cover ./...
.PHONY: test-short
test-short: ## Run unit tests (short mode)
@echo "$(COLOR_GREEN)Running tests (short mode)...$(COLOR_RESET)"
@go test -short -v ./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage report
@echo "$(COLOR_GREEN)Running tests with coverage...$(COLOR_RESET)"
@go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "$(COLOR_GREEN)Coverage report generated: coverage.html$(COLOR_RESET)"
.PHONY: bench
bench: ## Run benchmarks
@echo "$(COLOR_GREEN)Running benchmarks...$(COLOR_RESET)"
@go test -bench=. -benchmem ./...
##@ Running
.PHONY: run
run: build-fast ## Build and run the service
@echo "$(COLOR_GREEN)Running $(SERVICE_NAME)...$(COLOR_RESET)"
@if [ -z "$(APPLE_SILICON_ENABLED)" ]; then \
./$(BIN_DIR)/$(BIN_NAME) $(RUN_ARGS); \
else \
$(MAKE) --no-print-directory apple-silicon-config && \
./$(BIN_DIR)/$(BIN_NAME) --config $(APPLE_SILICON_CONFIG); \
fi
.PHONY: run-dev
run-dev: ## Run service directly with go run (no build)
@echo "$(COLOR_GREEN)Running $(SERVICE_NAME) (dev mode)...$(COLOR_RESET)"
@if [ -z "$(APPLE_SILICON_ENABLED)" ]; then \
go run $(CMD_PATH) $(RUN_ARGS); \
else \
$(MAKE) --no-print-directory apple-silicon-config && \
go run $(CMD_PATH) --config $(APPLE_SILICON_CONFIG); \
fi
.PHONY: apple-silicon-config
apple-silicon-config: ## Generate a config with the MLX bridge settings
@if [ ! -s $(APPLE_SILICON_DIR)/secret ]; then \
echo "$(APPLE_SILICON_DIR)/secret not found, run 'make devbox-run FLYTE_DEV=True APPLE_SILICON=True' first"; \
exit 1; \
fi
@ip=$$(docker exec flyte-devbox cat /etc/hosts | awk '$$2 == "host.docker.internal" { print $$1; exit }'); \
if [ -z "$$ip" ]; then \
echo "host.docker.internal not found in flyte-devbox, is the devbox running?"; \
exit 1; \
fi; \
type=$$(kubectl --context flyte-devbox -n flyte get svc flyte-binary-http -o jsonpath='{.spec.type}' 2>/dev/null); \
if [ -z "$$type" ]; then \
kubectl --context flyte-devbox -n flyte create service externalname flyte-binary-http \
--external-name flyte-devbox-local.flyte.svc.cluster.local --tcp 8090:8090 >/dev/null || exit 1; \
echo "Created flyte-binary-http in flyte-devbox, pointing at the manager on the host"; \
elif [ "$$type" != ExternalName ]; then \
echo "flyte-binary-http is already served inside flyte-devbox, run 'make devbox-run FLYTE_DEV=True APPLE_SILICON=True' first"; \
exit 1; \
fi; \
if ! grep -q '^ k8s:$$' config.yaml; then \
echo "Error: no ' k8s:' line in config.yaml to add apple-silicon-bridge under, failed to create $(APPLE_SILICON_CONFIG)"; \
exit 1; \
fi; \
if ! grep -q 'rustfs-svc\.flyte\.svc\.cluster\.local:9000' config.yaml; then \
echo "Error: no 'rustfs-svc.flyte.svc.cluster.local:9000' in config.yaml to replace, failed to create $(APPLE_SILICON_CONFIG)"; \
exit 1; \
fi; \
if ! grep '_U_EP_OVERRIDE' config.yaml | grep -q 'host\.docker\.internal:8090'; then \
echo "Error: no '_U_EP_OVERRIDE' with 'host.docker.internal:8090' in config.yaml to replace, failed to create $(APPLE_SILICON_CONFIG)"; \
exit 1; \
fi; \
umask 077; \
{ \
echo ' apple-silicon-bridge:'; \
echo " endpoint: \"http://$$ip:$(APPLE_SILICON_PORT)\""; \
echo " token-secret: \"$$(cat $(APPLE_SILICON_DIR)/secret)\""; \
echo ' host-platform: "darwin/arm64"'; \
} | sed -e '/^ k8s:$$/r /dev/stdin' \
-e 's|rustfs-svc\.flyte\.svc\.cluster\.local:9000|rustfs-svc.flyte:9000|' \
-e '/_U_EP_OVERRIDE/s|host\.docker\.internal:8090|flyte-binary-http.flyte:8090|' \
config.yaml > $(APPLE_SILICON_CONFIG); \
echo "Apple MLX bridge config set successfully, at $(APPLE_SILICON_CONFIG)"
##@ Cleanup
.PHONY: clean
clean: ## Remove build artifacts
@echo "$(COLOR_YELLOW)Cleaning build artifacts...$(COLOR_RESET)"
@rm -rf $(BIN_DIR)
@rm -f coverage.out coverage.html
@echo "$(COLOR_GREEN)Clean complete$(COLOR_RESET)"
.PHONY: clean-all
clean-all: clean ## Remove build artifacts and installed tools
@echo "$(COLOR_YELLOW)Cleaning all artifacts and tools...$(COLOR_RESET)"
@rm -rf $(LOCALBIN)
@echo "$(COLOR_GREEN)Clean complete$(COLOR_RESET)"
##@ Dependencies
.PHONY: deps
deps: ## Download dependencies
@echo "$(COLOR_GREEN)Downloading dependencies...$(COLOR_RESET)"
@go mod download
.PHONY: deps-upgrade
deps-upgrade: ## Upgrade all dependencies
@echo "$(COLOR_GREEN)Upgrading dependencies...$(COLOR_RESET)"
@go get -u ./...
@go mod tidy
##@ Tools
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary
$(GOLANGCI_LINT): $(LOCALBIN)
@echo "$(COLOR_GREEN)Installing golangci-lint $(GOLANGCI_LINT_VERSION)...$(COLOR_RESET)"
@$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(LOCALBIN):
@mkdir -p $(LOCALBIN)
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo " Downloading $${package}" ;\
rm -f $(1) ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $$(basename $(1)-$(3)) $(1)
endef
##@ Info
.PHONY: info
info: ## Display service information
@echo "$(COLOR_BOLD)Service Information:$(COLOR_RESET)"
@echo " Service Name: $(COLOR_BLUE)$(SERVICE_NAME)$(COLOR_RESET)"
@echo " Binary Name: $(COLOR_BLUE)$(BIN_NAME)$(COLOR_RESET)"
@echo " Binary Path: $(COLOR_BLUE)$(BIN_DIR)/$(BIN_NAME)$(COLOR_RESET)"
@echo " CMD Path: $(COLOR_BLUE)$(CMD_PATH)$(COLOR_RESET)"
@echo " Go Version: $(COLOR_BLUE)$$(go version | cut -d' ' -f3)$(COLOR_RESET)"
.DEFAULT_GOAL := help