forked from vmware-tanzu/community-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
383 lines (300 loc) · 13.6 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Copyright 2021 VMware Tanzu Community Edition contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# detect the build OS
ifeq ($(OS),Windows_NT)
build_OS := Windows
NUL = NUL
else
build_OS := $(shell uname -s 2>/dev/null || echo Unknown)
NUL = /dev/null
endif
REQUIRED_BINARIES := imgpkg kbld ytt
.DEFAULT_GOAL:=help
### GLOBAL ###
ROOT_DIR := $(shell git rev-parse --show-toplevel)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
# Add supported OS-ARCHITECTURE combinations here
ENVS := linux-amd64 windows-amd64 darwin-amd64 darwin-arm64
TOOLS_DIR := $(ROOT_DIR)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
# Add tooling binaries here and in hack/tools/Makefile
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
TOOLING_BINARIES := $(GOLANGCI_LINT)
help: #### display help
@awk 'BEGIN {FS = ":.*## "; printf "\nTargets:\n"} /^[a-zA-Z_-]+:.*?#### / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.* ## "; printf "\n \033[1;32mBuild targets\033[36m\033[0m\n \033[0;37mTargets for building and/or installing CLI plugins on the system.\n Append \"ENVS=<os-arch>\" to the end of these targets to limit the binaries built.\n e.g.: make build-all-tanzu-cli-plugins ENVS=linux-amd64 \n List available at https://github.com/golang/go/blob/master/src/go/build/syslist.go\033[36m\033[0m\n\n"} /^[a-zA-Z_-]+:.*? ## / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.* ### "; printf "\n \033[1;32mRelease targets\033[36m\033[0m\n\033[0;37m Targets for producing a TCE release package.\033[36m\033[0m\n\n"} /^[a-zA-Z_-]+:.*? ### / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
### GLOBAL ###
##### BUILD #####
ifndef BUILD_VERSION
BUILD_VERSION ?= $$(git describe --tags --abbrev=0)
endif
CONFIG_VERSION ?= $$(echo "$(BUILD_VERSION)" | cut -d "-" -f1)
ifeq ($(strip $(BUILD_VERSION)),)
BUILD_VERSION = dev
endif
FRAMEWORK_BUILD_VERSION=$$(cat "./hack/FRAMEWORK_BUILD_VERSION")
# TANZU_FRAMEWORK_REPO_BRANCH sets a branch or tag to build Tanzu Framework
TANZU_FRAMEWORK_REPO_BRANCH ?= v0.2.1
# if the hash below is set, this overrides the value of TANZU_FRAMEWORK_REPO_BRANCH
TANZU_FRAMEWORK_REPO_HASH ?=
ifndef TKG_DEFAULT_IMAGE_REPOSITORY
TKG_DEFAULT_IMAGE_REPOSITORY = "projects.registry.vmware.com/tkg"
endif
ARTIFACTS_DIR ?= ./artifacts
TCE_RELEASE_DIR ?= /tmp/tce-release
# this captures where the tanzu CLI will be installed (due to usage of go install)
# When GOBIN is set, this is where the tanzu binary is installed
# When GOBIN is not set, but GOPATH is, $GOPATH/bin is where the tanzu binary is installed
# When GOBIN is not set and GOPATH is not set, ${HOME}/go/bin is where the tanzu binary is installed
TANZU_CLI_INSTALL_PATH = "$${HOME}/go/bin/tanzu"
ifdef GOPATH
TANZU_CLI_INSTALL_PATH = "$${GOPATH}/bin/tanzu"
endif
ifdef GOBIN
TANZU_CLI_INSTALL_PATH = "$${GOBIN}/tanzu"
endif
#INSTALLED_CLI_DIR
ifeq ($(TCE_CI_BUILD), true)
XDG_DATA_HOME := /tmp/mylocal
SED := sed -i
endif
ifeq ($(XDG_DATA_HOME),)
ifeq ($(build_OS), Darwin)
XDG_DATA_HOME := "${HOME}/Library/Application Support"
SED := sed -i '' -e
endif
endif
ifeq ($(XDG_DATA_HOME),)
ifeq ($(build_OS), Linux)
XDG_DATA_HOME := ${HOME}/.local/share
SED := sed -i
endif
endif
export XDG_DATA_HOME
export GO
export GOLANGCI_LINT
export ARTIFACTS_DIR
PRIVATE_REPOS="github.com/vmware-tanzu/*"
GO := GOPRIVATE=${PRIVATE_REPOS} go
##### BUILD #####
##### IMAGE #####
OCI_REGISTRY := projects.registry.vmware.com/tce
##### IMAGE #####
##### LINTING TARGETS #####
.PHONY: lint mdlint shellcheck check yamllint misspell actionlint urllint imagelint
check: ensure-deps lint mdlint shellcheck yamllint misspell actionlint urllint imagelint
.PHONY: ensure-deps
ensure-deps:
hack/ensure-dependencies.sh
GO_MODULES=$(shell find . -path "*/go.mod" | xargs -I _ dirname _)
get-deps:
@for i in $(GO_MODULES); do \
echo "-- Getting deps for $$i --"; \
working_dir=`pwd`; \
cd $${i}; \
$(MAKE) get-deps || exit 1; \
cd $$working_dir; \
done
lint: tools get-deps
@for i in $(GO_MODULES); do \
echo "-- Linting $$i --"; \
working_dir=`pwd`; \
cd $${i}; \
$(MAKE) lint || exit 1; \
cd $$working_dir; \
done
mdlint:
# mdlint rules with common errors and possible fixes can be found here:
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
hack/check-mdlint.sh
shellcheck:
hack/check-shell.sh
yamllint:
hack/check-yaml.sh
misspell:
hack/check-misspell.sh
actionlint:
go install github.com/rhysd/actionlint/cmd/actionlint@latest
actionlint -shellcheck=
urllint:
go install github.com/JitenPalaparthi/[email protected]
urllinter --path=./ --config=hack/.urllintconfig.yaml --summary=true --details=Fail
imagelint:
cd ./hack/imagelinter && go build -o imagelinter main.go
hack/imagelinter/imagelinter --path=./ --config=hack/.imagelintconfig.yaml --summary=true --details=all
##### LINTING TARGETS #####
##### Tooling Binaries
tools: $(TOOLING_BINARIES)
.PHONY: $(TOOLING_BINARIES)
$(TOOLING_BINARIES):
make -C $(TOOLS_DIR) $(@F)
##### Tooling Binaries
##### BUILD TARGETS #####
build-tce-cli-plugins: version clean-plugin build-cli-plugins ## builds the CLI plugins that live in the TCE repo into the artifacts directory
@printf "\n[COMPLETE] built TCE-specific plugins at $(ARTIFACTS_DIR)\n"
@printf "To install these plugins, run \`make install-tce-cli-plugins\`\n"
install-tce-cli-plugins: version clean-plugin build-cli-plugins framework-set-unstable-versions install-plugins ## builds and installs CLI plugins found in artifacts directory @printf "\n[COMPLETE] built and installed TCE-specific plugins at $${XDG_DATA_HOME}/tanzu-cli/. "
@printf "These plugins will be automatically detected by your tanzu CLI.\n"
build-all-tanzu-cli-plugins: version clean build-cli build-cli-plugins ## builds the Tanzu CLI and all CLI plugins that are used in TCE
@printf "\n[COMPLETE] built plugins at $(ARTIFACTS_DIR)\n"
@printf "These plugins will be automatically detected by tanzu CLI.\n"
@printf "\n[COMPLETE] built tanzu CLI at $(TCE_RELEASE_DIR). "
@printf "Move this binary to a location in your path!\n"
install-all-tanzu-cli-plugins: version clean build-cli install-cli build-cli-plugins install-plugins ## installs the Tanzu CLI and all CLI plugins that are used in TCE
@printf "\n[COMPLETE] built and installed TCE-specific plugins at $${XDG_DATA_HOME}/tanzu-cli/."
@printf "These plugins will be automatically detected by your tanzu CLI.\n"
@printf "\n[COMPLETE] built and installed tanzu CLI at $(TANZU_CLI_INSTALL_PATH). "
@printf "Move this binary to a location in your path!\n"
release: build-all-tanzu-cli-plugins package-release ### builds and produces the release packaging/tarball for TCE in your local Go environment
release-docker: ### builds and produces the release packaging/tarball for TCE in a containerized environment
docker run --rm \
-e HOME=/go \
-e TCE_CI_BUILD=true \
-w /go/src/community-edition \
-v ${PWD}:/go/src/community-edition \
-v /tmp:/tmp \
golang:1.16.2 \
sh -c "cd /go/src/community-edition &&\
./hack/fix-for-ci-build.sh &&\
make release"
clean: clean-release clean-plugin clean-framework
# RELEASE MANAGEMENT
version:
@echo "BUILD_VERSION:" ${BUILD_VERSION}
@echo "CONFIG_VERSION:" ${CONFIG_VERSION}
@echo "FRAMEWORK_BUILD_VERSION:" ${FRAMEWORK_BUILD_VERSION}
@echo "XDG_DATA_HOME:" $(XDG_DATA_HOME)
.PHONY: package-release
package-release:
TCE_RELEASE_DIR=${TCE_RELEASE_DIR} FRAMEWORK_BUILD_VERSION=${FRAMEWORK_BUILD_VERSION} BUILD_VERSION=${BUILD_VERSION} hack/release/package-release.sh
# IMPORTANT: This should only ever be called CI/github-action
.PHONY: cut-release
cut-release: version
TCE_RELEASE_DIR=${TCE_RELEASE_DIR} FRAMEWORK_BUILD_VERSION=${FRAMEWORK_BUILD_VERSION} \
BUILD_VERSION=$(BUILD_VERSION) FAKE_RELEASE=$(shell expr $(BUILD_VERSION) | grep fake) \
hack/release/cut-release.sh
echo "$(BUILD_VERSION)" | tee -a ./cayman_trigger.txt
.PHONY: upload-signed-assets
upload-signed-assets:
cd ./hack/asset && $(MAKE) run && cd ../..
# IMPORTANT: This should only ever be called CI/github-action
clean-release:
rm -rf ./build
rm -f ./hack/NEW_BUILD_VERSION
# RELEASE MANAGEMENT
# TANZU CLI
.PHONY: build-cli
build-cli:
TCE_RELEASE_DIR=${TCE_RELEASE_DIR} \
TKG_DEFAULT_IMAGE_REPOSITORY=${TKG_DEFAULT_IMAGE_REPOSITORY} TANZU_FRAMEWORK_REPO_BRANCH=$(TANZU_FRAMEWORK_REPO_BRANCH) \
TANZU_FRAMEWORK_REPO_HASH=$(TANZU_FRAMEWORK_REPO_HASH) BUILD_EDITION=tce TCE_BUILD_VERSION=$(BUILD_VERSION) \
FRAMEWORK_BUILD_VERSION=${FRAMEWORK_BUILD_VERSION} ENVS="${ENVS}" hack/build-tanzu.sh
.PHONY: install-cli
install-cli:
TCE_RELEASE_DIR=${TCE_RELEASE_DIR} \
FRAMEWORK_BUILD_VERSION=${FRAMEWORK_BUILD_VERSION} ENVS="${ENVS}" hack/install-tanzu.sh
.PHONY: clean-framework
clean-framework:
rm -rf ${TCE_RELEASE_DIR}
rm -rf ${XDG_DATA_HOME}/tanzu-cli
mkdir -p ${XDG_DATA_HOME}/tanzu-cli
framework-set-unstable-versions:
@cd ./hack/builder/ && $(MAKE) framework-set-unstable-versions
# TANZU CLI
# PLUGINS
# Dynamically generate OS-ARCH targets to allow for parallel execution
PLUGIN_JOBS := $(addprefix build-cli-plugins-,${ENVS})
.PHONY: prep-build-cli
prep-build-cli:
@cd ./cli/cmd/plugin/ && for plugin in */; do\
printf "===> Preparing $${plugin}\n";\
working_dir=`pwd`;\
cd $${plugin};\
$(MAKE) get-deps;\
cd $${working_dir};\
done
.PHONY: build-cli-plugins
build-cli-plugins: prep-build-cli ${PLUGIN_JOBS}
# Entries for PLUGIN_JOBS are generated from this template
.PHONY: build-cli-plugins-%
build-cli-plugins-%: prep-build-cli
$(eval ARCH = $(word 2,$(subst -, ,$*)))
$(eval OS = $(word 1,$(subst -, ,$*)))
@printf "===> Building with ${OS}-${ARCH}\n";
@cd ./hack/builder/ && $(MAKE) compile OS=${OS} ARCH=${ARCH} TANZU_CORE_BUCKET="tce-tanzu-cli-framework" TKG_DEFAULT_IMAGE_REPOSITORY=${TKG_DEFAULT_IMAGE_REPOSITORY}
.PHONY: build-cli-plugins-local
build-cli-plugins-local: build-cli-plugins-${GOHOSTOS}-${GOHOSTARCH}
.PHONY: install-plugins
install-plugins:
@cd ./hack/builder/ && $(MAKE) install-plugins
.PHONY: build-install-plugins-local
build-install-plugins-local: build-cli-plugins-local install-plugins
@printf "CLI plugins built and installed\n"
test-plugins: ## run tests on TCE plugins
# TODO(joshrosso): update once we get our testing strategy in place
@echo "No tests to run."
.PHONY: clean-plugin
clean-plugin:
rm -rf ${ARTIFACTS_DIR}
# PLUGINS
##### BUILD TARGETS #####
##### PACKAGE OPERATIONS #####
check-carvel:
$(foreach exec,$(REQUIRED_BINARIES),\
$(if $(shell which $(exec)),,$(error "'$(exec)' not found. Carvel toolset is required. See instructions at https://carvel.dev/#install")))
.PHONY: create-package
create-package: # Stub out new package directories and manifests. Usage: make create-package NAME=foobar VERSION=10.0.0
@hack/packages/create-package.sh $(NAME) $(VERSION)
vendir-sync-package: check-carvel # Performs a `vendir sync` for a package. Usage: make vendir-package-sync PACKAGE=foobar VERSION=1.0.0
@printf "\n===> syncing $${PACKAGE}/$${VERSION}\n";\
cd addons/packages/$${PACKAGE}/$${VERSION}/bundle && vendir sync >> /dev/null;\
lock-package-images: check-carvel # Updates the image lock file for a package. Usage: make lock-package-images PACKAGE=foobar VERSION=1.0.0
@printf "\n===> Updating image lockfile for package $${PACKAGE}/$${VERSION}\n";\
cd addons/packages/$${PACKAGE}/$${VERSION} && kbld --file bundle --imgpkg-lock-output bundle/.imgpkg/images.yml >> /dev/null;\
push-package: check-carvel # Build and push a package template. Tag will default to `latest`. Usage: make push-package PACKAGE=foobar VERSION=1.0.0
@printf "\n===> pushing $${PACKAGE}/$${VERSION}\n";\
cd addons/packages/$${PACKAGE}/$${VERSION} && imgpkg push --bundle $(OCI_REGISTRY)/$${PACKAGE}:$${VERSION} --file bundle/;\
export CHANNEL
generate-package-repo: check-carvel # Generate and push the package repository. Usage: make generate-package-repo CHANNEL=main
cd ./hack/packages/ && $(MAKE) run
get-package-config: # Extracts the package values.yaml file. Usage: make get-package-config PACKAGE=foo VERSION=1.0.0
TEMP_DIR=`mktemp -d` \
&& imgpkg pull --bundle ${OCI_REGISTRY}/$${PACKAGE}:$${VERSION} -o $${TEMP_DIR} \
&& cp $${TEMP_DIR}/config/values.yaml ./$${PACKAGE}-$${VERSION}-values.yaml \
&& rm -rf $${TEMP_DIR}
test-packages-unit: check-carvel
$(GO) test -coverprofile cover.out -v `go list ./... | grep github.com/vmware-tanzu/community-edition/addons/packages | grep -v e2e`
create-repo: # Usage: make create-repo NAME=my-repo
cp hack/packages/templates/repo.yaml addons/repos/${NAME}.yaml
##### PACKAGE OPERATIONS #####
##### NESTED MAKEFILE SUPPORT #####
makefile:
@cat "./hack/makefile-template";
##### NESTED MAKEFILE SUPPORT #####
##### E2E TESTS #####
##### BUILD TARGETS #####
# TCE AWS management Cluster E2E Test
aws-management-cluster-e2e-test:
test/aws/deploy-tce-managed.sh
# TCE AWS Standalone Cluster E2E Test
aws-standalone-cluster-e2e-test:
test/aws/deploy-tce-standalone.sh
# Azure Standalone Cluster E2E Test
azure-standalone-cluster-e2e-test:
test/azure/deploy-standalone-cluster.sh
azure-management-and-workload-cluster-e2e-test:
test/azure/deploy-management-and-workload-cluster.sh
# TCE Docker Standalone Cluster E2E Test
tce-docker-standalone-cluster-e2e-test:
test/docker/run-tce-docker-standalone-cluster.sh
# TCE Docker Managed Cluster E2E Test
tce-docker-managed-cluster-e2e-test:
test/docker/run-tce-docker-managed-cluster.sh
# TCE vSphere Standalone Cluster E2E Test
tce-vsphere-standalone-cluster-e2e-test:
test/vsphere/run-tce-vsphere-standalone-cluster.sh
##### E2E TESTS #####