This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
88 lines (69 loc) · 3.18 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
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
SRC = $(shell find . -type f -name '*.go' -not -path './vendor/*')
all: thanos-replicate generate
tmp/help.txt: thanos-replicate
mkdir -p tmp
./thanos-replicate run --help &> tmp/help.txt
README.md: tmp/help.txt
embedmd -w README.md
thanos-replicate: go-vendor $(SRC)
CGO_ENABLED=0 GO111MODULE=on go build -mod vendor -v
.PHONY: go-vendor
go-vendor: go.mod go.sum
go mod vendor
.PHONY: lint
lint: fmt ${ALERTS} ${RULES}
golangci-lint run -v --enable-all
promtool check rules ${ALERTS} ${RULES}
.PHONY: test ${ALERTS} ${RULES}
test:
CGO_ENABLED=1 GO111MODULE=on GOPROXY=https://proxy.golang.org go test -v -race ./...
.PHONY: clean
clean:
-rm thanos-replicate
rm -rf ${DASHBOARDS}
rm -rf ${ALERTS}
rm -rf ${RULES}
EXAMPLES := examples
MANIFESTS := ${EXAMPLES}/manifests/
DASHBOARDS := ${EXAMPLES}/dashboards/
ALERTS := ${EXAMPLES}/alerts.yaml
RULES := ${EXAMPLES}/rules.yaml
SRC = $(shell find . -type f -name '*.go' -not -path './vendor/*')
JSONNET_SRC = $(shell find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print)
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
CONTAINER_CMD:=docker run --rm \
-u="$(shell id -u):$(shell id -g)" \
-v "$(shell go env GOCACHE):/.cache/go-build" \
-v "$(PWD):/go/src/github.com/observatorium/thanos-replicate:Z" \
-w "/go/src/github.com/observatorium/thanos-replicate" \
-e USER=deadbeef \
-e GO111MODULE=on \
quay.io/coreos/jsonnet-ci
.PHONY: generate
generate: jsonnet-vendor ${ALERTS} ${RULES} ${DASHBOARDS} ${MANIFESTS}
.PHONY: generate-in-docker
generate-in-docker:
@echo ">> Compiling assets and generating Kubernetes manifests"
$(CONTAINER_CMD) make $(MFLAGS) generate
.PHONY: ${MANIFESTS}
${MANIFESTS}: jsonnet/main.jsonnet jsonnet/lib/*
@rm -rf ${MANIFESTS}
@mkdir -p ${MANIFESTS}
jsonnet -J jsonnet/vendor -m ${MANIFESTS} jsonnet/main.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml && rm -f {}' -- {}
.PHONY: ${DASHBOARDS}
${DASHBOARDS}: jsonnet/thanos-replicate-mixin/mixin.libsonnet jsonnet/thanos-replicate-mixin/defaults.libsonnet jsonnet/thanos-replicate-mixin/dashboards/*
@rm -rf ${DASHBOARDS}
@mkdir -p ${DASHBOARDS}
jsonnet -J jsonnet/vendor -m ${DASHBOARDS} jsonnet/thanos-replicate-mixin/dashboards.jsonnet
${ALERTS}: jsonnet/thanos-replicate-mixin/mixin.libsonnet jsonnet/thanos-replicate-mixin/defaults.libsonnet jsonnet/thanos-replicate-mixin/alerts/*
jsonnet jsonnet/thanos-replicate-mixin/alerts.jsonnet | gojsontoyaml > $@
${RULES}: jsonnet/thanos-replicate-mixin/mixin.libsonnet jsonnet/thanos-replicate-mixin/defaults.libsonnet jsonnet/thanos-replicate-mixin/rules/*
jsonnet jsonnet/thanos-replicate-mixin/rules.jsonnet | gojsontoyaml > $@
.PHONY: jsonnet-vendor
jsonnet-vendor: jsonnetfile.json
rm -rf jsonnet/vendor
jb install --jsonnetpkg-home="jsonnet/vendor"
.PHONY: fmt
fmt:
@fmt_res=$$(gofmt -d -s $$(find . -type f -name '*.go' -not -path './vendor/*' -not -path './jsonnet/vendor/*')); if [ -n "$$fmt_res" ]; then printf '\nGofmt found style issues. Please check the reported issues\nand fix them if necessary before submitting the code for review:\n\n%s' "$$fmt_res"; exit 1; fi
@echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNET_FMT) -i