forked from kubegems/kubegems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
124 lines (96 loc) · 5.36 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
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
BUILD_DATE?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_VERSION?=$(shell git describe --tags --dirty 2>/dev/null)
GIT_COMMIT?=$(shell git rev-parse HEAD 2>/dev/null)
GIT_BRANCH?=$(shell git symbolic-ref --short HEAD 2>/dev/null)
BIN_DIR = ${PWD}/bin
ifeq (${GIT_VERSION},)
GIT_VERSION=${GIT_BRANCH}
endif
IMAGE_REGISTRY?=docker.io
IMAGE_TAG=${GIT_VERSION}
ifeq (${IMAGE_TAG},main)
IMAGE_TAG = latest
endif
# Image URL to use all building/pushing image targets
IMG ?= ${IMAGE_REGISTRY}/kubegems/kubegems:$(IMAGE_TAG)
GOPACKAGE=$(shell go list -m)
ldflags+=-w -s
ldflags+=-X '${GOPACKAGE}/pkg/version.gitVersion=${GIT_VERSION}'
ldflags+=-X '${GOPACKAGE}/pkg/version.gitCommit=${GIT_COMMIT}'
ldflags+=-X '${GOPACKAGE}/pkg/version.buildDate=${BUILD_DATE}'
##@ All
all: container-build ## build all
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
generate: ## Generate WebhookConfiguration, ClusterRole, CustomResourceDefinition objects and code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) paths="./pkg/apis/plugins/..." crd output:crd:artifacts:config=deploy/plugins/kubegems-installer/crds # Generate installer CRDs
$(CONTROLLER_GEN) paths="./pkg/apis/gems/..." crd output:crd:artifacts:config=deploy/plugins/kubegems-local/crds # Generate agent/controller CRDs
$(CONTROLLER_GEN) paths="./pkg/..." object:headerFile="hack/boilerplate.go.txt" # Generate DeepCopy, DeepCopyInto, DeepCopyObject
# $(CONTROLLER_GEN) paths="./pkg/..." rbac:roleName=manager-role webhook output:dir=deploy/rbac # Generate RBAC
# $(CONTROLLER_GEN) paths="./pkg/..." webhook output:dir=deploy/webhook # Generate Webhooks
helm template --namespace kubegems-installer --include-crds kubegems-installer deploy/plugins/kubegems-installer \
| kubectl annotate -f - --local -oyaml meta.helm.sh/release-name=kubegems-installer meta.helm.sh/release-namespace=kubegems-installer \
| tee deploy/installer.yaml
swagger:
go install github.com/swaggo/swag/cmd/[email protected]
swag f -g cmd/main.go
swag i --parseDependency --parseInternal -g cmd/main.go -o docs/swagger
check: linter ## Static code check.
${LINTER} run ./...
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
##@ Build
build: ## Build binaries.
- mkdir -p ${BIN_DIR}
CGO_ENABLED=0 go build -o ${BIN_DIR}/kubegems -gcflags=all="-N -l" -ldflags="${ldflags}" cmd/main.go
plugins-download: ## Build plugins-cache
${BIN_DIR}/kubegems plugins -c bin/plugins template deploy/plugins/* | ${BIN_DIR}/kubegems plugins -c bin/plugins download -
${BIN_DIR}/kubegems plugins -c bin/plugins download deploy/*.yaml
plugins-images: ## List all images used in all plugins
sh scripts/plugins-images.sh --list
container: build ## Build container image.
ifneq (, $(shell which docker))
docker build -t ${IMG} .
else
buildah bud -t ${IMG} .
endif
push: ## Push docker image with the manager.
ifneq (, $(shell which docker))
docker push ${IMG}
else
buildah push ${IMG}
endif
CONTROLLER_GEN = ${BIN_DIR}/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
GOBIN=${BIN_DIR} go install sigs.k8s.io/controller-tools/cmd/[email protected]
KUSTOMIZE = ${BIN_DIR}/kustomize
KUSTOMIZE_VERSION = 4.4.1
kustomize: ## Download kustomize locally if necessary.
mkdir -p $(BIN_DIR)
curl -SLf https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv$(KUSTOMIZE_VERSION)/kustomize_v$(KUSTOMIZE_VERSION)_linux_amd64.tar.gz | tar -xz -C $(BIN_DIR)
LINTER = ${BIN_DIR}/golangci-lint
linter: ## Download controller-gen locally if necessary.
GOBIN=${BIN_DIR} go install github.com/golangci/golangci-lint/cmd/[email protected]
K8S_VERSION = 1.20.0
setup-envtest: ## setup operator test environment
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
setup-envtest use ${K8S_VERSION}