-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
49 lines (41 loc) · 1.67 KB
/
Makefile
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
#!/usr/bin/make -f
OUT_DIR ?= docs
JB_ARGS ?= install
export GOFLAGS := -mod=mod
export GOBIN := $(shell pwd)/bin
JB_BIN := $(GOBIN)/jb
JSONNET_BIN := $(GOBIN)/jsonnet
SANITIZER_BIN := $(GOBIN)/sanitizer
YQ_BIN := $(GOBIN)/yq
tools := $(JB_BIN) $(JSONNET_BIN) $(SANITIZER_BIN) $(YQ_BIN)
mixins := $(patsubst mixins/%.libsonnet,%,$(wildcard mixins/*.libsonnet))
dashboards: $(addprefix dashboards-, $(mixins))
alerts: $(addprefix prometheusAlerts-, $(mixins))
rules: $(addprefix prometheusRules-, $(mixins))
.DEFAULT_GOAL := all
all: vendor dashboards prom
prom: alerts rules
dashboards-%: vendor $(tools)
@echo "Rendering dashboards for $* ..."
@$(JSONNET_BIN) -J vendor -cm $(OUT_DIR)/$*/dashboards -e '(import "mixins/$*.libsonnet").grafanaDashboards'
@find $(OUT_DIR)/$*/dashboards -type f -name '*.json' -exec $(YQ_BIN) --inplace --indent 2 --prettyPrint -o json {} \;
prometheus%: vendor $(tools)
$(eval TYPE := $(word 1,$(subst -, ,$@)))
$(eval MIXIN := $(word 2,$(subst -, ,$@)))
$(eval TARGET_FILE := $(OUT_DIR)/$(MIXIN)/$(TYPE))
@echo "Rendering $(TYPE) for $(MIXIN) ..."
@mkdir -p $(shell dirname $(TARGET_FILE))
@$(JSONNET_BIN) -J vendor -S -e 'std.manifestYamlDoc((import "mixins/$(MIXIN).libsonnet").$(TYPE))' > $(TARGET_FILE).tmp
@$(SANITIZER_BIN) $(TARGET_FILE).tmp | tee $(TARGET_FILE).yaml | $(YQ_BIN) --prettyPrint -o json > $(TARGET_FILE).json
@rm $(TARGET_FILE).tmp
$(tools):
go install ./cmd/sanitizer
go install github.com/google/go-jsonnet/cmd/jsonnet@latest
go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
go install github.com/mikefarah/yq/v4@latest
.PHONY: vendor
vendor: $(tools)
@$(JB_BIN) $(JB_ARGS)
.PHONY: clean
clean:
@rm -rf $(OUT_DIR)