-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
97 lines (73 loc) · 2.58 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
TOOLS_BIN_DIR ?= $(shell pwd)/tmp/bin
export PATH := $(TOOLS_BIN_DIR):$(PATH)
GOLANGCILINTER_BINARY=$(TOOLS_BIN_DIR)/golangci-lint
MDOX_BINARY=$(TOOLS_BIN_DIR)/mdox
MDOX_VALIDATE_CONFIG?=.mdox.validate.yaml
TOOLING=$(MDOX_BINARY) $(GOLANGCILINTER_BINARY)
MD_FILES_TO_FORMAT=$(shell ls *.md)
REVISION ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
RELEASE_VERSION ?=$(shell git describe --tags --abbrev=0 2>/dev/null || echo $(REVISION))
BINARY_FOLDER=bin
BINARY_NAME=prom-analytics-proxy
ARTIFACT_NAME=coralogix/$(BINARY_NAME)
GOCMD=go
GOMAIN=main.go
GOBUILD=$(GOCMD) build
GOOS?=$(shell go env GOOS)
ENVVARS=GOOS=$(GOOS) CGO_ENABLED=0
LDFLAGS=-w -extldflags "-static" \
-X github.com/prometheus/common/version.Version=$(RELEASE_VERSION) \
-X github.com/prometheus/common/version.Revision=$(REVISION) \
-X github.com/prometheus/common/version.Branch=$(BRANCH) \
-X github.com/prometheus/common/version.BuildUser=$(shell whoami) \
-X "github.com/prometheus/common/version.BuildDate=$(shell date -u)"
.PHONY: docker-build
docker-build:
@DOCKER_BUILDKIT=1 docker build -t ${ARTIFACT_NAME}:${RELEASE_VERSION} -f Dockerfile --progress=plain .
.PHONY: build
build:
$(ENVVARS) $(GOCMD) build -ldflags '$(LDFLAGS)' -o $(BINARY_FOLDER)/$(BINARY_NAME) -v $(GOMAIN)
.PHONY: deps
deps:
$(ENVVARS) $(GOCMD) mod download
.PHONY: fmt
fmt:
$(ENVVARS) $(GOCMD) fmt -x ./...
.PHONY: vet
vet:
$(ENVVARS) $(GOCMD) vet ./...
.PHONY: tests
tests:
$(ENVVARS) $(GOCMD) test ./...
.PHONY: check-golang
check-golang: $(GOLANGCILINTER_BINARY)
$(GOLANGCILINTER_BINARY) run
.PHONY: fix-golang
fix-golang: $(GOLANGCILINTER_BINARY)
$(GOLANGCILINTER_BINARY) run --fix
.PHONY: docs
docs: $(MDOX_BINARY)
@echo ">> formatting and local/remote link check"
$(MDOX_BINARY) fmt --soft-wraps -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)
.PHONY: check-docs
check-docs: $(MDOX_BINARY)
@echo ">> checking formatting and local/remote links"
$(MDOX_BINARY) fmt --soft-wraps --check -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)
all: fmt vet tests deps build
.PHONY: tidy
tidy:
go mod tidy -v
cd scripts && go mod tidy -v -modfile=go.mod -compat=1.18
.PHONY: uibuild
uibuild:
cd ui && npm run build
.PHONY: uidependencies
uidependencies:
cd ui && npm install
.PHONY: build
$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)
$(TOOLING): $(TOOLS_BIN_DIR)
@echo Installing tools from scripts/tools.go
@cat scripts/tools.go | grep _ | awk -F'"' '{print $$2}' | GOBIN=$(TOOLS_BIN_DIR) xargs -tI % go install -mod=readonly -modfile=scripts/go.mod %