-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
98 lines (79 loc) · 3.94 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
FLAGS =
TESTENVVAR =
REGISTRY = piranhahu
TAG = $(shell git describe --abbrev=0 || git rev-parse --short HEAD)
PKGS = $(shell go list ./... | grep -v /vendor/)
ARCH ?= $(shell go env GOARCH)
BuildDate = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
Commit = $(shell git rev-parse --short HEAD)
ALL_ARCH = amd64
PKG=github.com/tmon546596046/board-state-metrics/pkg
GO_VERSION=1.15.5
JB_BINARY:=$(firstword $(subst :, ,$(GOPATH)))/bin/jb
JSONNET_VENDOR=jsonnet/jsonnetfile.lock.json jsonnet/vendor
JSONNET_SRC=$(shell find ./jsonnet -type f)
GOJSONTOYAML_BINARY:=$(firstword $(subst :, ,$(GOPATH)))/bin/gojsontoyaml
IMAGE = $(REGISTRY)/board-state-metrics
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
validate-modules:
@echo "- Verifying that the dependencies have expected content..."
GO111MODULE=on go mod verify
@echo "- Checking for any unused/missing packages in go.mod..."
GO111MODULE=on go mod tidy
@echo "- Checking for unused packages in vendor..."
GO111MODULE=on go mod vendor
@git diff --exit-code -- go.sum go.mod vendor/
doccheck:
@echo "- Checking if the documentation is up to date..."
@grep -hoE '(board_[^ |]+)' docs/* --exclude=README.md| sort -u > documented_metrics
@sed -n 's/.*# TYPE \(board_[^ ]\+\).*/\1/p' pkg/collectors/*_test.go | sort -u > tested_metrics
@diff -u0 tested_metrics documented_metrics || (echo "ERROR: Metrics with - are present in tests but missing in documentation, metrics with + are documented but not tested."; exit 1)
@echo OK
@rm -f tested_metrics documented_metrics
@echo "- Checking for orphan documentation files"
@cd docs; for doc in *.md; do if [ "$$doc" != "README.md" ] && ! grep -q "$$doc" *.md; then echo "ERROR: No link to documentation file $${doc} detected"; exit 1; fi; done
@echo OK
gofmtcheck:
@go fmt $(PKGS) | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi
build: clean
GO111MODULE=on GOOS=$(shell uname -s | tr A-Z a-z) GOPROXY=https://goproxy.cn GOARCH=$(ARCH) CGO_ENABLED=0 go build -mod=vendor -ldflags "-s -w -X ${PKG}/version.Release=${TAG} -X ${PKG}/version.Commit=${Commit} -X ${PKG}/version.BuildDate=${BuildDate}" -o board-state-metrics
test-unit: clean build
GO111MODULE=on GOOS=$(shell uname -s | tr A-Z a-z) GOPROXY=https://goproxy.cn GOARCH=$(ARCH) $(TESTENVVAR) go test --race $(FLAGS) $(PKGS)
TEMP_DIR := $(shell mktemp -d)
all: all-container
sub-container-%:
$(MAKE) --no-print-directory ARCH=$* container
sub-push-%:
$(MAKE) --no-print-directory ARCH=$* push
all-container: $(addprefix sub-container-,$(ALL_ARCH))
all-push: $(addprefix sub-push-,$(ALL_ARCH))
container: .container-$(ARCH)
.container-$(ARCH):
docker run --rm -v "$$PWD":/go/src/github.com/tmon546596046/board-state-metrics -w /go/src/github.com/tmon546596046/board-state-metrics -e GO111MODULE=on -e GOPROXY=https://goproxy.cn -e GOOS=linux -e GOARCH=$(ARCH) -e CGO_ENABLED=0 golang:${GO_VERSION} go build -ldflags "-s -w -X ${PKG}/version.Release=${TAG} -X ${PKG}/version.Commit=${Commit} -X ${PKG}/version.BuildDate=${BuildDate}" -o board-state-metrics
cp -r * $(TEMP_DIR)
docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)
docker tag $(MULTI_ARCH_IMG):$(TAG) $(MULTI_ARCH_IMG):latest
ifeq ($(ARCH), amd64)
# Adding check for amd64
docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):latest
endif
docker-push: .docker-push-$(ARCH)
.docker-push-$(ARCH): .container-$(ARCH)
docker push $(MULTI_ARCH_IMG):$(TAG)
docker push $(MULTI_ARCH_IMG):latest
ifeq ($(ARCH), amd64)
docker push $(IMAGE):$(TAG)
docker push $(IMAGE):latest
endif
jsonnet/vendor: $(JB_BINARY) jsonnet/jsonnetfile.json
cd jsonnet && jb install
manifests: $(JSONNET_SRC) $(JSONNET_VENDOR) $(GOJSONTOYAML_BINARY) hack/build-jsonnet.sh
./hack/build-jsonnet.sh
$(JB_BINARY):
go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
$(GOJSONTOYAML_BINARY):
go get -u github.com/brancz/gojsontoyaml
clean:
rm -f board-state-metrics
.PHONY: all build all-push all-container test-unit container docker-push clean validate-modules