|
| 1 | + |
| 2 | +# Image URL to use all building/pushing image targets |
| 3 | +IMG ?= ghcr.io/achetronic/mcp-proxy:placeholder |
| 4 | + |
| 5 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 6 | +ifeq (,$(shell go env GOBIN)) |
| 7 | +GOBIN=$(shell go env GOPATH)/bin |
| 8 | +else |
| 9 | +GOBIN=$(shell go env GOBIN) |
| 10 | +endif |
| 11 | + |
| 12 | +# Get the current Go OS |
| 13 | +GO_OS ?= $(or $(GOOS),$(shell go env GOOS)) |
| 14 | +# Get the current Go ARCH |
| 15 | +GO_ARCH ?= $(or $(GOARCH),$(shell go env GOARCH)) |
| 16 | + |
| 17 | +OS=$(shell uname | tr '[:upper:]' '[:lower:]') |
| 18 | + |
| 19 | +# CONTAINER_TOOL defines the container tool to be used for building images. |
| 20 | +# Be aware that the target commands are only tested with Docker which is |
| 21 | +# scaffolded by default. However, you might want to replace it to use other |
| 22 | +# tools. (i.e. podman) |
| 23 | +CONTAINER_TOOL ?= docker |
| 24 | + |
| 25 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 26 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 27 | +SHELL = /usr/bin/env bash -o pipefail |
| 28 | +.SHELLFLAGS = -ec |
| 29 | + |
| 30 | +.PHONY: all |
| 31 | +all: build |
| 32 | + |
| 33 | +##@ General |
| 34 | + |
| 35 | +# The help target prints out all targets with their descriptions organized |
| 36 | +# beneath their categories. The categories are represented by '##@' and the |
| 37 | +# target descriptions by '##'. The awk command is responsible for reading the |
| 38 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 39 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 40 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 41 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 42 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 43 | +# More info on the awk command: |
| 44 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 45 | + |
| 46 | +.PHONY: help |
| 47 | +help: ## Display this help. |
| 48 | + @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) |
| 49 | + |
| 50 | +##@ Development |
| 51 | + |
| 52 | +.PHONY: fmt |
| 53 | +fmt: ## Run go fmt against code. |
| 54 | + go fmt ./... |
| 55 | + |
| 56 | +.PHONY: vet |
| 57 | +vet: ## Run go vet against code. |
| 58 | + go vet ./... |
| 59 | + |
| 60 | +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint |
| 61 | +GOLANGCI_LINT_VERSION ?= v1.54.2 |
| 62 | +golangci-lint: |
| 63 | + @[ -f $(GOLANGCI_LINT) ] || { \ |
| 64 | + set -e ;\ |
| 65 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\ |
| 66 | + } |
| 67 | + |
| 68 | +.PHONY: lint |
| 69 | +lint: golangci-lint ## Run golangci-lint linter & yamllint |
| 70 | + $(GOLANGCI_LINT) run |
| 71 | + |
| 72 | +.PHONY: lint-fix |
| 73 | +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes |
| 74 | + $(GOLANGCI_LINT) run --fix |
| 75 | + |
| 76 | +##@ Build |
| 77 | +.PHONY: swagger |
| 78 | +swagger: install-swag ## Build Swagger documents. |
| 79 | + $(SWAG) init --dir "./cmd/,." --outputTypes "go" |
| 80 | + |
| 81 | +.PHONY: build |
| 82 | +build: fmt vet ## Build CLI binary. |
| 83 | + go build -o bin/mcp-proxy-$(GO_OS)-$(GO_ARCH) cmd/main.go |
| 84 | + |
| 85 | +.PHONY: run |
| 86 | +run: fmt vet ## Run a controller from your host. |
| 87 | + go run ./cmd/ --config ./docs/config-http-stdio.yaml |
| 88 | + |
| 89 | +# If you wish to build the manager image targeting other platforms you can use the --platform flag. |
| 90 | +# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. |
| 91 | +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 92 | +.PHONY: docker-build |
| 93 | +docker-build: ## Build docker image with the manager. |
| 94 | + $(CONTAINER_TOOL) build --no-cache -t ${IMG} . |
| 95 | + |
| 96 | +.PHONY: docker-push |
| 97 | +docker-push: ## Push docker image with the manager. |
| 98 | + $(CONTAINER_TOOL) push ${IMG} |
| 99 | + |
| 100 | +PACKAGE_NAME ?= package.tar.gz |
| 101 | +.PHONY: package |
| 102 | +package: ## Package binary. |
| 103 | + @printf "\nCreating package at dist/$(PACKAGE_NAME) \n" |
| 104 | + @mkdir -p dist |
| 105 | + |
| 106 | + @if [ "$(OS)" = "linux" ]; then \ |
| 107 | + tar --transform="s/mcp-proxy-$(GO_OS)-$(GO_ARCH)/mcp-proxy/" -cvzf dist/$(PACKAGE_NAME) -C bin mcp-proxy-$(GO_OS)-$(GO_ARCH) -C ../ LICENSE README.md; \ |
| 108 | + elif [ "$(OS)" = "darwin" ]; then \ |
| 109 | + tar -cvzf dist/$(PACKAGE_NAME) -s '/mcp-proxy-$(GO_OS)-$(GO_ARCH)/mcp-proxy/' -C bin mcp-proxy-$(GO_OS)-$(GO_ARCH) -C ../ LICENSE README.md; \ |
| 110 | + else \ |
| 111 | + echo "Unsupported OS: $(GO_OS)"; \ |
| 112 | + exit 1; \ |
| 113 | + fi |
| 114 | + |
| 115 | +.PHONY: package-signature |
| 116 | +package-signature: ## Create a signature for the package. |
| 117 | + @printf "\nCreating package signature at dist/$(PACKAGE_NAME).md5 \n" |
| 118 | + md5sum dist/$(PACKAGE_NAME) | awk '{ print $$1 }' > dist/$(PACKAGE_NAME).md5 |
0 commit comments