forked from kubernetes/cloud-provider-openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
211 lines (169 loc) · 6.59 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# golang-client Makefile
# Follows the interface defined in the Golang CTI proposed
# in https://review.openstack.org/410355
#REPO_VERSION?=$(shell git describe --tags)
GIT_HOST = k8s.io
CONTAINER_ENGINE ?= docker
PWD := $(shell pwd)
BASE_DIR := $(shell basename $(PWD))
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
export GO111MODULE := on
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
PKG := $(shell awk '/^module/ { print $$2 }' go.mod)
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
SOURCES := Makefile go.mod go.sum $(shell find $(DEST) -name '*.go' 2>/dev/null)
HAS_GOX := $(shell command -v gox;)
GOX_PARALLEL ?= 3
TARGETS ?= linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x
DIST_DIRS = find * -type d -exec
TEMP_DIR :=$(shell mktemp -d)
TAR_FILE ?= rootfs.tar
GOOS ?= $(shell go env GOOS)
GOPROXY ?= $(shell go env GOPROXY)
VERSION ?= $(shell git describe --dirty --tags --match='v*')
GOARCH :=
GOFLAGS :=
TAGS :=
LDFLAGS := "-w -s -X 'k8s.io/component-base/version.gitVersion=$(VERSION)' -X 'k8s.io/cloud-provider-openstack/pkg/version.Version=$(VERSION)'"
GOX_LDFLAGS := $(shell echo "$(LDFLAGS) -extldflags \"-static\"")
REGISTRY ?= registry.k8s.io/provider-os
IMAGE_OS ?= linux
IMAGE_NAMES ?= openstack-cloud-controller-manager \
cinder-csi-plugin \
k8s-keystone-auth \
octavia-ingress-controller \
manila-csi-plugin \
barbican-kms-plugin \
magnum-auto-healer
ARCH ?= amd64
ARCHS ?= amd64 arm arm64 ppc64le s390x
BUILD_CMDS ?= openstack-cloud-controller-manager \
cinder-csi-plugin \
k8s-keystone-auth \
octavia-ingress-controller \
manila-csi-plugin \
barbican-kms-plugin \
magnum-auto-healer \
client-keystone-auth
# CTI targets
$(GOBIN):
echo "create gobin"
mkdir -p $(GOBIN)
work: $(GOBIN)
build-all-archs:
@for arch in $(ARCHS); do $(MAKE) ARCH=$${arch} build ; done
build: $(BUILD_CMDS)
$(BUILD_CMDS): $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOPROXY=${GOPROXY} go build \
-trimpath \
-ldflags $(LDFLAGS) \
-o $@ \
cmd/$@/main.go
test: unit functional
check: work
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.0 run ./...
unit: work
go test -tags=unit $(shell go list ./... | sed -e '/sanity/ { N; d; }' | sed -e '/tests/ {N; d;}') $(TESTARGS)
functional:
@echo "$@ not yet implemented"
test-cinder-csi-sanity: work
go test $(GIT_HOST)/$(BASE_DIR)/tests/sanity/cinder
test-manila-csi-sanity: work
go test $(GIT_HOST)/$(BASE_DIR)/tests/sanity/manila
# kept for compatibility reasons.
fmt: check
lint: check
vet: check
cover: work
go test -tags=unit $(shell go list ./...) -cover
docs:
@echo "$@ not yet implemented"
godoc:
@echo "$@ not yet implemented"
releasenotes:
@echo "Reno not yet implemented for this repo"
translation:
@echo "$@ not yet implemented"
# Do the work here
# Set up the development environment
env:
@echo "PWD: $(PWD)"
@echo "BASE_DIR: $(BASE_DIR)"
@echo "GOPATH: $(GOPATH)"
@echo "GOROOT: $(GOROOT)"
@echo "DEST: $(DEST)"
@echo "PKG: $(PKG)"
go version
go env
# Get our dev/test dependencies in place
bootstrap:
tools/test-setup.sh
.bindep:
virtualenv .bindep
.bindep/bin/pip install -i https://pypi.python.org/simple bindep
bindep: .bindep
@.bindep/bin/bindep -b -f bindep.txt || true
install-distro-packages:
tools/install-distro-packages.sh
clean:
rm -rf _dist .bindep
@echo "clean builds binary"
@for binary in $(BUILD_CMDS); do rm -rf $${binary}*; done
realclean: clean
rm -rf vendor
if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
rm -rf $(GOPATH); \
fi
shell:
$(SHELL) -i
# Build a single image for the local default platform and push to the local
# container engine
build-local-image-%:
$(CONTAINER_ENGINE) buildx build --output type=docker \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
--target $* \
.
# Build all images locally
build-local-images: $(addprefix build-image-,$(IMAGE_NAMES))
# Build a single image for all architectures in ARCHS and push it to REGISTRY
push-multiarch-image-%:
$(CONTAINER_ENGINE) buildx build --output type=registry \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
--platform $(shell echo $(addprefix linux/,$(ARCHS)) | sed 's/ /,/g') \
--target $* \
.
# Push all multiarch images
push-multiarch-images: $(addprefix push-multiarch-image-,$(IMAGE_NAMES))
version:
@echo ${VERSION}
.PHONY: build-cross
build-cross: work
ifndef HAS_GOX
echo "installing gox"
go install github.com/mitchellh/gox
endif
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/openstack-cloud-controller-manager/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/cinder-csi-plugin/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/k8s-keystone-auth/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/client-keystone-auth/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/octavia-ingress-controller/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/manila-csi-plugin/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/magnum-auto-healer/
.PHONY: dist
dist: build-cross
( \
cd _dist && \
$(DIST_DIRS) cp ../LICENSE {} \; && \
$(DIST_DIRS) cp ../README.md {} \; && \
$(DIST_DIRS) tar -zcf cloud-provider-openstack-$(VERSION)-{}.tar.gz {} \; && \
$(DIST_DIRS) zip -r cloud-provider-openstack-$(VERSION)-{}.zip {} \; \
)
.PHONY: bindep build clean cover work docs fmt functional lint realclean \
relnotes test translation version build-cross dist codeclimate