Makefile 6.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# Dynamo EPP Makefile
# Builds custom EPP image with Dynamo KV-aware routing plugins

# Image configuration
DOCKER_SERVER ?= dynamo
IMAGE_NAME := dynamo-epp
GIT_COMMIT_SHA ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
GIT_TAG ?= $(shell git describe --tags --dirty --always 2>/dev/null || echo "dev")
IMAGE_REPO ?= $(DOCKER_SERVER)/$(IMAGE_NAME)
IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG)

# Build configuration
13
14
# PLATFORMS: defaults to host arch for fast local builds (image-load, image-kind)
# MULTIARCH_PLATFORMS: used by image-multiarch for multi-architecture manifests
15
16
17
18
19
20
21
22
23
24
HOST_ARCH := $(shell uname -m)
ifeq ($(HOST_ARCH),x86_64)
    PLATFORMS ?= linux/amd64
else ifeq ($(HOST_ARCH),aarch64)
    PLATFORMS ?= linux/arm64
else ifeq ($(HOST_ARCH),arm64)
    PLATFORMS ?= linux/arm64
else
    PLATFORMS ?= linux/amd64
endif
25
MULTIARCH_PLATFORMS ?= linux/amd64,linux/arm64
26
27
# Docker proxy for avoiding rate limits (e.g., ECR mirror)
DOCKER_PROXY ?=
28
EXTRA_BUILD_ARGS ?=
29

30
31
32
33
34
35
# sccache configuration for Rust compilation caching (CI only).
# Leave USE_SCCACHE unset locally to build without S3 cache.
USE_SCCACHE ?=
SCCACHE_BUCKET ?=
SCCACHE_REGION ?=

36
37
DOCKER_BUILDX_CMD ?= docker buildx
IMAGE_BUILD_CMD ?= $(DOCKER_BUILDX_CMD) build
38
RUST_IMAGE ?= $(DOCKER_PROXY)rust:1.93.1
39
BUILDER_IMAGE ?= $(DOCKER_PROXY)golang:1.25
40
41
42
43
44
45
46
47
48
49
50
BASE_IMAGE ?= $(DOCKER_PROXY)ubuntu:24.04

# Container tool
CONTAINER_TOOL ?= docker

# Kind cluster name for local testing
KIND_CLUSTER ?= kind

# Project directory
PROJECT_DIR := $(shell pwd)

51
# Dynamo repository root (build context for Docker)
52
DYNAMO_DIR ?= $(shell cd $(PROJECT_DIR)/../../.. && pwd)
53
54

# Local development paths (for host-native builds only, not used by Docker)
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
DYNAMO_LIB_DIR := $(PROJECT_DIR)/pkg/plugins/dynamo_kv_scorer/lib
DYNAMO_INCLUDE_DIR := $(PROJECT_DIR)/pkg/plugins/dynamo_kv_scorer/include

.PHONY: help
help: ## Display this help
	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf "  \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.PHONY: fmt
fmt: ## Run go fmt
	go fmt ./...

.PHONY: vet
vet: ## Run go vet
	go vet ./...

.PHONY: tidy
tidy: ## Run go mod tidy
	go mod tidy

.PHONY: test
test: ## Run tests
	CGO_ENABLED=1 go test ./... -v

##@ Build

.PHONY: build
build: dynamo-lib-check ## Build the EPP binary locally (requires CGO and Dynamo libraries)
	CGO_ENABLED=1 go build -o bin/epp ./cmd/epp

.PHONY: build-with-lib
build-with-lib: dynamo-lib build ## Build Dynamo library and EPP binary

.PHONY: image-build
90
image-build: ## Build the Docker image (self-contained, no host prerequisites)
91
92
	$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
		--platform=$(PLATFORMS) \
93
94
		--build-context dynamo=$(DYNAMO_DIR) \
		--build-arg RUST_IMAGE=$(RUST_IMAGE) \
95
96
97
98
		--build-arg BASE_IMAGE=$(BASE_IMAGE) \
		--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
		--build-arg COMMIT_SHA=$(GIT_COMMIT_SHA) \
		--build-arg BUILD_REF=$(GIT_TAG) \
99
		$(EXTRA_BUILD_ARGS) $(PUSH) $(LOAD) .
100
101
102
103
104
105
106
107
108
109
110
111
112

.PHONY: image-push
image-push: PUSH=--push ## Build and push the Docker image
image-push: image-build

.PHONY: image-load
image-load: LOAD=--load ## Build and load the Docker image locally
image-load: image-build

.PHONY: image-kind
image-kind: image-load ## Build and load the image into kind cluster
	kind load docker-image $(IMAGE_TAG) --name $(KIND_CLUSTER)

