forked from secretflow/kuscia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (113 loc) · 5.47 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
# Image URL to use all building image targets
DATETIME = $(shell date +"%Y%m%d%H%M%S")
KUSCIA_VERSION_TAG = $(shell git describe --tags --always)
# Get current architecture information
UNAME_M_OUTPUT := $(shell uname -m)
# To configure the ARCH variable to either arm64 or amd64 or UNAME_M_OUTPUT
ARCH := $(if $(filter aarch64 arm64,$(UNAME_M_OUTPUT)),arm64,$(if $(filter amd64 x86_64,$(UNAME_M_OUTPUT)),amd64,$(UNAME_M_OUTPUT)))
TAG = ${KUSCIA_VERSION_TAG}-${DATETIME}
IMG := secretflow/kuscia:${TAG}
# TEST_SUITE used by integration test
TEST_SUITE ?= all
ENVOY_IMAGE ?= secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/kuscia-envoy:0.4.0.dev20240407
DEPS_IMAGE ?= secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/kuscia-deps:0.5.0b0
# 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
# Setting SHELL to bash allows bash commands to be executed by recipes.
# 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
.PHONY: all
all: build
##@ 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
.PHONY: help
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%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: ## Generate CustomResourceDefinition objects.
bash hack/generate-crds.sh
.PHONY: generate
generate: gen-clientset gen-proto-code ## Generate all code that Kuscia needs.
.PHONY: gen-clientset
gen-clientset: # Generate CRD runtime.Object and Clientset\Informer|Listers.
bash hack/update-codegen.sh
.PHONY: gen-proto-code
gen-proto-code: # Generate protobuf golang code that Kuscia needs.
bash hack/proto-to-go.sh
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: verify_error_code
verify_error_code: ## Verify integrity of error code i18n configuration.
bash hack/errorcode/gen_error_code_doc.sh verify proto/api/v1alpha1/errorcode/error_code.proto hack/errorcode/i18n/errorcode.zh-CN.toml
.PHONY: gen_error_code_doc
gen_error_code_doc: verify_error_code ## Generate error code markdown doc.
bash hack/errorcode/gen_error_code_doc.sh doc proto/api/v1alpha1/errorcode/error_code.proto hack/errorcode/i18n/errorcode.zh-CN.toml docs/reference/apis/error_code_cn.md
.PHONY: check_code
check_code: verify_error_code fmt vet ## check code format
echo "FINISH"
.PHONY: test
test: ## Run tests.
rm -rf ./test-results
mkdir -p test-results
go test ./cmd/... --parallel 4 -gcflags="all=-N -l" -coverprofile=test-results/cmd.covprofile.out | tee test-results/cmd.output.txt
go test ./pkg/... --parallel 4 -gcflags="all=-N -l" -coverprofile=test-results/pkg.covprofile.out | tee test-results/pkg.output.txt
cat ./test-results/cmd.output.txt | go-junit-report > ./test-results/TEST-cmd.xml
cat ./test-results/pkg.output.txt | go-junit-report > ./test-results/TEST-pkg.xml
echo "mode: set" > ./test-results/coverage.out && cat ./test-results/*.covprofile.out | grep -v mode: | sort -r | awk '{if($$1 != last) {print $0;last=$$1}}' >> ./test-results/coverage.out
cat ./test-results/coverage.out | gocover-cobertura > ./test-results/coverage.xml
.PHONY: clean
clean: # clean build and test product.
-rm -rf ./test-results
-rm -rf ./build/apps
-rm -rf ./build/framework
-rm -rf ./tmp-crd-code
-rm -rf ./build/linux
##@ Build
.PHONY: build
build: check_code ## Build kuscia binary.
bash hack/build.sh -t kuscia
mkdir -p build/linux/${ARCH}
cp -rp build/apps build/linux/${ARCH}
.PHONY: docs
docs: gen_error_code_doc ## Build docs.
cd docs && pip install -r requirements.txt && make html
.PHONY: deps-build
deps-build:
bash hack/k3s/build.sh
mkdir -p build/linux/${ARCH}/k3s
cp -rp build/k3s/bin build/linux/${ARCH}/k3s
.PHONY: deps-image
deps-image: deps-build
docker build -t ${DEPS_IMAGE} -f ./build/dockerfile/base/kuscia-deps.Dockerfile .
.PHONY: image
image: export GOOS=linux
image: export GOARCH=${ARCH}
image: build ## Build docker image with the manager.
docker build -t ${IMG} --build-arg KUSCIA_ENVOY_IMAGE=${ENVOY_IMAGE} --build-arg DEPS_IMAGE=${DEPS_IMAGE} -f ./build/dockerfile/kuscia-anolis.Dockerfile .
.PHONY: build-monitor
build-monitor:
docker build -t secretflow/kusica-monitor -f ./build/dockerfile/kuscia-monitor.Dockerfile .
.PHONY: integration_test
integration_test: image ## Run Integration Test
mkdir -p run/test
cd run && KUSCIA_IMAGE=${IMG} docker run --rm ${IMG} cat /home/kuscia/scripts/test/integration_test.sh > ./test/integration_test.sh && chmod u+x ./test/integration_test.sh
cd run && KUSCIA_IMAGE=${IMG} ./test/integration_test.sh ${TEST_SUITE}