forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
166 lines (130 loc) · 5.33 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
# TEST_FLAGS used as flags of go test.
TEST_FLAGS ?= -v --race
# DAEMON_BINARY_NAME is the name of binary of daemon.
DAEMON_BINARY_NAME=pouchd
# CLI_BINARY_NAME is the name of binary of pouch client.
CLI_BINARY_NAME=pouch
# DAEMON_INTEGRATION_BINARY_NAME is the name of test binary of daemon.
DAEMON_INTEGRATION_BINARY_NAME=pouchd-integration
# INTEGRATION_TESTCASE_BINARY_NAME is the name of binary of integration cases.
INTEGRATION_TESTCASE_BINARY_NAME=pouchd-integration-test
# DEST_DIR is base path used to install pouch & pouchd
DEST_DIR=/usr/local
# the following variables used for the daemon build
# API_VERSION is used for daemon API Version in go build.
API_VERSION="1.24"
# VERSION is used for daemon Release Version in go build.
VERSION ?= "1.0.0-rc1"
# GIT_COMMIT is used for daemon GitCommit in go build.
GIT_COMMIT=$(shell git describe --dirty --always --tags 2> /dev/null || true)
# BUILD_TIME is used for daemon BuildTime in go build.
BUILD_TIME=$(shell date --rfc-3339 s 2> /dev/null | sed -e 's/ /T/')
VERSION_PKG=github.com/alibaba/pouch
DEFAULT_LDFLAGS="-X ${VERSION_PKG}/version.GitCommit=${GIT_COMMIT} \
-X ${VERSION_PKG}/version.Version=${VERSION} \
-X ${VERSION_PKG}/version.ApiVersion=${API_VERSION} \
-X ${VERSION_PKG}/version.BuildTime=${BUILD_TIME}"
# COVERAGE_PACKAGES is the coverage we care about.
COVERAGE_PACKAGES=$(shell go list ./... | \
grep -v github.com/alibaba/pouch$$ | \
grep -v github.com/alibaba/pouch/storage/volume/examples/demo | \
grep -v github.com/alibaba/pouch/test | \
grep -v github.com/alibaba/pouch/cli | \
grep -v github.com/alibaba/pouch/cri/apis | \
grep -v github.com/alibaba/pouch/apis/types )
COVERAGE_PACKAGES_LIST=$(shell echo $(COVERAGE_PACKAGES) | tr " " ",")
build: build-daemon build-cli ## build PouchContainer both daemon and cli binaries
build-daemon: modules ## build PouchContainer daemon binary
@echo "$@: bin/${DAEMON_BINARY_NAME}"
@mkdir -p bin
@GOOS=linux go build -ldflags ${DEFAULT_LDFLAGS} -o bin/${DAEMON_BINARY_NAME} -tags 'selinux'
build-cli: ## build PouchContainer cli binary
@echo "$@: bin/${CLI_BINARY_NAME}"
@mkdir -p bin
@go build -o bin/${CLI_BINARY_NAME} github.com/alibaba/pouch/cli
build-daemon-integration: modules ## build PouchContainer daemon integration testing binary
@echo $@
@mkdir -p bin
go test -c ${TEST_FLAGS} \
-cover -covermode=atomic -coverpkg ${COVERAGE_PACKAGES_LIST} \
-o bin/${DAEMON_INTEGRATION_BINARY_NAME}
build-integration-test: modules ## build PouchContainer integration test-case binary
@echo $@
@mkdir -p bin
go test -c \
-o bin/${INTEGRATION_TESTCASE_BINARY_NAME} github.com/alibaba/pouch/test
modules: ## run modules to generate volume related code
@echo "build volume $@"
@./hack/module --clean
@./hack/module --add-volume=github.com/alibaba/pouch/storage/volume/modules/tmpfs
@./hack/module --add-volume=github.com/alibaba/pouch/storage/volume/modules/local
install: ## install pouch and pouchd binary into /usr/local/bin
@echo $@
@mkdir -p $(DEST_DIR)/bin
install bin/$(CLI_BINARY_NAME) $(DEST_DIR)/bin
install bin/$(DAEMON_BINARY_NAME) $(DEST_DIR)/bin
uninstall: ## uninstall pouchd and pouch binary
@echo $@
@rm -f $(addprefix $(DEST_DIR)/bin/,$(notdir $(DAEMON_BINARY_NAME)))
@rm -f $(addprefix $(DEST_DIR)/bin/,$(notdir $(CLI_BINARY_NAME)))
.PHONY: download_dependencies
download_dependencies: ## download related dependencies, such as dumb_init
@echo $@
hack/install/install_ci_related.sh
hack/install/install_containerd.sh
hack/install/install_dumb_init.sh
hack/install/install_local_persist.sh
hack/install/install_lxcfs.sh
hack/install/install_nsenter.sh
hack/install/install_runc.sh
.PHONY: clean
clean: ## clean to remove bin/* and files created by module
@go clean
@rm -f bin/*
@rm -rf coverage/*
@./hack/module --clean
.PHONY: check
check: gometalinter validate-swagger ## run all linters
.PHONY: validate-swagger
validate-swagger: ## run swagger validate
@echo $@
./hack/validate_swagger.sh
# gometalinter consumes .gometalinter.json as config.
.PHONY: gometalinter
gometalinter: ## run gometalinter for go source code
@echo $@
gometalinter --config .gometalinter.json ./...
.PHONY: unit-test
unit-test: modules ## run go unit-test
@echo $@
@mkdir -p coverage
@( for pkg in ${COVERAGE_PACKAGES}; do \
go test ${TEST_FLAGS} \
-cover -covermode=atomic \
-coverprofile=coverage/unit-test-`echo $$pkg | tr "/" "_"`.out \
$$pkg || exit; \
done )
.PHONY: integration-test
integration-test: ## run daemon integration-test
@echo $@
@mkdir -p coverage
./hack/testing/run_daemon_integration.sh
.PHONY: cri-v1alpha1-test
cri-v1alpha1-test: ## run v1 alpha1 cri-v1alpha1-test
@echo $@
@mkdir -p coverage
./hack/testing/run_daemon_cri_integration.sh v1alpha1
.PHONY: cri-v1alpha2-test
cri-v1alpha2-test: ## run v1 alpha2 cri-v1alpha2-test
@echo $@
@mkdir -p coverage
./hack/testing/run_daemon_cri_integration.sh v1alpha2
.PHONY: test
test: unit-test integration-test cri-v1alpha1-test cri-v1alpha2-test ## run the unit-test, integration-test , cri-v1alpha1-test and cri-v1alpha2-test
.PHONY: coverage
coverage: ## combine coverage after test
@echo $@
@gocovmerge coverage/* > coverage.txt
.PHONY: help
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-28s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)