-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·166 lines (130 loc) · 4.88 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
# Image URL to use all building/pushing image targets
IMG ?= onmetal-csi-driver:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.0
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
ENVTEST ?= $(LOCALBIN)/setup-envtest
ADDLICENSE ?= $(LOCALBIN)/addlicense
GOIMPORTS ?= $(LOCALBIN)/goimports
MOCKGEN ?= $(LOCALBIN)/mockgen
## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
ADDLICENSE_VERSION ?= v1.1.1
MOCKGEN_VERSION ?= v0.3.0
GOIMPORTS_VERSION ?= v0.13.0
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
BINARY_NAME=onmetal-csi-driver
DOCKER_IMAGE=onmetal-csi-driver
BUILDARGS ?=
# For Development Build #################################################################
# Docker.io username and tag
DOCKER_USER=onmetal
DOCKER_IMAGE_TAG=latest
# For Development Build #################################################################
# For Production Build ##################################################################
ifeq ($(env),prod)
# For Production
# Do not change following values unless change in production version or username
#For docker.io
DOCKER_USER=your_docker_user_name
DOCKER_IMAGE_TAG=1.1.0
endif
# For Production Build ##################################################################
##@ Tools
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
build:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/
lint: ## Run golangci-lint against code.
golangci-lint run ./...
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
modverify:
$(GOMOD) verify
modtidy:
$(GOMOD) tidy
moddownload:
$(GOMOD) download
# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME) -v ./cmd/
docker-build:
docker build $(BUILDARGS) -t ${IMG} -f Dockerfile .
docker-push:
docker push ${IMG}
buildlocal: build docker-build clean
all: build docker-build docker-push clean
deploy:
cd config/manager && $(KUSTOMIZE) edit set image onmetal-csi-driver=${IMG}
kubectl apply -k config/default
undeploy:
kubectl delete -k config/default
.PHONY: fmt
fmt: goimports ## Run goimports against code.
$(GOIMPORTS) -w .
vet: ## Run go vet against code.
go vet ./...
test: generate-mocks fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
.PHONY: add-license
add-license: addlicense ## Add license headers to all go files.
find . -name '*.go' -exec $(ADDLICENSE) -c 'OnMetal authors' {} +
.PHONY: check-license
check-license: addlicense ## Check that every file has a license header present.
find . -name '*.go' -exec $(ADDLICENSE) -check -c 'OnMetal authors' {} +
.PHONY: check
check: add-license fmt lint test # Generate manifests, code, lint, add licenses, test
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: addlicense
addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary.
$(ADDLICENSE): $(LOCALBIN)
test -s $(LOCALBIN)/addlicense || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION)
.PHONY: goimports
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
test -s $(LOCALBIN)/goimports || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
.PHONY: generate-mocks
generate-mocks: mockgen ## Generate code (mocks etc.).
MOCKGEN=$(MOCKGEN) go generate ./...
./hack/fix-mountwrapper-mock.sh
.PHONY: mockgen
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
$(MOCKGEN): $(LOCALBIN)
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)