forked from llm-d/llm-d-inference-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
283 lines (232 loc) · 10.3 KB
/
Makefile
File metadata and controls
283 lines (232 loc) · 10.3 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
SHELL := /usr/bin/env bash
# Local directories
LOCALBIN ?= $(shell pwd)/bin
LOCALLIB ?= $(shell pwd)/lib
# Build tools and dependencies are defined in Makefile.tools.mk.
include Makefile.tools.mk
# Cluster (Kubernetes/OpenShift) specific targets are defined in Makefile.cluster.mk.
include Makefile.cluster.mk
# Kind specific targets are defined in Makefile.kind.mk.
include Makefile.kind.mk
# Defaults
TARGETOS ?= $(shell command -v go >/dev/null 2>&1 && go env GOOS || uname -s | tr '[:upper:]' '[:lower:]')
TARGETARCH ?= $(shell command -v go >/dev/null 2>&1 && go env GOARCH || uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/; s/armv7l/arm/')
PROJECT_NAME ?= llm-d-inference-scheduler
SIDECAR_IMAGE_NAME ?= llm-d-routing-sidecar
VLLM_SIMULATOR_IMAGE_NAME ?= llm-d-inference-sim
SIDECAR_NAME ?= pd-sidecar
UDS_TOKENIZER_IMAGE_NAME ?= llm-d-uds-tokenizer
IMAGE_REGISTRY ?= ghcr.io/llm-d
IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/$(PROJECT_NAME)
EPP_TAG ?= dev
export EPP_IMAGE ?= $(IMAGE_TAG_BASE):$(EPP_TAG)
SIDECAR_TAG ?= dev
SIDECAR_IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/$(SIDECAR_IMAGE_NAME)
export SIDECAR_IMAGE ?= $(SIDECAR_IMAGE_TAG_BASE):$(SIDECAR_TAG)
VLLM_SIMULATOR_TAG ?= latest
VLLM_SIMULATOR_TAG_BASE ?= $(IMAGE_REGISTRY)/$(VLLM_SIMULATOR_IMAGE_NAME)
export VLLM_SIMULATOR_IMAGE ?= $(VLLM_SIMULATOR_TAG_BASE):$(VLLM_SIMULATOR_TAG)
UDS_TOKENIZER_TAG ?= dev
UDS_TOKENIZER_TAG_BASE ?= $(IMAGE_REGISTRY)/$(UDS_TOKENIZER_IMAGE_NAME)
export UDS_TOKENIZER_IMAGE ?= $(UDS_TOKENIZER_TAG_BASE):$(UDS_TOKENIZER_TAG)
NAMESPACE ?= hc4ai-operator
LINT_NEW_ONLY ?= false # Set to true to only lint new code, false to lint all code (default matches CI behavior)
# Map go arch to platform-specific arch for typos tool
ifeq ($(TARGETOS),darwin)
ifeq ($(TARGETARCH),amd64)
TYPOS_TARGET_ARCH = x86_64
else ifeq ($(TARGETARCH),arm64)
TYPOS_TARGET_ARCH = aarch64
else
TYPOS_TARGET_ARCH = $(TARGETARCH)
endif
TAR_OPTS = --strip-components 1
TYPOS_ARCH = $(TYPOS_TARGET_ARCH)-apple-darwin
else
ifeq ($(TARGETARCH),amd64)
TYPOS_TARGET_ARCH = x86_64
else ifeq ($(TARGETARCH),arm64)
TYPOS_TARGET_ARCH = aarch64
else
TYPOS_TARGET_ARCH = $(TARGETARCH)
endif
TAR_OPTS = --wildcards '*/typos'
TYPOS_ARCH = $(TYPOS_TARGET_ARCH)-unknown-linux-musl
endif
CONTAINER_RUNTIME := $(shell { command -v docker >/dev/null 2>&1 && echo docker; } || { command -v podman >/dev/null 2>&1 && echo podman; } || echo "")
export CONTAINER_RUNTIME
BUILDER := $(shell command -v buildah >/dev/null 2>&1 && echo buildah || echo $(CONTAINER_RUNTIME))
PLATFORMS ?= linux/amd64 # linux/arm64 # linux/s390x,linux/ppc64le
GIT_COMMIT_SHA ?= "$(shell git rev-parse HEAD 2>/dev/null)"
BUILD_REF ?= $(shell git describe --abbrev=0 2>/dev/null)
# go source files
SRC = $(shell find . -type f -name '*.go')
# CGO_ENABLED=1 is required for ZMQ (linking handled via pkg-config)
CGO_ENABLED=1
# Internal variables for generic targets
epp_IMAGE = $(EPP_IMAGE)
sidecar_IMAGE = $(SIDECAR_IMAGE)
epp_NAME = epp
sidecar_NAME = $(SIDECAR_NAME)
epp_TEST_FILES = go list ./... | grep -v /test/ | grep -v ./pkg/sidecar/
sidecar_TEST_FILES = go list ./pkg/sidecar/...
.PHONY: help
help: ## Print help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: clean
clean: ## Clean build artifacts, tools and caches
go clean -testcache -cache
rm -rf $(LOCALLIB) $(LOCALBIN) build
.PHONY: format
format: check-golangci-lint ## Format Go source files
@printf "\033[33;1m==== Running go fmt ====\033[0m\n"
@gofmt -l -w $(SRC)
$(GOLANGCI_LINT) fmt
.PHONY: lint
lint: check-golangci-lint check-typos ## Run lint (use LINT_NEW_ONLY=true to only check new code)
@printf "\033[33;1m==== Running linting ====\033[0m\n"
@if [ "$(LINT_NEW_ONLY)" = "true" ]; then \
printf "\033[33mChecking new code only (LINT_NEW_ONLY=true)\033[0m\n"; \
$(GOLANGCI_LINT) run --new; \
else \
printf "\033[33mChecking all code (LINT_NEW_ONLY=false, default)\033[0m\n"; \
$(GOLANGCI_LINT) run; \
fi
$(TYPOS)
.PHONY: install-hooks
install-hooks: ## Install git hooks
git config core.hooksPath hooks
.PHONY: test
test: test-unit test-e2e ## Run all tests (unit and e2e)
.PHONY: test-unit
test-unit: test-unit-epp test-unit-sidecar ## Run unit tests
.PHONY: test-unit-%
test-unit-%: check-dependencies ## Run unit tests
@printf "\033[33;1m==== Running Unit Tests ====\033[0m\n"
@go test -v $$($($*_TEST_FILES) | tr '\n' ' ')
.PHONY: test-filter
test-filter: check-dependencies ## Run filtered unit tests (usage: make test-filter PATTERN=TestName TYPE=epp)
@if [ -z "$(PATTERN)" ]; then \
echo "ERROR: PATTERN is required. Usage: make test-filter PATTERN=TestName [TYPE=epp|sidecar]"; \
exit 1; \
fi
@TEST_TYPE="$(if $(TYPE),$(TYPE),epp)"; \
printf "\033[33;1m==== Running Filtered Tests (pattern: $(PATTERN), type: $$TEST_TYPE) ====\033[0m\n"; \
if [ "$$TEST_TYPE" = "epp" ]; then \
go test -v -run "$(PATTERN)" $$($(epp_TEST_FILES) | tr '\n' ' '); \
else \
go test -v -run "$(PATTERN)" $$($(sidecar_TEST_FILES) | tr '\n' ' '); \
fi
.PHONY: test-integration
test-integration: check-dependencies ## Run integration tests
@printf "\033[33;1m==== Running Integration Tests ====\033[0m\n"
go test -v -tags=integration_tests ./test/integration/
.PHONY: test-e2e
test-e2e: image-build image-build-uds-tokenizer image-pull ## Run end-to-end tests against a new kind cluster
@printf "\033[33;1m==== Running End to End Tests ====\033[0m\n"
PATH=$(LOCALBIN):$$PATH ./test/scripts/run_e2e.sh
.PHONY: post-deploy-test
post-deploy-test: ## Run post deployment tests
echo Success!
@echo "Post-deployment tests passed."
##@ Build
.PHONY: build
build: build-epp build-sidecar ## Build the project for both epp and sidecar
.PHONY: build-%
build-%: check-go ## Build the project
@printf "\033[33;1m==== Building ====\033[0m\n"
@go build -o bin/$($*_NAME) cmd/$($*_NAME)/main.go
##@ Container image Build/Push/Pull
.PHONY: image-build
image-build: image-build-epp image-build-sidecar ## Build Container image using $(CONTAINER_RUNTIME)
# Path to kv-cache repo for UDS tokenizer image build (can be overridden)
KV_CACHE_PATH ?= $(shell go list -m -f '{{.Dir}}' github.com/llm-d/llm-d-kv-cache 2>/dev/null)
.PHONY: image-build-uds-tokenizer
image-build-uds-tokenizer: check-container-tool ## Build UDS tokenizer image from kv-cache
@printf "\033[33;1m==== Building UDS Tokenizer image $(UDS_TOKENIZER_IMAGE) ====\033[0m\n"
@if [ -z "$(KV_CACHE_PATH)" ]; then \
echo "kv-cache module not found, downloading Go modules..."; \
go mod download; \
fi
@KV_CACHE_PATH_CHECK=$$(go list -m -f '{{.Dir}}' github.com/llm-d/llm-d-kv-cache 2>/dev/null); \
if [ -z "$$KV_CACHE_PATH_CHECK" ]; then \
echo "Error: Could not find kv-cache module even after download."; \
exit 1; \
fi
$(CONTAINER_RUNTIME) build \
--platform linux/$(TARGETARCH) \
-t $(UDS_TOKENIZER_IMAGE) \
-f $(KV_CACHE_PATH)/services/uds_tokenizer/Dockerfile \
$(KV_CACHE_PATH)/services/uds_tokenizer
.PHONY: image-build-%
image-build-%: check-container-tool ## Build Container image using $(CONTAINER_RUNTIME)
@printf "\033[33;1m==== Building Docker image $($*_IMAGE) ====\033[0m\n"
$(CONTAINER_RUNTIME) build \
--platform linux/$(TARGETARCH) \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(TARGETARCH) \
--build-arg COMMIT_SHA=${GIT_COMMIT_SHA} \
--build-arg BUILD_REF=${BUILD_REF} \
-t $($*_IMAGE) -f Dockerfile.$* .
.PHONY: image-push
image-push: image-push-epp image-push-sidecar ## Push container images to registry using $(CONTAINER_RUNTIME)
.PHONY: image-push-%
image-push-%: check-container-tool ## Push container image to registry using $(CONTAINER_RUNTIME)
@printf "\033[33;1m==== Pushing Container image $($*_IMAGE) ====\033[0m\n"
$(CONTAINER_RUNTIME) push $($*_IMAGE)
.PHONY: image-pull
image-pull: check-container-tool ## Pull all related images using $(CONTAINER_RUNTIME)
@printf "\033[33;1m==== Pulling Container images ====\033[0m\n"
./scripts/pull_images.sh
##@ Container Run
.PHONY: run-container
run-container: check-container-tool ## Run app in container using $(CONTAINER_RUNTIME)
@echo "Starting container with $(CONTAINER_RUNTIME)..."
$(CONTAINER_RUNTIME) run -d --name $(PROJECT_NAME)-container $(EPP_IMAGE)
@echo "$(CONTAINER_RUNTIME) started successfully."
@echo "To use $(PROJECT_NAME), run:"
@echo "alias $(PROJECT_NAME)='$(CONTAINER_RUNTIME) exec -it $(PROJECT_NAME)-container /app/$(PROJECT_NAME)'"
.PHONY: stop-container
stop-container: check-container-tool ## Stop and remove container
@echo "Stopping and removing container..."
$(CONTAINER_RUNTIME) stop $(PROJECT_NAME)-container && $(CONTAINER_RUNTIME) rm $(PROJECT_NAME)-container
@echo "$(CONTAINER_RUNTIME) stopped and removed. Remove alias if set: unalias $(PROJECT_NAME)"
##@ Environment
.PHONY: env
env: ## Print environment variables
@echo "TARGETOS=$(TARGETOS)"
@echo "TARGETARCH=$(TARGETARCH)"
@echo "CONTAINER_RUNTIME=$(CONTAINER_RUNTIME)"
@echo "IMAGE_TAG_BASE=$(IMAGE_TAG_BASE)"
@echo "EPP_TAG=$(EPP_TAG)"
@echo "EPP_IMAGE=$(EPP_IMAGE)"
@echo "SIDECAR_TAG=$(SIDECAR_TAG)"
@echo "SIDECAR_IMAGE=$(SIDECAR_IMAGE)"
@echo "VLLM_SIMULATOR_TAG=$(VLLM_SIMULATOR_TAG)"
@echo "VLLM_SIMULATOR_IMAGE=$(VLLM_SIMULATOR_IMAGE)"
@echo "UDS_TOKENIZER_TAG=$(UDS_TOKENIZER_TAG)"
@echo "UDS_TOKENIZER_IMAGE=$(UDS_TOKENIZER_IMAGE)"
.PHONY: print-namespace
print-namespace: ## Print the current namespace
@echo "$(NAMESPACE)"
.PHONY: print-project-name
print-project-name: ## Print the current project name
@echo "$(PROJECT_NAME)"
##@ Deprecated aliases for backwards compatibility
.PHONY: install-docker
install-docker: ## DEPRECATED: Use 'make run-container' instead
@echo "WARNING: 'make install-docker' is deprecated. Use 'make run-container' instead."
@$(MAKE) run-container
.PHONY: uninstall-docker
uninstall-docker: ## DEPRECATED: Use 'make stop-container' instead
@echo "WARNING: 'make uninstall-docker' is deprecated. Use 'make stop-container' instead."
@$(MAKE) stop-container
.PHONY: install
install: ## DEPRECATED: Use 'make run-container' instead
@echo "WARNING: 'make install' is deprecated. Use 'make run-container' instead."
@$(MAKE) run-container
.PHONY: uninstall
uninstall: ## DEPRECATED: Use 'make stop-container' instead
@echo "WARNING: 'make uninstall' is deprecated. Use 'make stop-container' instead."
@$(MAKE) stop-container