-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMakefile
140 lines (115 loc) · 4.4 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
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
include .bingo/Variables.mk
PREFIX ?= $(shell pwd)
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)
DOCKER_IMAGE_REPO ?= quay.io/thanos/thanosbench
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short HEAD)
# Ensure everything works even if GOPATH is not set, which is often the case.
# Default to standard GOPATH.
GOPATH ?= $(HOME)/go
TMP_GOPATH ?= /tmp/thanos-go
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO111MODULE ?= on
export GO111MODULE
GOPROXY ?= https://proxy.golang.org
export GOPROXY
GIT ?= $(shell which git)
# Support gsed on OSX (installed via brew), falling back to sed. On Linux
# systems gsed won't be installed, so will use sed as expected.
SED ?= $(shell which gsed 2>/dev/null || which sed)
define require_clean_work_tree
@git update-index -q --ignore-submodules --refresh
@if ! git diff-files --quiet --ignore-submodules --; then \
echo >&2 "cannot $1: you have unstaged changes."; \
git diff-files --name-status -r --ignore-submodules -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
echo >&2 "cannot $1: your index contains uncommitted changes."; \
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
endef
.PHONY: all
all: format build
.PHONY: build
build: check-git deps $(PROMU)
@echo ">> building binaries $(GOBIN)"
@$(PROMU) build --prefix $(PREFIX)
# crossbuild builds all binaries for all platforms.
.PHONY: crossbuild
crossbuild: $(PROMU)
@echo ">> crossbuilding all binaries"
$(PROMU) crossbuild -v
.PHONY: gen
gen:
@echo ">> generating benchmarks configs"
@rm -rf benchmarks/**/manifests
@go run benchmarks/base/main.go generate
@go run benchmarks/lts/main.go generate --tag=v0.8.1
@go run benchmarks/remote-read/chunkiter/main.go generate
@go run benchmarks/remote-read/streamedchunks/main.go generate
.PHONY: promu
promu: $(PROMU)
.PHONY: tarballs-release
tarballs-release: $(PROMU)
@echo ">> Publishing tarballs"
$(PROMU) crossbuild -v tarballs
$(PROMU) checksum -v .tarballs
$(PROMU) release -v .tarballs
# deps ensures fresh go.mod and go.sum.
.PHONY: deps
deps:
@go mod tidy
@go mod verify
# docker builds docker with no tag.
.PHONY: docker
docker: build
@echo ">> building docker image 'thanosbench'"
@docker build -t "thanosbench" .
# docker-push pushes docker image build under `thanos` to "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
.PHONY: docker-push
docker-push:
@echo ">> pushing thanosbench image as $(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
@docker tag "thanosbench" "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
@docker push "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
# format formats the code (including imports format).
.PHONY: format
format: $(GOIMPORTS)
@echo ">> formatting code"
@$(GOIMPORTS) -w $(FILES_TO_FMT)
.PHONY: check-git
check-git:
ifneq ($(GIT),)
@test -x $(GIT) || (echo >&2 "No git executable binary found at $(GIT)."; exit 1)
else
@echo >&2 "No git binary found."; exit 1
endif
.PHONY: docs
docs: ## Regenerates flags in docs for all thanos commands.
docs: $(EMBEDMD) build
@EMBEDMD_BIN="$(EMBEDMD)" SED_BIN="$(SED)" THANOSBENCH_BIN="./thanosbench" scripts/genflagdocs.sh
@find . -type f -name "*.md" | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh
.PHONY: lint
# PROTIP:
# Add
# --cpu-profile-path string Path to CPU profile output file
# --mem-profile-path string Path to memory profile output file
#
# to debug big allocations during linting.
lint: check-git $(GOLANGCI_LINT) $(MISSPELL)
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCI_LINT) run --enable goimports --enable goconst --skip-dirs vendor
@echo ">> detecting misspells"
@find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error
# checks Go code comments if they have trailing period (excludes protobuffers and vendor files).
# Comments with more than 3 spaces at beginning are omitted from the check, example: '// - foo'.
.PHONY: check-comments
check-comments:
@printf ">> checking Go comments trailing periods\n\n\n"
@./scripts/build-check-comments.sh
.PHONY: test
test:
@echo ">> running tests"
@go test ./...