113
114
##@ Multi-Architecture Builds

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Collect sccache args only when USE_SCCACHE=true. IRSA secrets come from the
# runner env (AWS_WEB_IDENTITY_TOKEN_FILE + AWS_ROLE_ARN); buildx mounts them
# into the RUN step that invokes cargo so sccache can authenticate to S3.
SCCACHE_ARGS =
ifeq ($(USE_SCCACHE),true)
  SCCACHE_ARGS += --build-arg USE_SCCACHE=true
  SCCACHE_ARGS += --build-arg SCCACHE_BUCKET=$(SCCACHE_BUCKET)
  SCCACHE_ARGS += --build-arg SCCACHE_REGION=$(SCCACHE_REGION)
  ifneq ($(AWS_WEB_IDENTITY_TOKEN_FILE),)
    ifneq ($(AWS_ROLE_ARN),)
      SCCACHE_ARGS += --secret id=aws-web-identity-token,src=$(AWS_WEB_IDENTITY_TOKEN_FILE)
      SCCACHE_ARGS += --secret id=aws-role-arn,env=AWS_ROLE_ARN
    endif
  endif
endif

131
132
133
134
135
136
137
138
139
140
.PHONY: image-multiarch
image-multiarch: ## Build multi-arch image (requires --push ; --load not supported)
	$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
		--platform=$(MULTIARCH_PLATFORMS) \
		--build-context dynamo=$(DYNAMO_DIR) \
		--build-arg RUST_IMAGE=$(RUST_IMAGE) \
		--build-arg BASE_IMAGE=$(BASE_IMAGE) \
		--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
		--build-arg COMMIT_SHA=$(GIT_COMMIT_SHA) \
		--build-arg BUILD_REF=$(GIT_TAG) \
141
		$(SCCACHE_ARGS) $(EXTRA_BUILD_ARGS) $(PUSH) .
142
143
144
145
146
147

.PHONY: image-multiarch-push
image-multiarch-push: PUSH=--push ## Build and push multi-arch image to registry
image-multiarch-push: image-multiarch


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
##@ Local Development with Buildx

.PHONY: image-local-build
image-local-build: ## Build image using a new buildx builder
	BUILDER=$$($(DOCKER_BUILDX_CMD) create --use) && \
	$(MAKE) image-build PUSH=$(PUSH) LOAD=$(LOAD) && \
	$(DOCKER_BUILDX_CMD) rm $$BUILDER

.PHONY: image-local-push
image-local-push: PUSH=--push ## Build and push using local buildx builder
image-local-push: image-local-build

.PHONY: image-local-load
image-local-load: LOAD=--load ## Build and load using local buildx builder
image-local-load: image-local-build

164
##@ Dynamo Library (for local host-native builds only)
165
166

.PHONY: dynamo-lib
167
dynamo-lib: ## Build Dynamo static library and copy to project (for local dev)
168
169
170
171
172
173
174
175
176
177
	@echo "Building Dynamo static library..."
	cd "$(DYNAMO_DIR)" && cargo build --release -p libdynamo_llm
	@echo "Copying files to EPP project..."
	@mkdir -p "$(DYNAMO_LIB_DIR)"
	@mkdir -p "$(DYNAMO_INCLUDE_DIR)"
	cp "$(DYNAMO_DIR)/lib/bindings/c/include/nvidia/dynamo_llm/llm_engine.h" "$(DYNAMO_INCLUDE_DIR)/"
	cp "$(DYNAMO_DIR)/target/release/libdynamo_llm_capi.a" "$(DYNAMO_LIB_DIR)/"
	@echo "Dynamo library ready!"

.PHONY: dynamo-lib-check
178
dynamo-lib-check: ## Check if Dynamo library files exist (for local dev)
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
	@if [ ! -f "$(DYNAMO_LIB_DIR)/libdynamo_llm_capi.a" ]; then \
		echo "ERROR: Dynamo library not found. Run 'make dynamo-lib' first."; \
		exit 1; \
	fi
	@if [ ! -f "$(DYNAMO_INCLUDE_DIR)/llm_engine.h" ]; then \
		echo "ERROR: Dynamo header not found. Run 'make dynamo-lib' first."; \
		exit 1; \
	fi
	@echo "Dynamo library files found."

##@ Clean

.PHONY: clean
clean: ## Clean build artifacts
	rm -rf bin/
	go clean

##@ All-in-one Build

.PHONY: all
199
all: image-local-load ## Build Docker image and load locally
200
201

.PHONY: all-push
202
all-push: image-push ## Build Docker image and push to registry
203
204

.PHONY: all-kind
205
all-kind: image-kind ## Build Docker image and load to kind
206
207
208
209
210
211
212
213
214

##@ Info

.PHONY: info
info: ## Show build info
	@echo "Image Tag: $(IMAGE_TAG)"
	@echo "Git Commit: $(GIT_COMMIT_SHA)"
	@echo "Git Tag: $(GIT_TAG)"
	@echo "Platforms: $(PLATFORMS)"
215
	@echo "Multi-Arch Platforms: $(MULTIARCH_PLATFORMS)"
216
	@echo "Docker Proxy: $(DOCKER_PROXY)"
217
	@echo "Rust Image: $(RUST_IMAGE)"
218
219
220
	@echo "Builder Image: $(BUILDER_IMAGE)"
	@echo "Base Image: $(BASE_IMAGE)"
	@echo "Dynamo Dir: $(DYNAMO_DIR)"