This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
forked from kanisterio/kanister
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
259 lines (206 loc) · 7.3 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
# 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"
###
### 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
ifeq ($(ARCH),amd64)
BASEIMAGE?=alpine
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armel/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
endif
IMAGE_NAME := $(BIN)
IMAGE := $(REGISTRY)/$(IMAGE_NAME)
BUILD_IMAGE ?= kanisterio/build:v0.0.5
DOCS_BUILD_IMAGE ?= kanisterio/docker-sphinx
DOCS_RELEASE_BUCKET ?= s3://docs.kanister.io
GITHUB_TOKEN ?= ""
# 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)
bin/$(ARCH)/$(BIN):
@echo "building: $@"
@$(MAKE) run CMD='-c " \
GOARCH=$(ARCH) \
VERSION=$(VERSION) \
PKG=$(PKG) \
./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) \
BASEIMAGE=$(BASEIMAGE) \
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)"'
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/sh $(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 --debug release --rm-dist --snapshot"'
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
stop-kind:
@$(MAKE) run CMD='-c "./build/local_kubernetes.sh stop_localkube"'