-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
179 lines (140 loc) · 5.05 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
VERSION ?= 1.0-dev
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
SOURCES := $(shell find . -type f -name '*.go')
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')
OUT_BASE_PATH= out
OUT_PATH = $(OUT_BASE_PATH)/$(GOOS)-$(GOARCH)
LDFLAGS := "-X kurator.dev/kurator/pkg/version.gitVersion=$(VERSION) \
-X kurator.dev/kurator/pkg/version.gitCommit=$(GIT_COMMIT_HASH) \
-X kurator.dev/kurator/pkg/version.gitTreeState=$(GIT_TREESTATE) \
-X kurator.dev/kurator/pkg/version.buildDate=$(BUILD_DATE)"
GO_BUILD=CGO_ENABLED=0 GOOS=$(GOOS) go build -ldflags $(LDFLAGS)
DOCKER_BUILD=docker build --build-arg BASE_VERSION=nonroot --build-arg BASE_IMAGE=gcr.io/distroless/static
FINDFILES=find . \( -path ./common-protos -o -path ./.git -o -path ./out -o -path ./.github -o -path ./hack -o -path ./licenses -o -path ./vendor \) -prune -o -type f
XARGS = xargs -0 -r
IMAGE_HUB ?= ghcr.io/kurator-dev
IMAGE_TAG ?= $(VERSION)
HELM_CHART_VERSION ?= $(VERSION)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
export PATH := $(GOBIN):$(PATH)
.PHONY: build
build: tidy kurator cluster-operator fleet-manager
.PHONY: tidy
tidy:
go mod tidy
.PHONY: kurator
kurator:
$(GO_BUILD) -o $(OUT_PATH)/kurator cmd/kurator/main.go
.PHONY: cluster-operator
cluster-operator:
$(GO_BUILD) -o $(OUT_PATH)/cluster-operator cmd/cluster-operator/main.go
.PHONY: fleet-manager
fleet-manager:
$(GO_BUILD) -o $(OUT_PATH)/fleet-manager cmd/fleet-manager/main.go
.PHONY: docker
docker: docker.cluster-operator docker.fleet-manager
.PHONY: docker.cluster-operator
docker.cluster-operator: cluster-operator
cp ./cmd/cluster-operator/Dockerfile $(OUT_PATH)/
cd $(OUT_PATH)/ && $(DOCKER_BUILD) -t ${IMAGE_HUB}/cluster-operator:${IMAGE_TAG} .
.PHONY: docker.fleet-manager
docker.fleet-manager: fleet-manager
cp ./cmd/fleet-manager/Dockerfile $(OUT_PATH)/
cd $(OUT_PATH)/ && $(DOCKER_BUILD) -t ${IMAGE_HUB}/fleet-manager:${IMAGE_TAG} .
.PHONY: docker-push
docker-push: docker
docker push ${IMAGE_HUB}/cluster-operator:${IMAGE_TAG}
docker push ${IMAGE_HUB}/fleet-manager:${IMAGE_TAG}
.PHONY: lint
lint: golangci-lint lint-copyright lint-markdown lint-shellcheck
.PHONY: lint-markdown
lint-markdown:
markdownlint docs --ignore docs/content/en/references --ignore docs/node_modules -c common/config/mdl.json
markdownlint ./README.md -c common/config/mdl.json
lint-copyright:
@${FINDFILES} \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' -o -name '*.py' -o -name '*.sh' \) \( ! \( -name '*.gen.go' -o -name '*.pb.go' -o -name '*_pb2.py' \) \) -print0 |\
${XARGS} hack/lint_copyright_banner.sh
# GitHub has shellcheck pre-installed
lint-shellcheck:
@echo Running Shellcheck linter ...
@shellcheck hack/*.sh
fix-copyright:
@${FINDFILES} \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' -o -name '*.py' -o -name '*.sh' \) \( ! \( -name '*.gen.go' -o -name '*.pb.go' -o -name '*_pb2.py' \) \) -print0 |\
${XARGS} hack/fix_copyright_banner.sh
golangci-lint:
hack/golangci-lint.sh
init-gen:
hack/init-gen-tools.sh
.PHONY: gen-prom
gen-prom: init-gen
hack/gen-prom.sh manifests/jsonnet/prometheus/prometheus.jsonnet manifests/profiles/prom/
.PHONY: gen-prom-thanos
gen-prom-thanos: init-gen
hack/gen-prom.sh manifests/jsonnet/prometheus/thanos.jsonnet manifests/profiles/prom-thanos/
.PHONY: gen-thanos
gen-thanos: init-gen
hack/gen-thanos.sh
.PHONY: sync-crds
sync-crds: gen-crd
hack/sync-crds.sh
.PHONY: gen-chart
gen-chart: sync-crds
HELM_CHART_VERSION=$(HELM_CHART_VERSION) IMAGE_TAG=$(IMAGE_TAG) hack/gen-chart.sh
.PHONY: test
test: clean tidy
go test -race -v -vet=off -coverprofile=coverage.out ./pkg/...
.PHONY: clean
clean:
go clean -testcache
go clean -cache
rm -rf $(OUT_BASE_PATH)
.PHONY: gen
gen: clean \
gen-code \
gen-api-doc \
tidy \
fix-copyright \
gen-thanos \
gen-prom \
gen-prom-thanos \
gen-thanos \
gen-chart
.PHONY: gen-check
gen-check: gen
hack/gen-check.sh
.PHONY: doc.serve
doc.serve:
KURATOR_VERSION=$(VERSION) hack/local-docsite-up.sh
.PHONY: doc.build
doc.build:
KURATOR_VERSION=$(VERSION) hack/local-docsite-build.sh
PHONY: init-codegen
init-codegen:
hack/init-codegen.sh
.PHONY: gen-api
gen-api: gen-code gen-crd gen-api-doc
.PHONY: gen-crd
gen-crd: init-codegen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
hack/update-crdgen.sh
.PHONY: gen-code
gen-code: init-codegen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
hack/update-codegen.sh
.PHONY: gen-api-doc
gen-api-doc: ## Generate API documentation
hack/gen-api-doc.sh
.PHONY: release-artifacts
release-artifacts: ## Release artifacts
release-artifacts: build docker gen-chart
VERSION=$(VERSION) OUT_BASE_PATH=$(OUT_BASE_PATH) hack/release-artifacts.sh