forked from ceph/go-ceph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
347 lines (296 loc) · 10.1 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
CI_IMAGE_NAME ?= go-ceph-ci
CONTAINER_CMD ?=
CONTAINER_OPTS ?= --security-opt $(shell grep -q selinux /sys/kernel/security/lsm 2>/dev/null && echo "label=disable" || echo "apparmor:unconfined")
CONTAINER_BUILD_OPTS ?=
CONTAINER_CONFIG_DIR ?= testing/containers/ceph
VOLUME_FLAGS ?=
CEPH_VERSION ?= pacific
RESULTS_DIR ?=
CHECK_GOFMT_FLAGS ?= -e -s -l
IMPLEMENTS_OPTS ?=
BUILD_TAGS ?= $(CEPH_VERSION)
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell docker version >/dev/null 2>&1 && echo docker)
endif
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell podman version >/dev/null 2>&1 && echo podman)
endif
ifeq ($(CEPH_VERSION),octopus)
CEPH_TAG ?= v15
endif
ifeq ($(CEPH_VERSION),pacific)
CEPH_TAG ?= v16
endif
ifeq ($(CEPH_VERSION),quincy)
CEPH_TAG ?= v17
endif
ifeq ($(CEPH_VERSION),reef)
CEPH_TAG ?= v18
endif
ifeq ($(CEPH_VERSION),squid)
CEPH_TAG ?= v19
endif
# pre-<codename> indicates we want to consume pre-release versions of ceph from
# the ceph ci. This way we can start testing on ceph versions before they hit
# quay.io/ceph/ceph
ifeq ($(CEPH_VERSION),pre-quincy)
CEPH_TAG ?= quincy
CEPH_IMG ?= quay.ceph.io/ceph-ci/ceph
GO_CEPH_VERSION := quincy
BUILD_TAGS := quincy,ceph_pre_quincy
endif
ifeq ($(CEPH_VERSION),pre-pacific)
CEPH_TAG ?= pacific
CEPH_IMG ?= quay.ceph.io/ceph-ci/ceph
GO_CEPH_VERSION := pacific
BUILD_TAGS := pacific,ceph_pre_pacific
endif
ifeq ($(CEPH_VERSION),pre-reef)
CEPH_TAG ?= reef
CEPH_IMG ?= quay.ceph.io/ceph-ci/ceph
GO_CEPH_VERSION := reef
BUILD_TAGS := reef,ceph_pre_reef
endif
ifeq ($(CEPH_VERSION),pre-squid)
CEPH_TAG ?= squid
CEPH_IMG ?= quay.ceph.io/ceph-ci/ceph
GO_CEPH_VERSION := squid
BUILD_TAGS := squid,ceph_pre_squid
endif
ifeq ($(CEPH_VERSION),main)
CEPH_TAG ?= main
CEPH_IMG ?= quay.ceph.io/ceph-ci/ceph
GO_CEPH_VERSION := main
BUILD_TAGS := main,ceph_main
endif
GO_CMD:=go
GOFMT_CMD:=gofmt
GOARCH:=$(shell $(GO_CMD) env GOARCH)
GOPROXY:=$(shell $(GO_CMD) env GOPROXY)
# the full name of the marker file including the ceph version
BUILDFILE=.build.$(CEPH_VERSION)
# files marking daemon containers supporting the tests
TEST_CTR_A=.run.test_ceph_a
TEST_CTR_B=.run.test_ceph_b
TEST_CTR_NET=.run.test_ceph_net
# the name of the image plus ceph version as tag
CI_IMAGE_TAG=$(CI_IMAGE_NAME):$(CEPH_VERSION)
ifneq ($(NO_PTRGUARD),)
CONTAINER_OPTS += -e NO_PTRGUARD=true
BUILD_TAGS := $(BUILD_TAGS),no_ptrguard
endif
ifneq ($(NO_PREVIEW),)
CONTAINER_OPTS += -e NO_PREVIEW=true
else
BUILD_TAGS := $(BUILD_TAGS),ceph_preview
endif
CONTAINER_OPTS += -e BUILD_TAGS=$(BUILD_TAGS)
ifdef GOPROXY
CONTAINER_OPTS += --env GOPROXY=$(GOPROXY)
endif
ifneq ($(USE_CACHE),)
GOCACHE_VOLUME := -v test_ceph_go_cache:/go
endif
SELINUX := $(shell getenforce 2>/dev/null)
ifeq ($(SELINUX),Enforcing)
VOLUME_FLAGS = :z
endif
ifdef RESULTS_DIR
RESULTS_VOLUME := -v $(RESULTS_DIR):/results$(VOLUME_FLAGS)
endif
ifneq ($(USE_GOCO),)
GO_CMD:=$(CONTAINER_CMD) run $(CONTAINER_OPTS) --rm $(GOCACHE_VOLUME) -v $(CURDIR):/go/src/github.com/ceph/go-ceph$(VOLUME_FLAGS) --entrypoint $(GO_CMD) $(CI_IMAGE_TAG)
GOFMT_CMD:=$(CONTAINER_CMD) run $(CONTAINER_OPTS) --rm $(GOCACHE_VOLUME) -v $(CURDIR):/go/src/github.com/ceph/go-ceph$(VOLUME_FLAGS) --entrypoint $(GOFMT_CMD) $(CI_IMAGE_TAG)
endif
# Assemble the various build args that will be passed container build command(s)
CONTAINER_BUILD_ARGS:=$(DEFAULT_BUILD_ARGS)
CONTAINER_BUILD_ARGS += --build-arg GOARCH=$(GOARCH)
ifneq ($(GO_VERSION),)
CONTAINER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION)
endif
ifdef CEPH_IMG
CONTAINER_BUILD_ARGS += --build-arg CEPH_IMG=$(CEPH_IMG)
endif
ifdef CEPH_TAG
CONTAINER_BUILD_ARGS += --build-arg CEPH_TAG=$(CEPH_TAG)
endif
ifdef GO_CEPH_VERSION
CONTAINER_BUILD_ARGS += --build-arg GO_CEPH_VERSION=$(GO_CEPH_VERSION)
else
CONTAINER_BUILD_ARGS += --build-arg GO_CEPH_VERSION=$(CEPH_VERSION)
endif
ifdef GOPROXY
CONTAINER_BUILD_ARGS += --build-arg GOPROXY=$(GOPROXY)
endif
build:
$(GO_CMD) build -v -tags $(BUILD_TAGS) $(shell $(GO_CMD) list ./... | grep -v /contrib)
fmt:
$(GO_CMD) fmt ./...
test:
$(GO_CMD) test -v -tags $(BUILD_TAGS) ./...
.PHONY: test-docker test-container test-multi-container
test-docker: test-container
test-container: $(BUILDFILE) $(RESULTS_DIR)
$(CONTAINER_CMD) run $(CONTAINER_OPTS) --rm --hostname test_ceph_aio \
-v $(CURDIR):/go/src/github.com/ceph/go-ceph$(VOLUME_FLAGS) $(RESULTS_VOLUME) $(GOCACHE_VOLUME) \
$(CI_IMAGE_TAG) $(ENTRYPOINT_ARGS)
test-multi-container: $(BUILDFILE) $(RESULTS_DIR)
-$(MAKE) test-containers-kill
-$(MAKE) test-containers-rm-volumes
-$(MAKE) test-containers-rm-network
$(MAKE) test-containers-test
$(MAKE) test-containers-kill
$(MAKE) test-containers-rm-volumes
$(MAKE) test-containers-rm-network
# The test-containers-* cleanup rules:
.PHONY: test-containers-clean \
test-containers-kill \
test-containers-rm-volumes \
test-containers-rm-network
test-containers-clean: test-containers-kill
-$(MAKE) test-containers-rm-volumes
-$(MAKE) test-containers-rm-network
test-containers-kill:
-$(CONTAINER_CMD) kill test_ceph_a || $(CONTAINER_CMD) rm test_ceph_a
-$(CONTAINER_CMD) kill test_ceph_b || $(CONTAINER_CMD) rm test_ceph_b
$(RM) $(TEST_CTR_A) $(TEST_CTR_B)
sleep 0.3
# sometimes the container runtime fails to remove things immediately after
# killing the containers. The short sleep helps avoid hitting that condition.
test-containers-rm-volumes:
$(CONTAINER_CMD) volume remove test_ceph_a_data test_ceph_b_data
test-containers-rm-network:
$(CONTAINER_CMD) network rm test_ceph_net
$(RM) $(TEST_CTR_NET)
# Thest test-containers-* setup rules:
.PHONY: test-containers-network \
test-containers-test_ceph_a \
test-containers-test_ceph_b \
test-containers-test
test-containers-network: $(TEST_CTR_NET)
$(TEST_CTR_NET):
($(CONTAINER_CMD) network ls -q | grep -q test_ceph_net) \
|| $(CONTAINER_CMD) network create test_ceph_net
@echo "test_ceph_net" > $(TEST_CTR_NET)
test-containers-test_ceph_a: $(TEST_CTR_A)
$(TEST_CTR_A): $(TEST_CTR_NET) $(BUILDFILE)
$(CONTAINER_CMD) run $(CONTAINER_OPTS) \
--cidfile=$(TEST_CTR_A) --rm -d --name test_ceph_a \
--hostname test_ceph_a \
--net test_ceph_net \
-v test_ceph_a_data:/tmp/ceph $(CI_IMAGE_TAG) \
--test-run=NONE --pause
test-containers-test_ceph_b: $(TEST_CTR_B)
$(TEST_CTR_B): $(TEST_CTR_NET) $(BUILDFILE)
$(CONTAINER_CMD) run $(CONTAINER_OPTS) \
--cidfile=$(TEST_CTR_B) --rm -d --name test_ceph_b \
--hostname test_ceph_b \
--net test_ceph_net \
-v test_ceph_b_data:/tmp/ceph $(CI_IMAGE_TAG) \
--test-run=NONE --pause
test-containers-test: $(BUILDFILE) $(TEST_CTR_A) $(TEST_CTR_B)
$(CONTAINER_CMD) run $(CONTAINER_OPTS) --rm \
--net test_ceph_net \
-v test_ceph_a_data:/ceph_a \
-v test_ceph_b_data:/ceph_b \
-v $(CURDIR):/go/src/github.com/ceph/go-ceph$(VOLUME_FLAGS) \
$(RESULTS_VOLUME) $(GOCACHE_VOLUME) \
$(CI_IMAGE_TAG) \
--wait-for=/ceph_a/.ready:/ceph_b/.ready \
--mirror-state=/ceph_b/.mstate \
--ceph-conf=/ceph_a/ceph.conf \
--mirror=/ceph_b/ceph.conf \
--altfs=@/ceph_a/altfs.txt \
$(ENTRYPOINT_ARGS)
ifdef RESULTS_DIR
$(RESULTS_DIR):
mkdir -p $(RESULTS_DIR)
endif
SHELL_SOURCES=entrypoint.sh micro-osd.sh
.PHONY: ci-image
ci-image: $(BUILDFILE)
$(BUILDFILE): $(CONTAINER_CONFIG_DIR)/Dockerfile $(SHELL_SOURCES)
$(CONTAINER_CMD) build \
$(CONTAINER_BUILD_ARGS) \
$(CONTAINER_BUILD_OPTS) \
-t $(CI_IMAGE_TAG) \
-f $(CONTAINER_CONFIG_DIR)/Dockerfile .
@$(CONTAINER_CMD) inspect -f '{{.Id}}' $(CI_IMAGE_TAG) > $(BUILDFILE)
echo $(CEPH_VERSION) >> $(BUILDFILE)
check: check-revive check-format check-shell
check-format:
! $(GOFMT_CMD) $(CHECK_GOFMT_FLAGS) . | sed 's,^,formatting error: ,' | grep 'go$$'
check-revive:
# Configure project's revive checks using .revive.toml
# See: https://github.com/mgechev/revive
revive -config .revive.toml $$(find . -name '*.go')
check-shell:
shellcheck -fgcc $(SHELL_SOURCES)
# Do a quick compile only check of the tests and impliclity the
# library code as well.
test-binaries: \
cephfs.test \
cephfs/admin.test \
common/admin/manager.test \
common/admin/nfs.test \
internal/callbacks.test \
internal/commands.test \
internal/cutil.test \
internal/errutil.test \
internal/retry.test \
rados.test \
rbd.test \
rbd/admin.test
test-bins: test-binaries
%.test: % force_go_build
$(GO_CMD) test -c -tags $(BUILD_TAGS) ./$<
implements:
cd contrib/implements && $(GO_CMD) build -o ../../implements
check-implements: implements
./implements $(IMPLEMENTS_OPTS) cephfs rados rbd
clean-implements:
$(RM) ./implements
.PHONY: api-check
api-check: implements-json
./contrib/apiage.py
.PHONY: api-update
api-update: implements-json
./contrib/apiage.py --mode=update --placeholder-versions
.PHONY: api-promote
api-promote: implements-json
./contrib/apiage.py --mode=promote \
--current-tag="$$(git describe --tags --abbrev=0)"
./contrib/apiage.py --mode=write-doc
.PHONY: api-fix-versions
api-fix-versions:
./contrib/apiage.py --mode=fix-versions \
--current-tag="$$(git describe --tags --abbrev=0)"
./contrib/apiage.py --mode=write-doc
.PHONY: api-doc
api-doc:
./contrib/apiage.py --mode=write-doc
.PHONY: api-check-updates
api-check-updates: $(RESULTS_DIR)
./contrib/apiage.py --mode=find-updates \
--current-tag="$$(git describe --tags --abbrev=0)" \
> $(RESULTS_DIR)/updates-found.json
.PHONY: api-report-updates
api-report-updates: api-check-updates
./contrib/apiage.py --mode=updates-to-markdown \
< $(RESULTS_DIR)/updates-found.json > $(RESULTS_DIR)/updates-found.md
.PHONY: api-report-issuetemplate
api-report-issuetemplate: api-check-updates
./contrib/apiage.py --mode=updates-to-issuetemplate \
--current-tag="$$(git describe --tags --abbrev=0)" \
< $(RESULTS_DIR)/updates-found.json \
> $(RESULTS_DIR)/issue.md
ifeq ($(RESULTS_DIR),)
IMPLEMENTS_DIR:=$(PWD)/_results
else
IMPLEMENTS_DIR:=$(RESULTS_DIR)
endif
implements-json: $(BUILDFILE)
$(MAKE) RESULTS_DIR="$(IMPLEMENTS_DIR)" ENTRYPOINT_ARGS="--test-run=IMPLEMENTS --micro-osd=/bin/true $(ENTRYPOINT_ARGS)" test-container
# force_go_build is phony and builds nothing, can be used for forcing
# go toolchain commands to always run
.PHONY: build fmt test test-docker check test-binaries test-bins force_go_build check-implements clean-implements implements-json