forked from kanisterio/kanister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
302 lines (233 loc) · 8.58 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
# 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.
# 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"
DOCKER_CONFIG ?= "$(HOME)/.docker"
# Mention the vm-driver that should be used to install OpenShift
vm-driver ?= "kvm"
# Refers to https://github.com/kopia/kopia/commit/317cc36892707ab9bdc5f6e4dea567d1e638a070
KOPIA_COMMIT_ID ?= "317cc36"
KOPIA_REPO ?= "kopia"
# Default OCP version in which the OpenShift apps are going to run
ocp_version ?= "4.10"
###
### 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)
BUILD_IMAGE ?= ghcr.io/kanisterio/build:v0.0.22
# tag 0.1.0 is, 0.0.1 (latest) + gh + aws + helm binary
DOCS_BUILD_IMAGE ?= ghcr.io/kanisterio/docker-sphinx:0.2.0
DOCS_RELEASE_BUCKET ?= s3://docs.kanister.io
GITHUB_TOKEN ?= ""
GOBORING ?= ""
# 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='-c " \
goreleaser build --id $(BIN) --rm-dist --debug --snapshot \
&& cp dist/$(BIN)_linux_$(ARCH)/$(BIN) bin/$(ARCH)/$(BIN) \
"'
bin/$(ARCH)/$(BIN):
@echo "building: $@"
@$(MAKE) run CMD='-c " \
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"
@docker run \
-ti \
--rm \
--privileged \
--net host \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD)/.go/cache:/go/.cache" \
-v "${HOME}/.kube:/root/.kube" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH):/go/bin" \
-v "$(DOCKER_CONFIG):/root/.docker" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh
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 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)
test: build-dirs
@$(MAKE) run CMD='-c "./build/test.sh $(SRC_DIRS)"'
helm-test: build-dirs
@$(MAKE) run CMD='-c "./build/helm-test.sh $(SRC_DIRS)"'
integration-test: build-dirs
@$(MAKE) run CMD='-c "./build/integration-test.sh short"'
openshift-test:
@/bin/bash ./build/integration-test.sh openshift $(ocp_version)
golint:
@$(MAKE) run CMD='-c "./build/golint.sh"'
codegen:
@$(MAKE) run CMD='-c "./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"
@docker run \
--entrypoint '' \
--rm \
-v "$(PWD):/repo" \
-w /repo \
$(DOCS_BUILD_IMAGE) \
/bin/bash -c $(DOCS_CMD)
else
@/bin/bash -c $(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"
@docker run \
--rm \
--net host \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v "${HOME}/.kube:/root/.kube" \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD)/.go/cache:/go/.cache" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH):/go/bin" \
-v "$(PWD)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)" \
-v "$(DOCKER_CONFIG):/root/.docker" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/bash $(CMD)
else
@/bin/bash $(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)
gorelease:
@$(MAKE) run CMD='-c "./build/gorelease.sh"'
release-snapshot:
@$(MAKE) run CMD='-c "GORELEASER_CURRENT_TAG=v9.99.9-dev goreleaser --debug release --rm-dist --snapshot"'
update-kopia-image:
@/bin/bash ./build/update_kopia_image.sh -c $(KOPIA_COMMIT_ID) -r $(KOPIA_REPO) -b $(GOBORING)
go-mod-download:
@$(MAKE) run CMD='-c "go mod download"'
start-kind:
@$(MAKE) run CMD='-c "./build/local_kubernetes.sh start_localkube"'
tiller:
@/bin/bash ./build/init_tiller.sh
install-minio:
@$(MAKE) run CMD='-c "./build/minio.sh install_minio"'
install-csi-hostpath-driver:
@$(MAKE) run CMD='-c "./build/local_kubernetes.sh install_csi_hostpath_driver"'
uninstall-minio:
@$(MAKE) run CMD='-c "./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='-c "./build/local_kubernetes.sh stop_localkube"'
check:
@./build/check.sh
gomod:
@$(MAKE) run CMD='-c "./build/gomod.sh"'