forked from virtual-kubelet/virtual-kubelet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
192 lines (155 loc) · 5.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
SHELL := /bin/bash
DOCKER_IMAGE := virtual-kubelet
exec := $(DOCKER_IMAGE)
github_repo := virtual-kubelet/virtual-kubelet
binary := virtual-kubelet
GOTEST ?= go test $(if $V,-v)
export GO111MODULE ?= on
include Makefile.e2e
# Currently this looks for a globally installed gobin. When we move to modules,
# should consider installing it locally
# Also, we will want to lock our tool versions using go mod:
# https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
gobin_tool ?= $(shell which gobin || echo $(GOPATH)/bin/gobin)
goimports := golang.org/x/tools/cmd/[email protected]
gocovmerge := github.com/wadey/gocovmerge@b5bfa59ec0adc420475f97f89b58045c721d761c
goreleaser := github.com/goreleaser/[email protected]
gox := github.com/mitchellh/[email protected]
# comment this line out for quieter things
# V := 1 # When V is set, try to enable extra logging for debugging
# Space separated patterns of packages to skip in list, test, format.
IGNORED_PACKAGES := /vendor/
TEST_OS := $(shell go env GOOS)
TEST_ARCH := $(shell go env GOARCH)
.PHONY: all
all: test build
.PHONY: safebuild
# safebuild builds inside a docker container with no clingons from your $GOPATH
safebuild:
@echo "Building..."
docker build --build-arg BUILD_TAGS="$(VK_BUILD_TAGS)" -t $(DOCKER_IMAGE):$(VERSION) .
.PHONY: build
build: build_tags := netgo osusergo
build: OUTPUT_DIR ?= bin
build: authors
@echo "Building..."
CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o $(OUTPUT_DIR)/$(binary) $(if $V,-v) $(VERSION_FLAGS) ./cmd/$(binary)
.PHONY: tags
tags:
@echo "Listing tags..."
@git tag
.PHONY: release
release: build goreleaser
$(gobin_tool) -run $(goreleaser)
##### =====> Utility targets <===== #####
.PHONY: clean test list cover format docker
mod:
@echo "Prune Dependencies..."
go mod tidy
docker:
@echo "Docker Build..."
docker build --build-arg BUILD_TAGS="$(VK_BUILD_TAGS)" -t $(DOCKER_IMAGE) .
clean:
@echo "Clean..."
rm -rf bin
vet:
@echo "go vet'ing..."
ifndef CI
@echo "go vet'ing Outside CI..."
go vet $(TESTDIRS)
else
@echo "go vet'ing in CI..."
mkdir -p test
( go vet $(TESTDIRS); echo $$? ) | \
tee test/vet.txt | sed '$$ d'; exit $$(tail -1 test/vet.txt)
endif
test:
$(GOTEST) $(TESTDIRS)
list:
@echo "List..."
@echo $(TESTDIRS)
cover: gocovmerge
@echo "Coverage Report..."
@echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!"
rm -f .GOPATH/cover/*.out cover/all.merged
$(if $V,@echo "-- go test -coverpkg=./... -coverprofile=cover/... ./...")
@for MOD in $(TESTDIRS); do \
go test -coverpkg=`echo $(TESTDIRS)|tr " " ","` \
-coverprofile=cover/unit-`echo $$MOD|tr "/" "_"`.out \
$$MOD 2>&1 | grep -v "no packages being tested depend on"; \
done
$(gobin_tool) -run $(gocovmerge) cover/*.out > cover/all.merged
ifndef CI
@echo "Coverage Report..."
go tool cover -html .GOPATH/cover/all.merged
else
@echo "Coverage Report In CI..."
go tool cover -html .GOPATH/cover/all.merged -o .GOPATH/cover/all.html
endif
@echo ""
@echo "=====> Total test coverage: <====="
@echo ""
go tool cover -func .GOPATH/cover/all.merged
format: goimports
@echo "Formatting..."
find . -iname \*.go | grep -v \
-e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) | xargs $(gobin_tool) -run $(goimports) -w
##### =====> Internals <===== #####
.PHONY: setup
setup: goimports gocovmerge goreleaser gox clean
env
@echo "Setup..."
if ! grep "/bin" .gitignore > /dev/null 2>&1; then \
echo "/bin" >> .gitignore; \
fi
if ! grep "/cover" .gitignore > /dev/null 2>&1; then \
echo "/cover" >> .gitignore; \
fi
mkdir -p cover
mkdir -p bin
mkdir -p test
VERSION := $(shell git describe --tags --always --dirty="-dev")
DATE := $(shell date -u '+%Y-%m-%d-%H:%M UTC')
VERSION_FLAGS := -ldflags='-X "main.buildVersion=$(VERSION)" -X "main.buildTime=$(DATE)"'
TESTDIRS ?= ./...
.PHONY: goimports
goimports: $(gobin_tool)
$(gobin_tool) -d $(goimports)
.PHONY: gocovmerge
gocovmerge: $(gobin_tool)
$(gobin_tool) -d $(gocovmerge)
.PHONY: goreleaser
goreleaser: $(gobin_tool)
$(gobin_tool) -d $(goreleaser)
.PHONY: gox
gox: $(gobin_tool)
# We make gox globally available, for people to use by hand
$(gobin_tool) $(gox)
$(gobin_tool):
GO111MODULE=off go get -u github.com/myitcv/gobin
authors:
git log --all --format='%aN <%cE>' | sort -u | sed -n '/github/!p' > GITAUTHORS
cat AUTHORS GITAUTHORS | sort -u > NEWAUTHORS
mv NEWAUTHORS AUTHORS
rm -f NEWAUTHORS
rm -f GITAUTHORS
checksums_2.3.1.txt:
curl -o checksums_2.3.1.txt -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/checksums.txt
kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}.tar.gz:
curl -C - -O -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}.tar.gz
kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}: kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}.tar.gz checksums_2.3.1.txt
sha256sum -c --ignore-missing checksums_2.3.1.txt
tar -xvf kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}.tar.gz
.PHONY: envtest
envtest: kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}
# You can add klog flags for debugging, like: -klog.v=10 -klog.logtostderr
# klogv2 flags just wraps our existing logrus.
KUBEBUILDER_ASSETS=$(PWD)/kubebuilder_2.3.1_${TEST_OS}_${TEST_ARCH}/bin $(GOTEST) -run=TestEnvtest ./node -envtest=true
.PHONY: fmt
fmt:
goimports -w $(shell go list -f '{{.Dir}}' ./...)
export GOLANG_CI_LINT_VERSION ?= v1.49.0
DOCKER_BUILD ?= docker buildx build
.PHONY: lint
lint:
$(DOCKER_BUILD) --target=lint --build-arg GOLANG_CI_LINT_VERSION --build-arg OUT_FORMAT .