forked from clusterpedia-io/clusterpedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
275 lines (237 loc) · 8.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
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
ON_PLUGINS ?= true
REGISTRY ?= "ghcr.io/clusterpedia-io/clusterpedia"
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
RELEASE_ARCHS ?= amd64 arm64
VERSION ?= $(shell git tag --points-at HEAD --sort -version:refname "v*" | head -1)
ifeq ($(VERSION),)
VERSION="latest"
endif
BUILDER_IMAGE_TAG = $(shell git rev-parse HEAD)
GIT_DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(GIT_DIFF), 1)
BUILDER_IMAGE_TAG := $(BUILDER_IMAGE_TAG)-dirty
endif
HOSTARCH = $(shell go env GOHOSTARCH)
all: apiserver binding-apiserver clustersynchro-manager controller-manager
gen-clusterconfigs:
./hack/gen-clusterconfigs.sh
clean-clusterconfigs:
./hack/clean-clusterconfigs.sh
.PHONY: crds
crds:
./hack/update-crds.sh
.PHONY: codegen
codegen:
./hack/update-codegen.sh
.PHONY: vendor
vendor:
./hack/update-vendor.sh
.PHONY: lint
lint: golangci-lint
$(GOLANGLINT_BIN) run
.PHONY: lint-fix
lint-fix: golangci-lint
$(GOLANGLINT_BIN) run --fix
.PHONY: test
test:
go test -race -cover -v ./pkg/...
.PHONY: clean
clean: clean-images
rm -rf bin
.PHONY: apiserver
apiserver:
ifeq ($(ON_PLUGINS), true)
hack/builder.sh $@
else
hack/builder-nocgo.sh $@
endif
.PHONY: binding-apiserver
binding-apiserver:
ifeq ($(ON_PLUGINS), true)
hack/builder.sh $@
else
hack/builder-nocgo.sh $@
endif
.PHONY: clustersynchro-manager
clustersynchro-manager:
ifeq ($(ON_PLUGINS), true)
hack/builder.sh $@
else
hack/builder-nocgo.sh $@
endif
.PHONY: controller-manager
controller-manager:
hack/builder-nocgo.sh $@
.PHONY: images
images: image-builder image-apiserver image-binding-apiserver image-clustersynchro-manager image-controller-manager
image-builder:
docker buildx build \
-t $(REGISTRY)/builder-$(GOARCH):$(BUILDER_IMAGE_TAG) \
--platform=linux/$(GOARCH) \
--load \
-f builder.dockerfile . ; \
build-image-%:
GOARCH=$(HOSTARCH) $(MAKE) image-builder
$(MAKE) $(subst build-,,$@)
image-apiserver:
docker buildx build \
-t $(REGISTRY)/apiserver-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BUILDER_IMAGE=$(REGISTRY)/builder-$(HOSTARCH):$(BUILDER_IMAGE_TAG) \
--build-arg BIN_NAME=apiserver .
image-binding-apiserver:
docker buildx build \
-t $(REGISTRY)/binding-apiserver-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BUILDER_IMAGE=$(REGISTRY)/builder-$(HOSTARCH):$(BUILDER_IMAGE_TAG) \
--build-arg BIN_NAME=binding-apiserver .
image-clustersynchro-manager:
docker buildx build \
-t $(REGISTRY)/clustersynchro-manager-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BUILDER_IMAGE=$(REGISTRY)/builder-$(HOSTARCH):$(BUILDER_IMAGE_TAG) \
--build-arg BIN_NAME=clustersynchro-manager .
image-controller-manager:
docker buildx build \
-t $(REGISTRY)/controller-manager-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BUILDER_IMAGE=$(REGISTRY)/builder-$(HOSTARCH):$(BUILDER_IMAGE_TAG) \
--build-arg BIN_NAME=controller-manager .
.PHONY: push-images
push-images: push-apiserver-image push-binding-apiserver-image push-clustersynchro-manager-image push-controller-manager-image
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-builder-image: clean-builder-manifest
set -e; \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch $(MAKE) image-builder; \
image=$(REGISTRY)/builder-$$arch:$(BUILDER_IMAGE_TAG); \
docker push $$image; \
images="$$images $$image"; \
if [ $(VERSION) != latest ]; then \
tag_image=$(REGISTRY)/builder-$$arch:$(VERSION); \
docker tag $$image $$tag_image; \
docker push $$tag_image; \
fi; \
done; \
docker manifest create $(REGISTRY)/builder:$(BUILDER_IMAGE_TAG) $$images; \
docker manifest push $(REGISTRY)/builder:$(BUILDER_IMAGE_TAG); \
if [ $(VERSION) != latest ]; then \
docker manifest create $(REGISTRY)/builder:$(VERSION) $$images; \
docker manifest push $(REGISTRY)/builder:$(VERSION); \
fi;
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-apiserver-image: clean-apiserver-manifest push-builder-image
set -e; \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch $(MAKE) image-apiserver; \
image=$(REGISTRY)/apiserver-$$arch:$(VERSION); \
docker push $$image; \
images="$$images $$image"; \
if [ $(VERSION) != latest ]; then \
latest_image=$(REGISTRY)/apiserver-$$arch:latest; \
docker tag $$image $$latest_image; \
docker push $$latest_image; \
fi; \
done; \
docker manifest create $(REGISTRY)/apiserver:$(VERSION) $$images; \
docker manifest push $(REGISTRY)/apiserver:$(VERSION); \
if [ $(VERSION) != latest ]; then \
docker manifest create $(REGISTRY)/apiserver:latest $$images; \
docker manifest push $(REGISTRY)/apiserver:latest; \
fi;
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-binding-apiserver-image: clean-binding-apiserver-manifest push-builder-image
set -e; \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch $(MAKE) image-binding-apiserver; \
image=$(REGISTRY)/binding-apiserver-$$arch:$(VERSION); \
docker push $$image; \
images="$$images $$image"; \
if [ $(VERSION) != latest ]; then \
latest_image=$(REGISTRY)/binding-apiserver-$$arch:latest; \
docker tag $$image $$latest_image; \
docker push $$latest_image; \
fi; \
done; \
docker manifest create $(REGISTRY)/binding-apiserver:$(VERSION) $$images; \
docker manifest push $(REGISTRY)/binding-apiserver:$(VERSION); \
if [ $(VERSION) != latest ]; then \
docker manifest create $(REGISTRY)/binding-apiserver:latest $$images; \
docker manifest push $(REGISTRY)/binding-apiserver:latest; \
fi;
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-clustersynchro-manager-image: clean-clustersynchro-manager-manifest push-builder-image
set -e; \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch $(MAKE) image-clustersynchro-manager; \
image=$(REGISTRY)/clustersynchro-manager-$$arch:$(VERSION); \
docker push $$image; \
images="$$images $$image"; \
if [ $(VERSION) != latest ]; then \
latest_image=$(REGISTRY)/clustersynchro-manager-$$arch:latest; \
docker tag $$image $$latest_image; \
docker push $$latest_image; \
fi; \
done; \
docker manifest create $(REGISTRY)/clustersynchro-manager:$(VERSION) $$images; \
docker manifest push $(REGISTRY)/clustersynchro-manager:$(VERSION); \
if [ $(VERSION) != latest ]; then \
docker manifest create $(REGISTRY)/clustersynchro-manager:latest $$images; \
docker manifest push $(REGISTRY)/clustersynchro-manager:latest; \
fi;
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-controller-manager-image: clean-controller-manager-manifest push-builder-image
set -e; \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch $(MAKE) image-controller-manager; \
image=$(REGISTRY)/controller-manager-$$arch:$(VERSION); \
docker push $$image; \
images="$$images $$image"; \
if [ $(VERSION) != latest ]; then \
latest_image=$(REGISTRY)/controller-manager-$$arch:latest; \
docker tag $$image $$latest_image; \
docker push $$latest_image; \
fi; \
done; \
docker manifest create $(REGISTRY)/controller-manager:$(VERSION) $$images; \
docker manifest push $(REGISTRY)/controller-manager:$(VERSION); \
if [ $(VERSION) != latest ]; then \
docker manifest create $(REGISTRY)/controller-manager:latest $$images; \
docker manifest push $(REGISTRY)/controller-manager:latest; \
fi;
clean-images: clean-apiserver-manifest clean-clustersynchro-manager-manifest
docker images|grep $(REGISTRY)/apiserver|awk '{print $$3}'|xargs docker rmi --force
docker images|grep $(REGISTRY)/clustersynchro-manager|awk '{print $$3}'|xargs docker rmi --force
clean-builder-manifest:
docker manifest rm $(REGISTRY)/builder:$(BUILDER_IMAGE_TAG) 2>/dev/null;\
docker manifest rm $(REGISTRY)/builder:$(VERSION) 2>/dev/null; exit 0
clean-apiserver-manifest:
docker manifest rm $(REGISTRY)/apiserver:$(VERSION) 2>/dev/null;\
docker manifest rm $(REGISTRY)/apiserver:latest 2>/dev/null; exit 0
clean-binding-apiserver-manifest:
docker manifest rm $(REGISTRY)/binding-apiserver:$(VERSION) 2>/dev/null;\
docker manifest rm $(REGISTRY)/binding-apiserver:latest 2>/dev/null; exit 0
clean-clustersynchro-manager-manifest:
docker manifest rm $(REGISTRY)/clustersynchro-manager:$(VERSION) 2>/dev/null;\
docker manifest rm $(REGISTRY)/clustersynchro-manager:latest 2>/dev/null; exit 0
clean-controller-manager-manifest:
docker manifest rm $(REGISTRY)/controller-manager:$(VERSION) 2>/dev/null;\
docker manifest rm $(REGISTRY)/controller-manager:latest 2>/dev/null; exit 0
.PHONY: golangci-lint
golangci-lint:
ifeq (, $(shell which golangci-lint))
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54
GOLANGLINT_BIN=$(shell go env GOPATH)/bin/golangci-lint
else
GOLANGLINT_BIN=$(shell which golangci-lint)
endif