-
Notifications
You must be signed in to change notification settings - Fork 155
/
Makefile
306 lines (224 loc) · 8.45 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
# Copyright 2019 The Kanister Authors.
#
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# include repository server's makefile
include Makefile.kubebuilder
# The binary to build (just the basename).
BIN := controller
# This repo's root import path (under GOPATH).
PKG := github.com/kanisterio/kanister
# Where to push the docker image.
REGISTRY ?= kanisterio
# Which architecture to build - see $(ALL_ARCH) for options.
ARCH ?= amd64
# This version-strategy uses git tags to set the version string
VERSION ?= $(shell git describe --tags --always --dirty)
#
# This version-strategy uses a manual value to set the version string
#VERSION := 1.2.3
PWD := $$(pwd)
# Whether to build inside a containerized build environment
DOCKER_BUILD ?= "true"
# Mention the vm-driver that should be used to install OpenShift
vm-driver ?= "kvm"
# Default OCP version in which the OpenShift apps are going to run
ocp_version ?= "4.13"
###
### These variables should not need tweaking.
###
SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
ALL_ARCH := amd64 arm arm64 ppc64le
# Set default base image dynamically for each arch
IMAGE_NAME := $(BIN)
IMAGE := $(REGISTRY)/$(IMAGE_NAME)
DOCS_RELEASE_BUCKET ?= s3://docs.kanister.io
GITHUB_TOKEN ?= ""
GOBORING ?= ""
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= "v0.12.0"
## Changelog file for goreleaser
CHANGELOG_FILE ?= ./CHANGELOG_CURRENT.md
# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all containers, see the 'all-container' rule.
# If you want to build AND push all containers, see the 'all-push' rule.
all: build
build-%:
@$(MAKE) --no-print-directory ARCH=$* build
container-%:
@$(MAKE) --no-print-directory ARCH=$* container
push-%:
@$(MAKE) --no-print-directory ARCH=$* push
all-build: $(addprefix build-, $(ALL_ARCH))
all-container: $(addprefix container-, $(ALL_ARCH))
all-push: $(addprefix push-, $(ALL_ARCH))
build: bin/$(ARCH)/$(BIN)
build-controller:
@$(MAKE) run CMD=" \
GOOS=linux GOARCH=$(ARCH) goreleaser build --id $(BIN) --rm-dist --debug --snapshot --single-target \
&& cp dist/$(BIN)_linux_$(ARCH)*/$(BIN) bin/$(ARCH)/$(BIN) \
"
bin/$(ARCH)/$(BIN):
@echo "building: $@"
@$(MAKE) run CMD=" \
GOARCH=$(ARCH) \
VERSION=$(VERSION) \
PKG=$(PKG) \
BIN=$(BIN) \
GOBORING=$(GOBORING) \
./build/build.sh \
"
# Example: make shell CMD="-c 'date > datefile'"
shell: build-dirs
@echo "launching a shell in the containerized build environment"
@PWD=$(PWD) ARCH=$(ARCH) PKG=$(PKG) GITHUB_TOKEN=$(GITHUB_TOKEN) CMD="/bin/bash $(CMD)" /bin/bash ./build/run_container.sh shell
DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION))
container: .container-$(DOTFILE_IMAGE) container-name
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in
@/bin/bash -c " \
BIN=$(BIN) \
ARCH=$(ARCH) \
IMAGE=$(IMAGE) \
VERSION=$(VERSION) \
SOURCE_BIN=bin/$(ARCH)/$(BIN) \
./build/package.sh \
"
container-name:
@echo "container: $(IMAGE):$(VERSION)"
release-controller: .push-$(DOTFILE_IMAGE) push-name
.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE)
ifeq ($(findstring gcr.io,$(REGISTRY)),gcr.io)
@gcloud docker -- push $(IMAGE):$(VERSION)
else
@docker push $(IMAGE):$(VERSION)
endif
@docker images -q $(IMAGE):$(VERSION) > $@
push-name:
@echo "pushed: $(IMAGE):$(VERSION)"
version:
@echo $(VERSION)
.PHONY: deploy format-vet go-test test codegen build-dirs run clean container-clean bin-clean docs start-kind tiller stop-kind release-snapshot go-mod-download
deploy: release-controller .deploy-$(DOTFILE_IMAGE)
.deploy-$(DOTFILE_IMAGE):
@sed \
-e 's|IMAGE|$(IMAGE)|g' \
-e 's|TAG|$(VERSION)|g' \
bundle.yaml.in > .deploy-$(DOTFILE_IMAGE)
@kubectl apply -f .deploy-$(DOTFILE_IMAGE)
format-vet: build-dirs
@$(MAKE) run CMD="./build/format-vet.sh $(SRC_DIRS)"
go-test: build-dirs
@$(MAKE) run CMD="TEST_FILTER=$(TEST_FILTER) ./build/test.sh $(SRC_DIRS)"
test: format-vet go-test
helm-test: build-dirs
@$(MAKE) run CMD="./build/helm-test.sh $(SRC_DIRS)"
integration-test: build-dirs
@$(MAKE) run CMD="./build/integration-test.sh short"
openshift-test:
@/bin/bash ./build/integration-test.sh openshift $(ocp_version)
golint:
@$(MAKE) run CMD="./build/golint.sh"
codegen:
@$(MAKE) run CMD="./build/codegen.sh"
DOCS_CMD = "cd docs && make clean && \
doc8 --max-line-length 90 --ignore D000 . && \
make spelling && make html"
docs:
ifeq ($(DOCKER_BUILD),"true")
@echo "running DOCS_CMD in the containerized build environment"
@PWD=$(PWD) ARCH=$(ARCH) CMD=$(DOCS_CMD) /bin/bash ./build/run_container.sh docs
else
@/bin/bash -c $(DOCS_CMD)
endif
API_DOCS_CMD = "gen-crd-api-reference-docs \
-config docs/api_docs/config.json \
-api-dir ./pkg/apis/cr/v1alpha1 \
-template-dir docs/api_docs/template \
-out-file API.md"
crd_docs:
ifeq ($(DOCKER_BUILD),"true")
@echo "running API_DOCS_CMD in the containerized build environment"
@PWD=$(PWD) ARCH=$(ARCH) CMD=$(API_DOCS_CMD) /bin/bash ./build/run_container.sh crd_docs
else
@/bin/bash -c $(API_DOCS_CMD)
endif
build-dirs:
@mkdir -p bin/$(ARCH)
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH)
run: build-dirs
ifeq ($(DOCKER_BUILD),"true")
@echo "running CMD in the containerized build environment"
@PWD=$(PWD) ARCH=$(ARCH) PKG=$(PKG) GITHUB_TOKEN=$(GITHUB_TOKEN) CMD="$(CMD)" /bin/bash ./build/run_container.sh run
else
@/bin/bash -c "$(CMD)"
endif
clean: dotfile-clean bin-clean
dotfile-clean:
rm -rf .container-* .dockerfile-* .push-* .deploy-*
bin-clean:
rm -rf .go bin
release-docs: docs
@if [ -z ${AWS_ACCESS_KEY_ID} ] || [ -z ${AWS_SECRET_ACCESS_KEY} ]; then\
echo "Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Exiting.";\
exit 1;\
fi;\
@if [ -f "docs/_build/html/index.html" ]; then\
aws s3 sync docs/_build/html $(DOCS_RELEASE_BUCKET) --delete;\
echo "Success";\
else\
echo "No built docs found";\
exit 1;\
fi;\
release-helm:
@/bin/bash ./build/release_helm.sh $(VERSION)
package-helm:
@$(MAKE) run CMD="PACKAGE_FOLDER=${PACKAGE_FOLDER} HELM_RELEASE_REPO_URL=${HELM_RELEASE_REPO_URL} HELM_RELEASE_REPO_INDEX=${HELM_RELEASE_REPO_INDEX} ./build/package_helm.sh $(VERSION)"
gorelease:
@$(MAKE) run CMD="CHANGELOG_FILE=$(CHANGELOG_FILE) GORELEASE_PARAMS=${GORELEASE_PARAMS} GHCR_LOGIN_TOKEN=${GHCR_LOGIN_TOKEN} GHCR_LOGIN_USER=${GHCR_LOGIN_USER} ./build/gorelease.sh"
release-snapshot:
@$(MAKE) run CMD="GORELEASER_CURRENT_TAG=v9.99.9-dev goreleaser --debug release --rm-dist --snapshot --timeout=60m0s"
go-mod-download:
@$(MAKE) run CMD="go mod download"
start-kind:
@$(MAKE) run CMD="./build/local_kubernetes.sh start_localkube"
tiller:
@/bin/bash ./build/init_tiller.sh
install-minio:
@$(MAKE) run CMD="./build/minio.sh install_minio"
install-csi-hostpath-driver:
@$(MAKE) run CMD="./build/local_kubernetes.sh install_csi_hostpath_driver"
uninstall-minio:
@$(MAKE) run CMD="./build/minio.sh uninstall_minio"
start-minishift:
@/bin/bash ./build/minishift.sh start_minishift $(vm-driver)
stop-minishift:
@/bin/bash ./build/minishift.sh stop_minishift
stop-kind:
@$(MAKE) run CMD="./build/local_kubernetes.sh stop_localkube"
check:
@./build/check.sh
go-mod-tidy:
@$(MAKE) run CMD="./build/gomodtidy.sh"
install-crds: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@$(MAKE) run CMD="kubectl apply -f pkg/customresource/"
uninstall-crds: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
@$(MAKE) run CMD="kubectl delete -f pkg/customresource/"
manifests: ## Generates CustomResourceDefinition objects.
@$(MAKE) run CMD="./build/generate_crds.sh ${CONTROLLER_TOOLS_VERSION}"
reno-new:
@PWD=$(PWD) ARCH=$(ARCH) PKG=$(PKG) GITHUB_TOKEN=$(GITHUB_TOKEN) CMD="EDITOR=vim reno new $(note) --edit" /bin/bash ./build/run_container.sh shell
reno-report:
@$(MAKE) run CMD="./build/reno_report.sh $(VERSION)"
reno-lint:
@$(MAKE) run CMD="reno lint"