forked from vmware-tanzu/tanzu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
142 lines (112 loc) · 5.73 KB
/
common.mk
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
# Copyright 2021 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
ROOT_DIR := $(shell git rev-parse --show-toplevel)
RELATIVE_ROOT ?= .
CONTROLLER_GEN_SRC ?= "./..."
# Framework has lots of components, and many build steps that are disparate.
# Use docker buildkit so that we get faster image builds and skip redundant work.
# TODO: We need to measure what this speeds up, and what it doesn't (and why).
export DOCKER_BUILDKIT := 1
# 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
GO := go
NUL = /dev/null
ifeq ($(GOHOSTOS),windows)
NUL = NUL
endif
BUILD_SHA ?= $$(git describe --match=$(git rev-parse --short HEAD) --always --dirty)
BUILD_DATE ?= $$(date -u +"%Y-%m-%d")
BUILD_VERSION ?= $(shell git describe --tags --abbrev=0 2>$(NUL))
ifeq ($(strip $(BUILD_VERSION)),)
BUILD_VERSION = dev
endif
# BUILD_EDITION is the Tanzu Edition, the plugin should be built for.
# Valid values for BUILD_EDITION are 'tce' and 'tkg'. Default value of BUILD_EDITION is 'tkg'.
ifneq ($(BUILD_EDITION), tce)
BUILD_EDITION = tkg
endif
ifdef DEBUG
LD_FLAGS = -s
GC_FLAGS = all=-N -l
else
LD_FLAGS = -s -w
GC_FLAGS =
endif
# Remove old package path for buildinfo vars when it's no longer in use by plugin binaries.
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.Date=$(BUILD_DATE)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.SHA=$(BUILD_SHA)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.Version=$(BUILD_VERSION)'
# Set buildinfo for plugins
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Date=$(BUILD_DATE)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.SHA=$(BUILD_SHA)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Version=$(BUILD_VERSION)'
# Set buildinfo for tkr, object-propagation and (potentially) other modules
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/util/buildinfo.Date=$(BUILD_DATE)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/util/buildinfo.SHA=$(BUILD_SHA)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/util/buildinfo.Version=$(BUILD_VERSION)'
# Add supported OS-ARCHITECTURE combinations here
ENVS ?= linux-amd64 windows-amd64 darwin-amd64
STANDALONE_PLUGINS ?= login management-cluster:k8s package:k8s pinniped-auth secret:k8s telemetry:k8s isolated-cluster
CONTEXTAWARE_PLUGINS ?= cluster:k8s kubernetes-release:k8s feature:k8s
ADMIN_PLUGINS ?= builder codegen test
PLUGINS ?= $(STANDALONE_PLUGINS) $(CONTEXTAWARE_PLUGINS)
STANDALONE_PLUGINS_WITHOUT_TARGET ?= $(shell echo $(STANDALONE_PLUGINS) | sed 's/:k8s//g' | sed 's/:tmc//g')
CONTEXTAWARE_PLUGINS_WITHOUT_TARGET ?= $(shell echo $(CONTEXTAWARE_PLUGINS) | sed 's/:k8s//g' | sed 's/:tmc//g')
PLUGINS_WITHOUT_TARGET ?= $(STANDALONE_PLUGINS_WITHOUT_TARGET) $(CONTEXTAWARE_PLUGINS_WITHOUT_TARGET)
# Hosts running SELinux need :z added to volume mounts
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
ifeq ($(SELINUX_ENABLED),1)
DOCKER_VOL_OPTS?=:z
endif
# Support DISTROLESS_BASE_IMAGE,GOPROXY,GOPROXY change while building image
GOPROXY ?= "https://proxy.golang.org,direct"
GOPROXY ?= "sum.golang.org"
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot
# Directories
TOOLS_DIR := $(abspath $(ROOT_DIR)/hack/tools)
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
# Add tooling binaries here and in hack/tools/Makefile
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
GOBINDATA := $(TOOLS_BIN_DIR)/gobindata
KUBEBUILDER := $(TOOLS_BIN_DIR)/kubebuilder
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
YTT := $(TOOLS_BIN_DIR)/ytt
KBLD := $(TOOLS_BIN_DIR)/kbld
VENDIR := $(TOOLS_BIN_DIR)/vendir
IMGPKG := $(TOOLS_BIN_DIR)/imgpkg
KAPP := $(TOOLS_BIN_DIR)/kapp
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
VALE := $(TOOLS_BIN_DIR)/vale
YQ := $(TOOLS_BIN_DIR)/yq
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
COUNTERFEITER := $(TOOLS_BIN_DIR)/counterfeiter
TOOLING_BINARIES := $(CONTROLLER_GEN) $(GOLANGCI_LINT) $(YTT) $(KBLD) $(VENDIR) $(IMGPKG) $(KAPP) $(KUSTOMIZE) $(GOIMPORTS) $(GOBINDATA) $(GINKGO) $(VALE) $(YQ) $(CONVERSION_GEN) $(COUNTERFEITER)
## --------------------------------------
##@ API/controller building and generation
## --------------------------------------
help: ## Display this help (default)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-28s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m\033[32m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
## --------------------------------------
##@ Tooling Binaries
## --------------------------------------
tools: $(TOOLING_BINARIES) ## Build tooling binaries
.PHONY: $(TOOLING_BINARIES)
$(TOOLING_BINARIES):
make -C $(TOOLS_DIR) $(@F)
generate-controller-code: $(CONTROLLER_GEN) $(GOIMPORTS) ## Generate code via controller-gen
$(CONTROLLER_GEN) $(GENERATOR) object:headerFile="$(ROOT_DIR)/hack/boilerplate.go.txt",year=$(shell date +%Y) paths="$(CONTROLLER_GEN_SRC)" $(OPTIONS)
$(MAKE) fmt
generate-manifests:
$(MAKE) generate-controller-code GENERATOR=crd OPTIONS="output:crd:artifacts:config=$(RELATIVE_ROOT)/config/crd/bases" CONTROLLER_GEN_SRC=$(CONTROLLER_GEN_SRC)
fmt: $(GOIMPORTS) ## Run goimports
$(GOIMPORTS) -w -local github.com/vmware-tanzu ./