Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
199 lines (167 loc) · 5.55 KB
/
Copy pathMakefile
File metadata and controls
199 lines (167 loc) · 5.55 KB
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
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)
export GO111MODULE := on
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
PKG := $(shell awk '/^module/ { print $$2 }' go.mod)
GOOS ?= $(shell go env GOOS)
GOPROXY ?= $(shell go env GOPROXY)
VERSION ?= $(shell git describe --dirty --tags --match='v*')
GOARCH :=
LDFLAGS := "-w -s -X 'k8s.io/component-base/version.gitVersion=$(VERSION)' -X 'k8s.io/cloud-provider-openstack/pkg/version.Version=$(VERSION)'"
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 \
osbrick-sidecar
ARCH ?= amd64
ARCHS ?= amd64 arm64 ppc64le s390x
# Architectures for osbrick-sidecar: restricted to platforms where PyPI
# ships pre-built grpcio wheels (no QEMU source-compile) and Debian
# Trixie ships Ceph packages.
OSBRICK_ARCHS ?= amd64 arm64
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
export GOLANGCI_LINT_VERSION ?= v2.14.0
export HELM_UNITTEST_VERSION ?= v1.1.2
# CTI targets
build-all-archs:
@for arch in $(ARCHS); do $(MAKE) ARCH=$${arch} build ; done
.PHONY: build
build: $(BUILD_CMDS)
$(BUILD_CMDS):
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOPROXY=${GOPROXY} go build \
-trimpath \
-ldflags $(LDFLAGS) \
-o $@ \
cmd/$@/main.go
.PHONY: test
test: unit functional
check:
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --timeout=20m ./...
.PHONY: lint-charts
lint-charts:
hack/verify-helm-charts.sh
.PHONY: unit
unit:
go test -tags=unit $(shell go list ./... | sed -e '/sanity/ { N; d; }' | sed -e '/tests/ {N; d;}') $(TESTARGS)
.PHONY: functional
functional:
@echo "$@ not yet implemented"
.PHONY: test-cinder-csi-sanity
test-cinder-csi-sanity:
go test $(GIT_HOST)/$(BASE_DIR)/tests/sanity/cinder
.PHONY: test-manila-csi-sanity
test-manila-csi-sanity:
go test $(GIT_HOST)/$(BASE_DIR)/tests/sanity/manila
test-sidecar:
cd sidecar && pip install --quiet -r test-requirements.txt
cd sidecar && ./generate_proto.sh
cd sidecar && PYTHONPATH=. python -m pytest tests/ $(TESTARGS)
# kept for compatibility reasons.
.PHONY: fmt
fmt: check
.PHONY: lint
lint: check
.PHONY: vet
vet: check
.PHONY: cover
cover:
go test -tags=unit $(shell go list ./...) -cover
# 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 "PKG: $(PKG)"
go version
go env
# Get our dev/test dependencies in place
bootstrap:
tools/test-setup.sh
.PHONY: clean
clean:
@echo "clean builds binary"
@for binary in $(BUILD_CMDS); do rm -rf $${binary}*; done
.PHONY: realclean
realclean: clean
rm -rf vendor
if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
rm -rf $(GOPATH); \
fi
# 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
.PHONY: build-local-images
build-local-images: $(addprefix build-local-image-,$(IMAGE_NAMES))
# Build a single image for all architectures in ARCHS but don't push it anywhere
build-multiarch-image-%:
$(CONTAINER_ENGINE) buildx build --output type=cacheonly \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
--platform $(shell echo $(addprefix linux/,$(ARCHS)) | sed 's/ /,/g') \
--target $* \
.
# Build all multiarch images
.PHONY: build-multiarch-images
build-multiarch-images: $(addprefix build-multiarch-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
.PHONY: push-multiarch-images
push-multiarch-images: $(addprefix push-multiarch-image-,$(IMAGE_NAMES))
# Sidecar images use their own Dockerfiles instead of multi-stage targets
# in the main Dockerfile. Explicit rules override the pattern rules above.
.PHONY: build-local-image-osbrick-sidecar
build-local-image-osbrick-sidecar:
$(CONTAINER_ENGINE) buildx build --output type=docker \
--tag $(REGISTRY)/osbrick-sidecar:$(VERSION) \
-f sidecar/Dockerfile.osbrick-sidecar \
.
.PHONY: build-multiarch-image-osbrick-sidecar
build-multiarch-image-osbrick-sidecar:
$(CONTAINER_ENGINE) buildx build --output type=cacheonly \
--tag $(REGISTRY)/osbrick-sidecar:$(VERSION) \
--platform $(shell echo $(addprefix linux/,$(OSBRICK_ARCHS)) | sed 's/ /,/g') \
-f sidecar/Dockerfile.osbrick-sidecar \
.
.PHONY: push-multiarch-image-osbrick-sidecar
push-multiarch-image-osbrick-sidecar:
$(CONTAINER_ENGINE) buildx build --output type=registry \
--tag $(REGISTRY)/osbrick-sidecar:$(VERSION) \
--platform $(shell echo $(addprefix linux/,$(OSBRICK_ARCHS)) | sed 's/ /,/g') \
-f sidecar/Dockerfile.osbrick-sidecar \
.
.PHONY: version
version:
@echo ${VERSION}