-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
343 lines (280 loc) · 12.6 KB
/
Copy pathMakefile
File metadata and controls
343 lines (280 loc) · 12.6 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
NAME=incident-commander
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
DATE = $(shell date "+%Y-%m-%d %H:%M:%S")
ifeq ($(VERSION),)
VERSION_TAG=$(shell git describe --abbrev=0 --tags --exact-match --match 'v[0-9]*' 2>/dev/null || echo latest)
else
VERSION_TAG=$(VERSION)
endif
# Image URL to use all building/pushing image targets
IMG ?= docker.io/flanksource/$(NAME):${VERSION_TAG}
COMMA := ,
# 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
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/.bin
HOMEBREW_NODE_PATHS := /usr/local/opt/node/bin /opt/homebrew/opt/node/bin /opt/homebrew/opt/node@24/bin
export PATH := $(LOCALBIN):$(foreach p,$(HOMEBREW_NODE_PATHS),$(if $(wildcard $(p)/node),$(p):))$(PATH)
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
MODERNIZE ?= $(LOCALBIN)/modernize
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
PROTOC ?= $(LOCALBIN)/protoc
PROTOC_GEN_GO ?= $(LOCALBIN)/protoc-gen-go
PROTOC_GEN_GO_GRPC ?= $(LOCALBIN)/protoc-gen-go-grpc
PROTOC_INCLUDE ?= $(LOCALBIN)/include
DEPS ?= $(LOCALBIN)/deps
## Tool Versions
KUSTOMIZE_VERSION ?= any
CONTROLLER_TOOLS_VERSION ?= v0.19.0
GOLANGCI_LINT_VERSION ?= 2.11.4
PROTOC_VERSION ?= 21.9
PROTOC_GEN_GO_VERSION ?= v1.36.11
PROTOC_GEN_GO_GRPC_VERSION ?= v1.6.0
PROTOC_OS = $(if $(filter darwin,$(OS)),osx,$(OS))
PROTOC_ARCH = $(if $(filter amd64,$(ARCH)),x86_64,$(if $(filter arm64,$(ARCH)),aarch_64,$(ARCH)))
NODE_VERSION ?= 24.11.0
PNPM_VERSION ?= 10.33.0
TAILWIND_VERSION ?= 3.4.17
TAILWIND_JS = auth/oidc/static/tailwind.min.js
DEPS_VERSION ?= $(shell go list -m -f '{{.Version}}' github.com/flanksource/deps 2>/dev/null || echo latest)
LLM_PRICING_REGISTRY = llm/pricing_registry.json
$(TAILWIND_JS):
curl -sL "https://cdn.tailwindcss.com/$(TAILWIND_VERSION)" -o $(TAILWIND_JS)
.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)
.PHONY: static
static: $(TAILWIND_JS) manifests generate fmt ginkgo ui
.PHONY: ui
ui: $(LOCALBIN)/pnpm ## Build the embedded catalog explorer UI (ui/frontend -> ui/frontend/dist/ui.js)
cd ui/frontend && CI=true pnpm install --no-frozen-lockfile --prefer-offline && pnpm run build
.PHONY: test
test:
ginkgo -r --skip-package=tests/e2e --keep-going \
--junit-report junit-report.xml \
--github-output --output-dir test-reports \
--succinct --label-filter='!ignore_local'
.PHONY: ci-test
ci-test: $(TAILWIND_JS) $(LOCALBIN) ui
go build -o ./.bin/$(NAME) main.go
ginkgo -r --skip-package=tests/e2e --keep-going --junit-report junit-report.xml --github-output --output-dir test-reports --succinct
.PHONY: e2e
e2e: $(TAILWIND_JS) ui
go build -o ./.bin/$(NAME) main.go
ginkgo -r --keep-going ./tests/e2e/...
fmt:
go fmt ./...
.PHONY: check-clientapi-dependencies
check-clientapi-dependencies:
@dependencies="$$(go list -deps -f '{{if and (not .Standard) (ne .ImportPath "github.com/flanksource/incident-commander/clientapi")}}{{.ImportPath}}{{end}}' ./clientapi)" || exit $$?; \
unexpected="$$(printf '%s\n' "$$dependencies" | sed '/^$$/d' | sort -u | grep -vxF 'github.com/google/uuid' || true)"; \
if [ -n "$$unexpected" ]; then \
echo "clientapi dependency boundary violation"; \
echo ""; \
echo "clientapi defines the shared wire types used by Faro and the SDK. It must remain"; \
echo "lightweight because every production dependency added here becomes part of Faro's"; \
echo "transitive dependency graph and increases the client binary size."; \
echo ""; \
echo "Only the Go standard library and github.com/google/uuid are allowed. Move"; \
echo "dependency-specific behavior or conversion into the calling client, SDK, or server"; \
echo "adapter instead of expanding clientapi's dependency boundary."; \
echo ""; \
echo "Unexpected dependencies:"; \
printf '%s\n' "$$unexpected" | sed 's/^/ - /'; \
exit 1; \
fi; \
echo "clientapi dependency check passed"
.PHONY: modernize
modernize: ## Run modernize against code.
$(MODERNIZE) ./...
docker:
DOCKER_BUILDKIT=1 docker build -t ${IMG} $(if $(GITHUB_TOKEN),--secret id=GITHUB_TOKEN$(COMMA)env=GITHUB_TOKEN) .
# Build the docker image
docker-dev: linux
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker-push-%:
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker tag $(IMG) $*/$(IMG)
docker push $*/$(IMG)
kubectl set image deployment/$(NAME) $(NAME)=$*/$(IMG)
# Push the docker image
docker-push:
docker push ${IMG}
.PHONY: tidy
tidy:
go mod tidy
cd plugin/api && go mod tidy
cd plugin/sdk && go mod tidy
.PHONY: compress
compress: .bin/upx linux faro
upx -1 ./.bin/$(NAME)_linux_amd64 ./.bin/$(NAME)_linux_arm64 ./.bin/faro_linux_amd64 ./.bin/faro_linux_arm64
.PHONY: linux
linux: $(TAILWIND_JS)
GOOS=linux GOARCH=amd64 go build -o ./.bin/$(NAME)_linux_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=linux GOARCH=arm64 go build -o ./.bin/$(NAME)_linux_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: darwin
darwin:
GOOS=darwin GOARCH=amd64 go build -o ./.bin/$(NAME)_darwin_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=darwin GOARCH=arm64 go build -o ./.bin/$(NAME)_darwin_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: windows
windows:
GOOS=windows GOARCH=amd64 go build -o ./.bin/$(NAME)_windows_amd64.exe -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
# faro is a slim Mission Control client (remote-only surfaces). Built for the
# requested matrix: linux amd64/arm64, darwin amd64/arm64, windows amd64/arm64.
.PHONY: faro-linux
faro-linux: $(TAILWIND_JS)
GOOS=linux GOARCH=amd64 go build -trimpath -o ./.bin/faro_linux_amd64 -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
GOOS=linux GOARCH=arm64 go build -trimpath -o ./.bin/faro_linux_arm64 -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
.PHONY: faro-darwin
faro-darwin: $(TAILWIND_JS)
GOOS=darwin GOARCH=amd64 go build -trimpath -o ./.bin/faro_darwin_amd64 -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
GOOS=darwin GOARCH=arm64 go build -trimpath -o ./.bin/faro_darwin_arm64 -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
.PHONY: faro-windows
faro-windows: $(TAILWIND_JS)
GOOS=windows GOARCH=amd64 go build -trimpath -o ./.bin/faro_windows_amd64.exe -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
GOOS=windows GOARCH=arm64 go build -trimpath -o ./.bin/faro_windows_arm64.exe -ldflags "-s -w -X \"main.version=$(VERSION_TAG)\"" ./faro
.PHONY: faro
faro: faro-linux faro-darwin faro-windows
.PHONY: binaries
binaries: linux darwin windows faro compress
.PHONY: release package-release
release: ui binaries package-release
package-release:
mkdir -p .release
cp .bin/incident-commander* .release/
cp .bin/faro* .release/
# Generate OpenAPI schema
.PHONY: gen-schemas
gen-schemas:
cp go.mod hack/generate-schemas && \
cd hack/generate-schemas && \
go mod edit -module=github.com/flanksource/incident-commander/hack/generate-schemas && \
go mod edit -require=github.com/flanksource/incident-commander@v1.0.0 && \
go mod edit -replace=github.com/flanksource/incident-commander=../../ && \
go mod edit -replace=github.com/flanksource/incident-commander/plugin/api=../../plugin/api && \
if grep -v "^//" ../../go.mod | grep -q "replace.*github.com/flanksource/duty.*=>"; then \
go mod edit -replace=github.com/flanksource/duty=../../../duty; \
fi && \
if grep -v "^//" ../../go.mod | grep -q "replace.*github.com/flanksource/clicky.*=>"; then \
go mod edit -replace=github.com/flanksource/clicky=../../../clicky; \
fi && \
go mod tidy && \
go run ./main.go
.PHONY: manifests
manifests: generate gen-schemas ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=config/crds
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object paths="./api/..." paths="./logs/..."
.PHONY: generate-llm-pricing
generate-llm-pricing: ## Regenerate embedded LLM pricing registry from models.dev.
go run llm/internal/gen-pricing/main.go --output "$(LLM_PRICING_REGISTRY)"
.PHONY: build go-build
build: static
$(MAKE) go-build
go-build: | $(LOCALBIN)
go build -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG) built at $(DATE)\"" main.go
.PHONY: dev
dev:
# Disabling CGO because of slow build times in apple silicon (just experimenting)
CGO_ENABLED=0 go build -v -o ./.bin/$(NAME) -gcflags="all=-N -l" main.go
.PHONY: build-slim
build-slim: $(TAILWIND_JS) ## Fast go build only (no codegen or fmt)
CGO_ENABLED=0 go build -o ./.bin/$(NAME) main.go
.PHONY: install
install:
cp ./.bin/$(NAME) /usr/local/bin/
.PHONY: test-e2e
test-e2e: bin
./test/e2e.sh
.bin/upx: .bin
wget -nv -O upx.tar.xz https://github.com/upx/upx/releases/download/v3.96/upx-3.96-$(ARCH)_$(OS).tar.xz
tar xf upx.tar.xz
mv upx-3.96-$(ARCH)_$(OS)/upx .bin
rm -rf upx-3.96-$(ARCH)_$(OS)
.bin:
mkdir -p .bin
.PHONY: install-deps
install-deps: $(DEPS) ## Install the deps CLI if not present
$(DEPS): | $(LOCALBIN)
@if [ -x "$(DEPS)" ]; then \
exit 0; \
elif command -v deps >/dev/null 2>&1; then \
ln -sf "$$(command -v deps)" "$(DEPS)"; \
else \
url="https://github.com/flanksource/deps/releases/download/$(DEPS_VERSION)/deps-$(OS)-$(ARCH).tar.gz"; \
tmp="$(LOCALBIN)/deps-$(OS)-$(ARCH).tar.gz"; \
if curl -fsSL "$$url" -o "$$tmp"; then \
tar -xzf "$$tmp" -C $(LOCALBIN); \
else \
GOBIN=$(LOCALBIN) go install github.com/flanksource/deps/cmd/deps@$(DEPS_VERSION); \
fi; \
rm -f "$$tmp"; \
fi
.PHONY: deps
deps: install-deps ginkgo controller-gen golangci-lint kustomize $(LOCALBIN)/pnpm $(TAILWIND_JS) ## Install all tool dependencies
$(LOCALBIN)/node: $(DEPS) | $(LOCALBIN)
$(DEPS) install node@$(NODE_VERSION) --bin-dir $(LOCALBIN) --app-dir $(LOCALBIN)/apps --tmp-dir $(LOCALBIN)/tmp
$(LOCALBIN)/pnpm: $(LOCALBIN)/node
npm install -g pnpm@$(PNPM_VERSION)
ln -sf apps/node/bin/pnpm $(LOCALBIN)/pnpm
ln -sf apps/node/bin/pnpx $(LOCALBIN)/pnpx
.PHONY: pnpm
pnpm: $(LOCALBIN)/pnpm
.PHONY: ginkgo
ginkgo:
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo
.PHONY: controller-gen
controller-gen: $(DEPS) | $(LOCALBIN)
$(DEPS) install controller-gen@$(CONTROLLER_TOOLS_VERSION) --bin-dir $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(DEPS) | $(LOCALBIN)
$(DEPS) install golangci/golangci-lint@v$(GOLANGCI_LINT_VERSION) --bin-dir $(LOCALBIN)
.PHONY: kustomize
kustomize: $(DEPS) | $(LOCALBIN)
$(DEPS) install kubernetes-sigs/kustomize@$(KUSTOMIZE_VERSION) --bin-dir $(LOCALBIN)
.PHONY: docs\:mcp
docs\:mcp: ## Generate MCP tools reference documentation
@mkdir -p docs
go run ./hack/gen-mcp-docs > docs/mcp-tools.md
@echo "Generated docs/mcp-tools.md"
report/kitchen-sink.json: report/build-kitchen-sink.ts report/testdata/kitchen-sink.yaml
cd report && ./node_modules/.bin/tsx build-kitchen-sink.ts
.PHONY: lint
lint: golangci-lint
$(GOLANGCI_LINT) run ./...
.PHONY: protoc
protoc: $(PROTOC) $(PROTOC_INCLUDE)/google/protobuf/struct.proto ## Install protoc into .bin
$(PROTOC) $(PROTOC_INCLUDE)/google/protobuf/struct.proto: $(LOCALBIN)
@set -e; \
tmp=$$(mktemp -d); \
trap 'trash "$$tmp" >/dev/null 2>&1 || true' EXIT; \
curl -sSL -o "$$tmp/protoc.zip" "https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip"; \
unzip -q "$$tmp/protoc.zip" -d "$$tmp/protoc"; \
if [ -f "$(PROTOC)" ]; then chmod u+w "$(PROTOC)"; fi; \
cp "$$tmp/protoc/bin/protoc" "$(PROTOC)"; \
mkdir -p "$(PROTOC_INCLUDE)"; \
cp -R "$$tmp/protoc/include/." "$(PROTOC_INCLUDE)/"; \
chmod +x "$(PROTOC)"
$(PROTOC_GEN_GO): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
$(PROTOC_GEN_GO_GRPC): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION)
.PHONY: proto
proto: protoc $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) ## Regenerate plugin gRPC stubs from plugin/api/plugin.proto
$(PROTOC) \
--proto_path=plugin/api \
--proto_path=$(PROTOC_INCLUDE) \
--go_out=plugin/api --go_opt=paths=source_relative \
--go-grpc_out=plugin/api --go-grpc_opt=paths=source_relative \
plugin.proto