forked from observatorium/up
/
Makefile
89 lines (67 loc) · 2.66 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
89
include .bingo/Variables.mk
BIN_DIR ?= ./tmp/bin
THANOS=$(BIN_DIR)/thanos
LOKI ?= $(BIN_DIR)/loki
LOKI_VERSION ?= 1.5.0
EXAMPLES := examples
MANIFESTS := ${EXAMPLES}/manifests
all: build generate validate
build: up
.PHONY: up
up: vendor
CGO_ENABLED=0 go build -v -ldflags '-w -extldflags '-static'' ./cmd/up
.PHONY: generate
generate: jsonnet-fmt ${MANIFESTS} README.md
.PHONY: validate
validate: $(KUBEVAL) $(MANIFESTS)
$(KUBEVAL) --ignore-missing-schemas $(MANIFESTS)/*.yaml
.PHONY: vendor
vendor: go.mod go.sum
go mod tidy
go mod vendor
.PHONY: go-fmt
go-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
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v -c .golangci.yml
container: Dockerfile up
docker build -t quay.io/observatorium/up:latest .
.PHONY: clean
clean:
-rm tmp/help.txt
-rm ./up
tmp/help.txt: clean build
mkdir -p tmp
-./up --help >tmp/help.txt 2>&1
.PHONY: README.md
README.md: $(EMBEDMD) tmp/help.txt
$(EMBEDMD) -w README.md
.PHONY: test-integration
test-integration: build test/integration.sh | $(THANOS) $(LOKI)
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./test/integration.sh
.PHONY: ${MANIFESTS}
${MANIFESTS}: jsonnet/main.jsonnet jsonnet/*.libsonnet $(JSONNET) $(GOJSONTOYAML)
@rm -rf ${MANIFESTS}
@mkdir -p ${MANIFESTS}
$(JSONNET) -J jsonnet/vendor -m ${MANIFESTS} jsonnet/main.jsonnet | xargs -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml && rm -f {}' -- {}
JSONNET_SRC = $(shell find . -name 'vendor' -prune -o -name 'examples/vendor' -prune -o -name 'tmp' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print)
JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s
.PHONY: jsonnet-fmt
jsonnet-fmt: | $(JSONNETFMT)
PATH=$$PATH:$(BIN_DIR):$(FIRST_GOPATH)/bin echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNETFMT_CMD) -i
.PHONY: format
format: $(GOLANGCI_LINT) go-fmt jsonnet-fmt
$(GOLANGCI_LINT) run --fix -c .golangci.yml
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(THANOS): $(BIN_DIR)
wget -O ./tmp/thanos.tar.gz https://github.com/thanos-io/thanos/releases/download/v0.11.0/thanos-0.11.0.linux-amd64.tar.gz
tar xvfz ./tmp/thanos.tar.gz -C ./tmp
mv ./tmp/thanos-0.11.0.linux-amd64/thanos $@
$(LOKI): $(BIN_DIR)
loki_pkg="loki-$$(go env GOOS)-$$(go env GOARCH)" && \
cd $(BIN_DIR) && curl -O -L "https://github.com/grafana/loki/releases/download/v$(LOKI_VERSION)/$$loki_pkg.zip" && \
unzip $$loki_pkg.zip && \
mv $$loki_pkg loki && \
rm $$loki_pkg.zip