-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (129 loc) · 5.72 KB
/
Copy pathMakefile
File metadata and controls
161 lines (129 loc) · 5.72 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
SHELL := /bin/bash
APP_NAME := mytoolkit
VERSION := $(shell cat VERSION)
IMAGE := $(APP_NAME)
TAG := $(VERSION)
PLATFORMS := linux/amd64,linux/arm64
NAMESPACE := $(APP_NAME)
KIND_CLUSTER := kind-multinodes
KUBE_CONTEXT := kind-$(KIND_CLUSTER)
SRC := app
BIN_DIR := bin
LDFLAGS := -X github.com/aeciopires/mytoolkit/internal/version.Version=$(VERSION)
HOST_PORT := 8080
CHART_DIR := helm/$(APP_NAME)
REQUIRED_TOOLS := go git docker helm kubectl kind golangci-lint helm-docs
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: ## Build the mytoolkit binary into bin/ (version from ./VERSION)
mkdir -p $(BIN_DIR)
cd $(SRC) && go build -ldflags="$(LDFLAGS)" -o ../$(BIN_DIR)/$(APP_NAME) ./cmd/mytoolkit
.PHONY: run
run: ## Run the web server locally (go run)
cd $(SRC) && go run ./cmd/mytoolkit serve
.PHONY: mcp-run
mcp-run: ## Run the MCP server locally over stdio (go run)
cd $(SRC) && go run ./cmd/mytoolkit mcp
.PHONY: mcp-run-http
mcp-run-http: ## Run the MCP server locally over streamable HTTP on :8081
cd $(SRC) && go run ./cmd/mytoolkit mcp --transport http --port 8081
.PHONY: test
test: ## Run unit tests
cd $(SRC) && go test ./...
.PHONY: test-verbose
test-verbose: ## Run unit tests with verbose output
cd $(SRC) && go test -v ./...
.PHONY: coverage
coverage: ## Run tests with coverage report
cd $(SRC) && go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out
.PHONY: lint
lint: ## Run golangci-lint
cd $(SRC) && golangci-lint run
.PHONY: fmt
fmt: ## Format Go source
cd $(SRC) && gofmt -s -w .
.PHONY: vet
vet: ## Run go vet
cd $(SRC) && go vet ./...
.PHONY: check-tools
check-tools: ## Verify required development/runtime tools are installed
@missing=""; \
for tool in $(REQUIRED_TOOLS); do \
if command -v $$tool >/dev/null 2>&1; then \
echo "[OK] $$tool"; \
else \
echo "[MISSING] $$tool"; \
missing="$$missing $$tool"; \
fi; \
done; \
if command -v docker >/dev/null 2>&1 && ! docker compose version >/dev/null 2>&1; then \
echo "[MISSING] docker compose (plugin)"; \
missing="$$missing docker-compose-plugin"; \
fi; \
if [ -n "$$missing" ]; then \
echo ""; echo "Missing tools:$$missing"; \
exit 1; \
fi; \
echo ""; echo "All required tools are installed."
.PHONY: deps-check
deps-check: ## Verify the Go module graph is tidy (go.mod/go.sum hygiene)
cd $(SRC) && go mod verify && go mod tidy -diff
.PHONY: docker-build
docker-build: ## Build a local single-platform Docker image (version from ./VERSION)
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE):$(TAG) -t $(IMAGE):latest .
.PHONY: docker-buildx
docker-buildx: ## Build (and validate) a multi-arch image for linux/amd64 + linux/arm64
docker buildx build --platform $(PLATFORMS) --build-arg VERSION=$(VERSION) -t $(IMAGE):$(TAG) .
.PHONY: docker-run
docker-run: ## Run the local Docker image on $(HOST_PORT)
docker run --rm -p $(HOST_PORT):8080 $(IMAGE):$(TAG)
.PHONY: docker-push
docker-push: ## Prompt for Docker Hub credentials and push a multi-arch (amd64+arm64) image tagged $(VERSION)
@read -p "Docker Hub username: " DOCKERHUB_USER; \
read -s -p "Docker Hub password or access token: " DOCKERHUB_PASSWORD; echo; \
read -p "Docker Hub repository (e.g. yourname/mytoolkit): " DOCKERHUB_REPO; \
echo "$$DOCKERHUB_PASSWORD" | docker login --username "$$DOCKERHUB_USER" --password-stdin; \
docker buildx build --platform $(PLATFORMS) --build-arg VERSION=$(VERSION) -t "$$DOCKERHUB_REPO:$(VERSION)" -t "$$DOCKERHUB_REPO:latest" --push .; \
docker logout >/dev/null
.PHONY: compose-up
compose-up: ## Start the app via docker compose
docker compose up -d --build
.PHONY: compose-down
compose-down: ## Stop the app started via docker compose
docker compose down
.PHONY: helm-lint
helm-lint: ## Lint the Helm chart
helm lint helm/$(APP_NAME)
.PHONY: helm-template
helm-template: ## Render the Helm chart locally
helm template $(APP_NAME) helm/$(APP_NAME) --set ingress.enabled=true --set autoscaling.enabled=true
.PHONY: helm-set-appversion
helm-set-appversion: ## Sync $(CHART_DIR)/Chart.yaml's appVersion with the root VERSION file
sed -i.bak -E 's/^appVersion: .*/appVersion: "$(VERSION)"/' $(CHART_DIR)/Chart.yaml
rm -f $(CHART_DIR)/Chart.yaml.bak
.PHONY: helm-docs
helm-docs: helm-set-appversion ## Sync Chart.yaml's appVersion with VERSION, then regenerate helm/mytoolkit/README.md from README.md.gotmpl + values.yaml comments
helm-docs --chart-search-root=helm
.PHONY: swagger-gen
swagger-gen: ## Regenerate $(SRC)/docs (Swagger/OpenAPI spec) from @-annotations — run after touching any @Router/@Summary/etc. comment
cd $(SRC) && go run github.com/swaggo/swag/cmd/swag@v1.16.6 init -g cmd/mytoolkit/main.go -o docs --parseDependency --parseInternal
.PHONY: kind-load
kind-load: ## Load the local Docker image into the kind-multinodes cluster
kind load docker-image $(IMAGE):$(TAG) --name $(KIND_CLUSTER)
.PHONY: helm-install
helm-install: ## helm upgrade --install against $(KUBE_CONTEXT) / namespace $(NAMESPACE)
helm upgrade --install $(APP_NAME) helm/$(APP_NAME) \
--namespace $(NAMESPACE) --create-namespace \
--kube-context $(KUBE_CONTEXT)
.PHONY: helm-uninstall
helm-uninstall: ## helm uninstall from $(KUBE_CONTEXT) / namespace $(NAMESPACE)
helm uninstall $(APP_NAME) --namespace $(NAMESPACE) --kube-context $(KUBE_CONTEXT)
.PHONY: helm-test
helm-test: ## Run helm test (hits /healthz) against the installed release
helm test $(APP_NAME) --namespace $(NAMESPACE) --kube-context $(KUBE_CONTEXT)
.PHONY: clean
clean: ## Remove build artifacts
rm -rf $(BIN_DIR) $(SRC)/coverage.out