1+ <<<<<<< HEAD
12# Image URL to use all building/pushing image targets
23IMG ?= controller:latest
34ADDITIONAL_IMAGES ?=
5+ ====== =
6+
7+ # Image configuration
8+ DOCKER_REGISTRY ?= ghcr.io
9+ BASE_IMAGE_REGISTRY ?= cgr.dev
10+ DOCKER_REPO ?= kagent-dev/kmcp
11+ HELM_REPO ?= oci://ghcr.io/kagent-dev
12+ HELM_DIST_FOLDER ?= dist
13+
14+ BUILD_DATE := $(shell date -u '+% Y-% m-% d')
15+ GIT_COMMIT := $(shell git rev-parse --short HEAD || echo "unknown")
16+ VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/-dirty//' | grep v || echo "v0.0.1+$(GIT_COMMIT ) ")
17+
18+ # Local architecture detection to build for the current platform
19+ LOCALARCH ?= $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
20+
21+ # Docker buildx configuration
22+ BUILDKIT_VERSION = v0.23.0
23+ BUILDX_NO_DEFAULT_ATTESTATIONS =1
24+ BUILDX_BUILDER_NAME ?= kmcp-builder-$(BUILDKIT_VERSION )
25+ DOCKER_BUILDER ?= docker buildx
26+ DOCKER_BUILD_ARGS ?= --builder $(BUILDX_BUILDER_NAME ) --pull --load --platform linux/$(LOCALARCH )
27+
28+ # Image configuration
29+ CONTROLLER_IMAGE_NAME ?= controller
30+ CONTROLLER_IMAGE_TAG ?= $(VERSION )
31+ CONTROLLER_IMG ?= $(DOCKER_REGISTRY ) /$(DOCKER_REPO ) /$(CONTROLLER_IMAGE_NAME ) :$(CONTROLLER_IMAGE_TAG )
32+
33+ # Image URL to use all building/pushing image targets (backward compatibility)
34+ IMG ?= $(CONTROLLER_IMG )
35+ DIST_FOLDER ?= dist
36+ >>>>>>> b9c7047 (add Helm chart (# 2))
437
538# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
639ifeq (,$(shell go env GOBIN) )
942GOBIN =$(shell go env GOBIN)
1043endif
1144
12- # CONTAINER_TOOL defines the container tool to be used for building images.
13- # Be aware that the target commands are only tested with Docker which is
14- # scaffolded by default. However, you might want to replace it to use other
15- # tools. (i.e. podman)
16- CONTAINER_TOOL ?= docker
17-
1845# Setting SHELL to bash allows bash commands to be executed by recipes.
1946# Options are set to exit when a recipe line exits non-zero or a piped command fails.
2047SHELL = /usr/bin/env bash -o pipefail
@@ -46,27 +73,49 @@ help: ## Display this help.
4673manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4774 $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
4875
49- .PHONY : helm-crd
50- helm-crd : manifests # # Generate Helm CRD template from the generated CRD definition.
51- @echo " Generating Helm CRD template from config/crd/bases/kagent.dev_mcpservers.yaml"
52- @mkdir -p helm/kmcp/templates/crds
53- @echo ' {{- if .Values.crd.create }}' > helm/kmcp/templates/crds/mcpserver-crd.yaml
54- @awk ' /^ name: mcpservers.kagent.dev$$/ { \
55- print; \
56- print " labels:" ; \
57- print " {{- include \" kmcp.labels\" . | nindent 4 }}" ; \
58- next; \
59- } \
60- { print }' config/crd/bases/kagent.dev_mcpservers.yaml >> helm/kmcp/templates/crds/mcpserver-crd.yaml
61- @echo ' {{- end }}' >> helm/kmcp/templates/crds/mcpserver-crd.yaml
62- @echo " Helm CRD template generated at helm/kmcp/templates/crds/mcpserver-crd.yaml"
63-
64- .PHONY : helm-templates
65- helm-templates : helm-crd # # Generate all Helm templates from source definitions.
66- @echo " All Helm templates updated successfully"
76+ .PHONY : helm-lint
77+ helm-lint :
78+ helm lint helm/kmcp
79+
80+ .PHONY : helm-package
81+ helm-package :
82+ mkdir -p $(DIST_FOLDER )
83+ @echo " Packaging Helm chart with version $( VERSION) ..."
84+ @cp helm/kmcp/Chart.yaml helm/kmcp/Chart.yaml.bak
85+ @sed " s/^version: .*/version: $( VERSION) /" helm/kmcp/Chart.yaml.bak > helm/kmcp/Chart.yaml
86+ @helm package helm/kmcp --version $(VERSION ) -d $(DIST_FOLDER )
87+ @mv helm/kmcp/Chart.yaml.bak helm/kmcp/Chart.yaml
88+
89+ .PHONY : helm-cleanup
90+ helm-cleanup : # # Clean up Helm chart packages
91+ rm -f $(DIST_FOLDER ) /* .tgz
92+
93+ .PHONY : helm-build
94+ helm-build : helm-lint helm-package # # Build and package the Helm chart
95+ @echo " Helm chart built successfully"
96+
97+ .PHONY : helm-publish
98+ helm-publish : helm-package # # Publish Helm chart to OCI registry
99+ @echo " Publishing Helm chart to $( HELM_REPO) /kmcp/helm..."
100+ @helm push $(HELM_DIST_FOLDER ) /kmcp-$(VERSION ) .tgz $(HELM_REPO ) /kmcp/helm
101+ @echo " Helm chart published successfully"
102+
103+ .PHONY : helm-test
104+ helm-test :
105+ @echo " Running Helm chart unit tests..."
106+ @command -v helm > /dev/null 2>&1 || { \
107+ echo " Helm is not installed. Please install Helm manually." ; \
108+ exit 1; \
109+ }
110+ @helm plugin list | grep -q ' unittest' || { \
111+ echo " Installing helm-unittest plugin..." ; \
112+ helm plugin install https://github.com/quintush/helm-unittest; \
113+ }
114+ @helm unittest helm/kmcp
115+ @echo " Helm chart unit tests completed successfully"
67116
68117.PHONY : manifests-all
69- manifests-all : manifests helm-templates # # Generate both Kustomize and Helm manifests from source definitions.
118+ manifests-all : manifests # # Generate Kustomize from source definitions.
70119 @echo " All manifests (Kustomize and Helm) updated successfully"
71120
72121.PHONY : generate
@@ -133,61 +182,19 @@ run: manifests generate fmt vet ## Run a controller from your host.
133182# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
134183.PHONY : docker-build
135184docker-build : # # Build docker image with the manager.
136- $(CONTAINER_TOOL ) build -t ${IMG} .
185+ - $(DOCKER_BUILDER ) create --name $(BUILDX_BUILDER_NAME )
186+ $(DOCKER_BUILDER ) use $(BUILDX_BUILDER_NAME )
187+ $(DOCKER_BUILDER ) build $(DOCKER_BUILD_ARGS ) -t ${CONTROLLER_IMG} .
188+ - $(DOCKER_BUILDER ) rm $(BUILDX_BUILDER_NAME )
137189
138190.PHONY : kind-load-images
139191kind-load-images : # # Load images into Kind cluster. Defaults to current kind cluster.
140192 kind load docker-image ${IMG} $(ADDITIONAL_IMAGES )
141193
142194.PHONY : docker-push
143195docker-push : # # Push docker image with the manager.
144- $(CONTAINER_TOOL ) push ${IMG}
145-
146- # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
147- # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
148- # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
149- # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
150- # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
151- # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
152- PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
153- .PHONY : docker-buildx
154- docker-buildx : # # Build and push docker image for the manager for cross-platform support
155- # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
156- sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
157- - $(CONTAINER_TOOL ) buildx create --name kmcp-builder
158- $(CONTAINER_TOOL ) buildx use kmcp-builder
159- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
160- - $(CONTAINER_TOOL ) buildx rm kmcp-builder
161- rm Dockerfile.cross
162-
163- .PHONY : build-installer
164- build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
165- mkdir -p dist
166- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
167- $(KUSTOMIZE ) build config/default > dist/install.yaml
168-
169- # #@ Deployment
170-
171- ifndef ignore-not-found
172- ignore-not-found = false
173- endif
174-
175- .PHONY : install
176- install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
177- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
178-
179- .PHONY : uninstall
180- uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
181- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
182-
183- .PHONY : deploy
184- deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
185- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
186- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
196+ $(DOCKER_BUILDER ) push ${CONTROLLER_IMG}
187197
188- .PHONY : undeploy
189- undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
190- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
191198
192199# #@ Dependencies
193200
@@ -212,10 +219,6 @@ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller
212219ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
213220GOLANGCI_LINT_VERSION ?= v1.63.4
214221
215- .PHONY : kustomize
216- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
217- $(KUSTOMIZE ) : $(LOCALBIN )
218- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
219222
220223.PHONY : controller-gen
221224controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
0 commit comments