-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
98 lines (78 loc) · 2.85 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
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GOOS ?=$(shell go env GOOS)
GOARCH ?=$(shell go env GOARCH)
# Keep an existing GOPATH, make a private one if it is undefined
export GOPATH ?=$(shell pwd)/../.go
export GOBIN ?=$(GOPATH)/bin
# Images management
REGISTRY_SERVER ?=swr.cn-north-4.myhuaweicloud.com
REGISTRY ?=$(REGISTRY_SERVER)/k8s-csi
REGISTRY_USERNAME ?=
REGISTRY_PASSWORD ?=
SOURCES := $(shell find . -name '*.go' 2>/dev/null)
VERSION ?= $(shell git describe --dirty --tags --match='v*')
SECRET := $(shell cat </dev/urandom | head -n 1 | md5sum | head -c 32)
LDFLAGS := "-w -s -X 'github.com/huaweicloud/huaweicloud-csi-driver/pkg/version.Version=$(VERSION)' \
-X 'github.com/huaweicloud/huaweicloud-csi-driver/pkg/obs.Secret=$(SECRET)'"
TEMP_DIR:=$(shell mktemp -d)
ALL ?= evs-csi-plugin \
sfs-csi-plugin
# sfsturbo-csi-plugin
# CTI targets
$(GOBIN):
echo ":: Create GOBIN"
mkdir -p $(GOBIN)
work: $(GOBIN)
build: $(addprefix build-cmd-,$(ALL))
build-cmd-%: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o $* \
cmd/$*/main.go
if [ "$*" = "obs-csi-plugin" ]; then (CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o cluster/images/obs-csi-plugin/csi-connector-server \
cluster/images/obs-csi-plugin/csi-connector-server.go);fi
images: $(addprefix image-,$(ALL))
image-%: work
$(MAKE) $(addprefix build-cmd-,$*)
cp -r cluster/images/$* $(TEMP_DIR)
cp $* $(TEMP_DIR)/$*
@echo ":: Build image $(REGISTRY)/$* ::"
docker build --pull $(TEMP_DIR)/$* -t $(REGISTRY)/$*:$(VERSION)
rm -rf $(TEMP_DIR)/$*
push-images: $(addprefix push-image-,$(ALL))
push-image-%:
@echo ":: Push image $* to $(REGISTRY) ::"
ifneq ($(and $(REGISTRY_USERNAME),$(REGISTRY_PASSWORD)),)
docker login -u ${REGISTRY_USERNAME} -p ${REGISTRY_PASSWORD} ${REGISTRY_SERVER}
endif
docker push $(REGISTRY)/$*:$(VERSION)
clean:
@echo ":: Clean builds binary ::"
@for binary in $(ALL); do rm -rf $${binary}*; done
test: work
go test --race --v ./pkg/...
go test --race --v ./cmd/...
verify:
hack/verify.sh
lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run --config ./ ./...
fmt:
hack/update-gofmt.sh
vet:
hack/check-govet.sh
version:
@echo ${VERSION}