forked from kubernetes/cloud-provider-openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
327 lines (265 loc) · 11.2 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# 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 := $(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)
GIT_VERSION := $(shell git describe --dirty --tags --match='v*')
VERSION ?= $(GIT_VERSION)
ALPINE_ARCH :=
DEBIAN_ARCH :=
QEMUARCH :=
QEMUVERSION := "v4.2.0-4"
GOARCH :=
GOFLAGS :=
TAGS :=
LDFLAGS := "-w -s -X 'k8s.io/component-base/version.gitVersion=$(VERSION)'"
GOX_LDFLAGS := $(shell echo "$(LDFLAGS) -extldflags \"-static\"")
REGISTRY ?= k8scloudprovider
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
# This option is for running docker manifest command
export DOCKER_CLI_EXPERIMENTAL := enabled
# CTI targets
$(GOBIN):
echo "create gobin"
mkdir -p $(GOBIN)
work: $(GOBIN)
ifeq ($(ARCH),arm)
DEBIAN_ARCH=$(ARCH)
GOARCH=$(ARCH)
QEMUARCH=$(ARCH)
ALPINE_ARCH=arm32v7
else ifeq ($(ARCH),arm64)
DEBIAN_ARCH=$(ARCH)
GOARCH=$(ARCH)
QEMUARCH=aarch64
ALPINE_ARCH=arm64v8
else
DEBIAN_ARCH=$(ARCH)
GOARCH=$(ARCH)
QEMUARCH=$(ARCH)
ALPINE_ARCH=$(ARCH)
endif
build-all-archs:
@for arch in $(ARCHS); do $(MAKE) ARCH=$${arch} build ; done
build: $(addprefix build-cmd-,$(BUILD_CMDS))
client-keystone-auth: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o client-keystone-auth \
cmd/client-keystone-auth/main.go
# Remove individual go build targets, once we migrate openlab-zuul-jobs
# to use new build-cmd-% targets.
cinder-csi-plugin: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o cinder-csi-plugin \
cmd/cinder-csi-plugin/main.go
# This target is for supporting CI jobs of release-1.17 branch. We should delete this target once 1.17 support is dropped and change the cinder-csi-plugin related CI jobs to use target image-cinder-csi-plugin
image-csi-plugin:
$(MAKE) image-cinder-csi-plugin
manila-csi-plugin: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o manila-csi-plugin \
cmd/manila-csi-plugin/main.go
# Remove this individual go build target, once we remove
# image-controller-manager below.
openstack-cloud-controller-manager: work $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags $(LDFLAGS) \
-o openstack-cloud-controller-manager-$(ARCH) \
cmd/openstack-cloud-controller-manager/main.go
# Remove individual image builder once we migrate openlab-zuul-jobs
# to use new image-openstack-cloud-controller-manager target.
image-controller-manager: work openstack-cloud-controller-manager
ifeq ($(GOOS),linux)
cp -r cluster/images/openstack-cloud-controller-manager $(TEMP_DIR)
cp openstack-cloud-controller-manager-$(ARCH) $(TEMP_DIR)/openstack-cloud-controller-manager
cp $(TEMP_DIR)/openstack-cloud-controller-manager/Dockerfile.build $(TEMP_DIR)/openstack-cloud-controller-manager/Dockerfile
$(CONTAINER_ENGINE) build -t $(REGISTRY)/openstack-cloud-controller-manager:$(VERSION) $(TEMP_DIR)/openstack-cloud-controller-manager
rm -rf $(TEMP_DIR)/openstack-cloud-controller-manager
else
$(error Please set GOOS=linux for building the image)
endif
build-cmd-%: work $(SOURCES)
@# Keep binary with no arch mark. We should remove this once we correct
@# openlab-zuul-jobs.
CGO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o $* \
cmd/$*/main.go
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags $(LDFLAGS) \
-o $*-$(ARCH) \
cmd/$*/main.go
test: unit functional
check: work
go run github.com/golangci/golangci-lint/cmd/[email protected] run ./... --config .golangci-check.yaml
# NOTE(chrigl): ci actually runs make check. Because golint didn't run on the code for quite some
# time, most linters in make check are disabled. codehygiene serves as a helper to further
# improve the quality of the code base.
codeclimate: work
go run github.com/golangci/golangci-lint/cmd/[email protected] 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
push-manifest-%:
$(CONTAINER_ENGINE) manifest create --amend $(REGISTRY)/$*:$(VERSION) $(shell echo $(ARCHS) | sed -e "s~[^ ]*~$(REGISTRY)/$*\-&:$(VERSION)~g")
@for arch in $(ARCHS); do $(CONTAINER_ENGINE) manifest annotate --os $(IMAGE_OS) --arch $${arch} $(REGISTRY)/$*:${VERSION} $(REGISTRY)/$*-$${arch}:${VERSION}; done
$(CONTAINER_ENGINE) manifest push --purge $(REGISTRY)/$*:${VERSION}
push-all-manifest: $(addprefix push-manifest-,$(IMAGE_NAMES))
build-images: $(addprefix image-,$(IMAGE_NAMES))
push-images: $(addprefix push-image-,$(IMAGE_NAMES))
image-%: work
$(MAKE) $(addprefix build-cmd-,$*)
ifeq ($(GOOS),linux)
cp -r cluster/images/$* $(TEMP_DIR)
ifneq ($(ARCH),amd64)
$(CONTAINER_ENGINE) run --rm --privileged multiarch/qemu-user-static --reset -p yes
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)/$*
@# Ensure we don't get surprised by umask settings
chmod 0755 $(TEMP_DIR)/$*/qemu-$(QEMUARCH)-static
sed "/^FROM .*/a COPY qemu-$(QEMUARCH)-static /usr/bin/" $(TEMP_DIR)/$*/Dockerfile.build > $(TEMP_DIR)/$*/Dockerfile.build.tmp
mv $(TEMP_DIR)/$*/Dockerfile.build.tmp $(TEMP_DIR)/$*/Dockerfile.build
endif
cp $*-$(ARCH) $(TEMP_DIR)/$*
$(CONTAINER_ENGINE) build --build-arg ALPINE_ARCH=$(ALPINE_ARCH) --build-arg ARCH=$(ARCH) --build-arg DEBIAN_ARCH=$(DEBIAN_ARCH) --pull -t build-$*-$(ARCH) -f $(TEMP_DIR)/$*/Dockerfile.build $(TEMP_DIR)/$*
$(CONTAINER_ENGINE) create --name build-$*-$(ARCH) build-$*-$(ARCH)
$(CONTAINER_ENGINE) export build-$*-$(ARCH) > $(TEMP_DIR)/$*/$(TAR_FILE)
@echo "build image $(REGISTRY)/$*-$(ARCH)"
$(CONTAINER_ENGINE) build --build-arg ALPINE_ARCH=$(ALPINE_ARCH) --build-arg ARCH=$(ARCH) --build-arg DEBIAN_ARCH=$(DEBIAN_ARCH) --pull -t $(REGISTRY)/$*-$(ARCH):$(VERSION) $(TEMP_DIR)/$*
rm -rf $(TEMP_DIR)/$*
$(CONTAINER_ENGINE) rm build-$*-$(ARCH)
$(CONTAINER_ENGINE) rmi build-$*-$(ARCH)
else
$(error Please set GOOS=linux for building the image)
endif
push-image-%:
@echo "push image $*-$(ARCH) to $(REGISTRY)"
ifneq ($(and $(DOCKER_USERNAME),$(DOCKER_PASSWORD)),)
@$(CONTAINER_ENGINE) login -u="$(DOCKER_USERNAME)" -p="$(DOCKER_PASSWORD)"
endif
$(CONTAINER_ENGINE) push $(REGISTRY)/$*-$(ARCH):$(VERSION)
images: $(addprefix build-arch-image-,$(ARCH))
images-all-archs: $(addprefix build-arch-image-,$(ARCHS))
build-arch-image-%:
@echo "Building images for ARCH=$*"
$(MAKE) ARCH=$* build-images
upload-image-%:
$(MAKE) ARCH=$* build-images push-images
upload-images: $(addprefix upload-image-,$(ARCHS)) push-all-manifest
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