forked from volcano-sh/agentcube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
324 lines (267 loc) · 10.4 KB
/
Makefile
File metadata and controls
324 lines (267 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Image URL to use all building/pushing image targets
HUB ?= ghcr.io/volcano-sh
TAG ?= latest
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.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%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: gen-crd
gen-crd: controller-gen ## Generate CRD manifests
$(CONTROLLER_GEN) crd paths="./pkg/apis/runtime/v1alpha1/..." output:crd:artifacts:config=manifests/charts/base/crds
.PHONY: generate
generate: controller-gen gen-crd ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/..."
go mod tidy
.PHONY: gen-client
gen-client: ## Generate client-go code for CRDs
@echo "Generating client-go code..."
@bash hack/update-codegen.sh
@go mod tidy
.PHONY: gen-all
gen-all: generate gen-client ## Generate all code (CRDs, DeepCopy methods, and client-go)
.PHONY: gen-check
gen-check: gen-all ## Check if generated code is up to date
git diff --exit-code
.PHONY: build run clean test deps
# Build targets
build: generate ## Build workloadmanager binary
@echo "Building workloadmanager..."
go build -o bin/workloadmanager ./cmd/workload-manager
build-agentd: generate ## Build agentd binary
@echo "Building agentd..."
go build -o bin/agentd ./cmd/agentd
build-router: generate ## Build agentcube-router binary
@echo "Building agentcube-router..."
go build -o bin/agentcube-router ./cmd/router
build-all: build build-agentd build-router ## Build all binaries
# Run server (development mode)
run:
@echo "Running workloadmanager..."
go run ./cmd/workload-manager/main.go \
--port=8080 \
--ssh-username=sandbox \
--ssh-port=22
# Run server (with kubeconfig)
run-local:
@echo "Running workloadmanager with local kubeconfig..."
go run ./cmd/workload-manager/main.go \
--port=8080 \
--kubeconfig=${HOME}/.kube/config \
--ssh-username=sandbox \
--ssh-port=22
# Run router (development mode)
run-router:
@echo "Running agentcube-router..."
go run ./cmd/router/main.go \
--port=8080 \
--debug
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -rf bin/
rm -f workloadmanager agentd agentcube-router
# Install dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
# Update dependencies
update-deps:
@echo "Updating dependencies..."
go get -u ./...
go mod tidy
# Run tests
test:
@echo "Running tests..."
go test -v ./...
# Format code
fmt: ## Format code
@echo "Formatting code..."
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
# Run linter
.PHONY: lint
lint: golangci-lint ## Run golangci-lint
$(GOLANGCI_LINT) run ./...
# Generate copyright headers
.PHONY: gen-copyright
gen-copyright:
@echo "Adding copyright headers..."
@hack/update-copyright.sh
# Install to system
install: build
@echo "Installing workloadmanager..."
sudo cp bin/workloadmanager /usr/local/bin/
# Docker image variables
WORKLOAD_MANAGER_IMAGE ?= workloadmanager:latest
ROUTER_IMAGE ?= agentcube-router:latest
PICOD_IMAGE ?= picod:latest
IMAGE_REGISTRY ?= ""
# Docker and Kubernetes targets
docker-build:
@echo "Building Docker image..."
docker build -f docker/Dockerfile -t $(WORKLOAD_MANAGER_IMAGE) .
# Multi-architecture build (supports amd64, arm64)
docker-buildx:
@echo "Building multi-architecture Docker image..."
docker buildx build -f docker/Dockerfile --platform linux/amd64,linux/arm64 -t $(WORKLOAD_MANAGER_IMAGE) .
# Multi-architecture build and push
docker-buildx-push:
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-buildx-push IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Building and pushing multi-architecture Docker image to $(IMAGE_REGISTRY)/$(WORKLOAD_MANAGER_IMAGE)..."
docker buildx build -f docker/Dockerfile --platform linux/amd64,linux/arm64 \
-t $(IMAGE_REGISTRY)/$(WORKLOAD_MANAGER_IMAGE) \
--push .
docker-push: docker-build
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-push IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Tagging and pushing Docker image to $(IMAGE_REGISTRY)/$(WORKLOAD_MANAGER_IMAGE)..."
docker tag $(WORKLOAD_MANAGER_IMAGE) $(IMAGE_REGISTRY)/$(WORKLOAD_MANAGER_IMAGE)
docker push $(IMAGE_REGISTRY)/$(WORKLOAD_MANAGER_IMAGE)
# Load image to kind cluster
kind-load:
@echo "Loading image to kind..."
kind load docker-image $(WORKLOAD_MANAGER_IMAGE)
# Router Docker targets
docker-build-router:
@echo "Building Router Docker image..."
docker build -f docker/Dockerfile.router -t $(ROUTER_IMAGE) .
# Multi-architecture build for router (supports amd64, arm64)
docker-buildx-router:
@echo "Building multi-architecture Router Docker image..."
docker buildx build -f docker/Dockerfile.router --platform linux/amd64,linux/arm64 -t $(ROUTER_IMAGE) .
# Multi-architecture build and push for router
docker-buildx-push-router:
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-buildx-push-router IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Building and pushing multi-architecture Router Docker image to $(IMAGE_REGISTRY)/$(ROUTER_IMAGE)..."
docker buildx build -f docker/Dockerfile.router --platform linux/amd64,linux/arm64 \
-t $(IMAGE_REGISTRY)/$(ROUTER_IMAGE) \
--push .
docker-push-router: docker-build-router
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-push-router IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Tagging and pushing Router Docker image to $(IMAGE_REGISTRY)/$(ROUTER_IMAGE)..."
docker tag $(ROUTER_IMAGE) $(IMAGE_REGISTRY)/$(ROUTER_IMAGE)
docker push $(IMAGE_REGISTRY)/$(ROUTER_IMAGE)
# Load router image to kind cluster
kind-load-router:
@echo "Loading router image to kind..."
kind load docker-image $(ROUTER_IMAGE)
# Picod Docker targets
docker-build-picod:
@echo "Building Picod Docker image..."
docker build -f docker/Dockerfile.picod -t $(PICOD_IMAGE) .
# Multi-architecture build for picod (supports amd64, arm64)
docker-buildx-picod:
@echo "Building multi-architecture Picod Docker image..."
docker buildx build -f docker/Dockerfile.picod --platform linux/amd64,linux/arm64 -t $(PICOD_IMAGE) .
# Multi-architecture build and push for picod
docker-buildx-push-picod:
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-buildx-push-picod IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Building and pushing multi-architecture Picod Docker image to $(IMAGE_REGISTRY)/$(PICOD_IMAGE)..."
docker buildx build -f docker/Dockerfile.picod --platform linux/amd64,linux/arm64 \
-t $(IMAGE_REGISTRY)/$(PICOD_IMAGE) \
--push .
docker-push-picod: docker-build-picod
@if [ -z "$(IMAGE_REGISTRY)" ]; then \
echo "Error: IMAGE_REGISTRY not set. Usage: make docker-push-picod IMAGE_REGISTRY=your-registry.com"; \
exit 1; \
fi
@echo "Tagging and pushing Picod Docker image to $(IMAGE_REGISTRY)/$(PICOD_IMAGE)..."
docker tag $(PICOD_IMAGE) $(IMAGE_REGISTRY)/$(PICOD_IMAGE)
docker push $(IMAGE_REGISTRY)/$(PICOD_IMAGE)
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.17.2
GOLANGCI_LINT_VERSION ?= v1.64.1
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
# 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)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
# E2E Test targets
E2E_CLUSTER_NAME ?= agentcube-e2e
AGENT_SANDBOX_REPO ?= https://github.com/kubernetes-sigs/agent-sandbox.git
AGENT_SANDBOX_VERSION ?= main
e2e:
./test/e2e/run_e2e.sh
e2e-clean:
@echo "Cleaning up E2E environment..."
kind delete cluster --name $(E2E_CLUSTER_NAME)
rm -rf /tmp/agent-sandbox
# Python SDK targets
.PHONY: build-python-sdk
build-python-sdk: ## Build Python SDK
@echo "Building Python SDK..."
cp LICENSE sdk-python/LICENSE
cd sdk-python && python3 -m build; cd ..; rm -f sdk-python/LICENSE
@echo "Build complete. Artifacts are in sdk-python/dist/"