forked from clusterpedia-io/clusterpedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
230 lines (197 loc) · 8.34 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
BASEIMAGE ?= "alpine:3.14"
REGISTRY ?= "ghcr.io/clusterpedia-io/clusterpedia"
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
RELEASE_ARCHS ?= amd64 arm64
# Git information, used to set clusterpedia version
GIT_VERSION ?= $(shell git describe --tags --dirty)
GIT_COMMIT_HASH ?= $(shell git rev-parse HEAD)
GIT_TREESTATE = "clean"
GIT_DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(GIT_DIFF), 1)
GIT_TREESTATE = "dirty"
endif
BUILD_DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
KUBE_DEPENDENCE_VERSION = $(shell go list -m k8s.io/kubernetes | cut -d' ' -f2)
LDFLAGS += -X github.com/clusterpedia-io/clusterpedia/pkg/version.gitVersion=$(GIT_VERSION)
LDFLAGS += -X github.com/clusterpedia-io/clusterpedia/pkg/version.gitCommit=$(GIT_COMMIT_HASH)
LDFLAGS += -X github.com/clusterpedia-io/clusterpedia/pkg/version.gitTreeState=$(GIT_TREESTATE)
LDFLAGS += -X github.com/clusterpedia-io/clusterpedia/pkg/version.buildDate=$(BUILD_DATE)
# The `client-go/pkg/version` effects the **User-Agent** when using client-go to request.
# User-Agent="<bin name>/$(GIT_VERSION) ($(GOOS)/$(GOARCH)) kubernetes/$(GIT_COMMIT_HASH)[/<component name>]"
# eg. "clustersynchro-manager/0.4.0 (linux/amd64) kubernetes/fbf0f4f/clustersynchro-manager"
LDFLAGS += -X k8s.io/client-go/pkg/version.gitVersion=$(GIT_VERSION)
LDFLAGS += -X k8s.io/client-go/pkg/version.gitMajor=$(shell echo '$(subst v,,$(GIT_VERSION))' | cut -d. -f1)
LDFLAGS += -X k8s.io/client-go/pkg/version.gitMinor=$(shell echo '$(subst v,,$(GIT_VERSION))' | cut -d. -f2)
LDFLAGS += -X k8s.io/client-go/pkg/version.gitCommit=$(GIT_COMMIT_HASH)
LDFLAGS += -X k8s.io/client-go/pkg/version.gitTreeState=$(GIT_TREESTATE)
LDFLAGS += -X k8s.io/client-go/pkg/version.buildDate=$(BUILD_DATE)
# The `component-base/version` effects the version obtained using Kubernetes OpenAPI.
# OpenAPI Path: /apis/clusterpedia.io/v1beta1/resources/version
# $ kubectl version
LDFLAGS += -X k8s.io/component-base/version.gitVersion=$(KUBE_DEPENDENCE_VERSION)
LDFLAGS += -X k8s.io/component-base/version.gitMajor=$(shell echo '$(subst v,,$(KUBE_DEPENDENCE_VERSION))' | cut -d. -f1)
LDFLAGS += -X k8s.io/component-base/version.gitMinor=$(shell echo '$(subst v,,$(KUBE_DEPENDENCE_VERSION))' | cut -d. -f2)
LDFLAGS += -X k8s.io/component-base/version.gitCommit=$(GIT_COMMIT_HASH)
LDFLAGS += -X k8s.io/component-base/version.gitTreeState=$(GIT_TREESTATE)
LDFLAGS += -X k8s.io/component-base/version.buildDate=$(BUILD_DATE)
VERSION ?= "latest"
LATEST_TAG=$(shell git describe --tags)
ifeq ($(LATEST_TAG),$(shell git describe --abbrev=0 --tags))
VERSION=$(LATEST_TAG)
endif
all: 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:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "$(LDFLAGS)" \
-o bin/apiserver \
cmd/apiserver/main.go
.PHONY: clustersynchro-manager
clustersynchro-manager:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "$(LDFLAGS)" \
-o bin/clustersynchro-manager \
cmd/clustersynchro-manager/main.go
.PHONY: controller-manager
controller-manager:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "$(LDFLAGS)" \
-o bin/controller-manager \
cmd/controller-manager/main.go
.PHONY: images
images: image-apiserver image-clustersynchro-manager image-controller-manager
image-apiserver:
GOOS="linux" $(MAKE) apiserver
docker buildx build \
-t ${REGISTRY}/apiserver-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BASEIMAGE=$(BASEIMAGE) \
--build-arg BINNAME=apiserver .
image-clustersynchro-manager:
GOOS="linux" $(MAKE) clustersynchro-manager
docker buildx build \
-t $(REGISTRY)/clustersynchro-manager-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BASEIMAGE=$(BASEIMAGE) \
--build-arg BINNAME=clustersynchro-manager .
image-controller-manager:
GOOS="linux" $(MAKE) controller-manager
docker buildx build \
-t $(REGISTRY)/controller-manager-$(GOARCH):$(VERSION) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BASEIMAGE=$(BASEIMAGE) \
--build-arg BINNAME=controller-manager .
.PHONY: push-images
push-images: push-apiserver-image push-clustersynchro-manager-image push-controller-manager-image
# clean manifest https://github.com/docker/cli/issues/954#issuecomment-586722447
push-apiserver-image: clean-apiserver-manifest
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-clustersynchro-manager-image: clean-clustersynchro-manager-manifest
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
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-apiserver-manifest:
docker manifest rm $(REGISTRY)/apiserver:$(VERSION) 2>/dev/null;\
docker manifest rm $(REGISTRY)/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/[email protected]
GOLANGLINT_BIN=$(shell go env GOPATH)/bin/golangci-lint
else
GOLANGLINT_BIN=$(shell which golangci-lint)
endif