forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·445 lines (354 loc) · 16.4 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# Copyright IBM Corp All Rights Reserved.
# Copyright London Stock Exchange Group All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# -------------------------------------------------------------
# This makefile defines the following targets
#
# - all (default) - builds all targets and runs all tests/checks
# - checks - runs all tests/checks
# - desk-check - runs linters and verify to test changed packages
# - configtxgen - builds a native configtxgen binary
# - configtxlator - builds a native configtxlator binary
# - cryptogen - builds a native cryptogen binary
# - peer - builds a native fabric peer binary
# - orderer - builds a native fabric orderer binary
# - release - builds release packages for the host platform
# - release-all - builds release packages for all target platforms
# - unit-test - runs the go-test based unit tests
# - verify - runs unit tests for only the changed package tree
# - profile - runs unit tests for all packages in coverprofile mode (slow)
# - test-cmd - generates a "go test" string suitable for manual customization
# - behave - runs the behave test
# - behave-deps - ensures pre-requisites are available for running behave manually
# - gotools - installs go tools like golint
# - linter - runs all code checks
# - license - checks go source files for Apache license header
# - native - ensures all native binaries are available
# - docker[-clean] - ensures all docker images are available[/cleaned]
# - peer-docker[-clean] - ensures the peer container is available[/cleaned]
# - orderer-docker[-clean] - ensures the orderer container is available[/cleaned]
# - tools-docker[-clean] - ensures the tools container is available[/cleaned]
# - protos - generate all protobuf artifacts based on .proto files
# - clean - cleans the build area
# - clean-all - superset of 'clean' that also removes persistent state
# - dist-clean - clean release packages for all target platforms
# - unit-test-clean - cleans unit test state (particularly from docker)
# - basic-checks - performs basic checks like license, spelling and linter
# - enable_ci_only_tests - triggers unit-tests in downstream jobs. Applicable only for CI not to
# use in the local machine.
# - docker-thirdparty - pulls thirdparty images (kafka,zookeeper,couchdb)
BASE_VERSION = 1.1.1
PREV_VERSION = 1.1.0
CHAINTOOL_RELEASE=1.1.0
BASEIMAGE_RELEASE=0.4.6
# Allow to build as a submodule setting the main project to
# the PROJECT_NAME env variable, for example,
# export PROJECT_NAME=hyperledger/fabric-test
ifeq ($(PROJECT_NAME),true)
PROJECT_NAME = $(PROJECT_NAME)/fabric
else
PROJECT_NAME = hyperledger/fabric
endif
IS_RELEASE = false
EXPERIMENTAL ?= true
ifeq ($(EXPERIMENTAL),true)
GO_TAGS += experimental
endif
ifneq ($(IS_RELEASE),true)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION)
else
PROJECT_VERSION=$(BASE_VERSION)
endif
PKGNAME = github.com/$(PROJECT_NAME)
CGO_FLAGS = CGO_CFLAGS=" "
ARCH=$(shell uname -m)
MARCH=$(shell go env GOOS)-$(shell go env GOARCH)
# defined in common/metadata/metadata.go
METADATA_VAR = Version=$(PROJECT_VERSION)
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
METADATA_VAR += BaseDockerNamespace=$(BASE_DOCKER_NS)
METADATA_VAR += Experimental=$(EXPERIMENTAL)
GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))
GO_TAGS ?=
CHAINTOOL_URL ?= https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/chaintool-$(CHAINTOOL_RELEASE)/hyperledger-fabric-chaintool-$(CHAINTOOL_RELEASE).jar
export GO_LDFLAGS GO_TAGS
EXECUTABLES = go docker git curl
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))
GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim)
JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
PROTOS = $(shell git ls-files *.proto | grep -v vendor)
# No sense rebuilding when non production code is changed
PROJECT_FILES = $(shell git ls-files | grep -v ^test | grep -v ^unit-test | \
grep -v ^bddtests | grep -v ^docs | grep -v _test.go$ | grep -v .md$ | \
grep -v ^.git | grep -v ^examples | grep -v ^devenv | grep -v .png$ | \
grep -v ^LICENSE )
RELEASE_TEMPLATES = $(shell git ls-files | grep "release/templates")
IMAGES = peer orderer ccenv javaenv buildenv testenv tools
RELEASE_PLATFORMS = windows-amd64 darwin-amd64 linux-amd64 linux-ppc64le linux-s390x
RELEASE_PKGS = configtxgen cryptogen configtxlator peer orderer
pkgmap.cryptogen := $(PKGNAME)/common/tools/cryptogen
pkgmap.configtxgen := $(PKGNAME)/common/tools/configtxgen
pkgmap.configtxlator := $(PKGNAME)/common/tools/configtxlator
pkgmap.peer := $(PKGNAME)/peer
pkgmap.orderer := $(PKGNAME)/orderer
pkgmap.block-listener := $(PKGNAME)/examples/events/block-listener
include docker-env.mk
all: native docker checks
checks: license spelling linter unit-test behave
basic-checks: license spelling linter
desk-check: license spelling linter verify behave
# Pull thirdparty docker images based on the latest baseimage release version
.PHONY: docker-thirdparty
docker-thirdparty:
docker pull $(DOCKER_NS)/fabric-couchdb:$(BASE_DOCKER_TAG)
docker tag $(DOCKER_NS)/fabric-couchdb:$(BASE_DOCKER_TAG) $(DOCKER_NS)/fabric-couchdb
docker pull $(DOCKER_NS)/fabric-zookeeper:$(BASE_DOCKER_TAG)
docker tag $(DOCKER_NS)/fabric-zookeeper:$(BASE_DOCKER_TAG) $(DOCKER_NS)/fabric-zookeeper
docker pull $(DOCKER_NS)/fabric-kafka:$(BASE_DOCKER_TAG)
docker tag $(DOCKER_NS)/fabric-kafka:$(BASE_DOCKER_TAG) $(DOCKER_NS)/fabric-kafka
.PHONY: spelling
spelling:
@scripts/check_spelling.sh
.PHONY: license
license:
@scripts/check_license.sh
.PHONY: gotools
gotools:
mkdir -p build/bin
cd gotools && $(MAKE) install BINDIR=$(GOPATH)/bin
.PHONY: gotools-clean
gotools-clean:
cd gotools && $(MAKE) clean
# This is a legacy target left to satisfy existing CI scripts
membersrvc-image:
@echo "membersrvc has been removed from this build"
.PHONY: peer
peer: build/bin/peer
peer-docker: build/image/peer/$(DUMMY)
.PHONY: orderer
orderer: build/bin/orderer
orderer-docker: build/image/orderer/$(DUMMY)
.PHONY: configtxgen
configtxgen: GO_TAGS+= nopkcs11
configtxgen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
configtxgen: build/bin/configtxgen
configtxlator: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
configtxlator: build/bin/configtxlator
cryptogen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
cryptogen: build/bin/cryptogen
tools-docker: build/image/tools/$(DUMMY)
javaenv: build/image/javaenv/$(DUMMY)
buildenv: build/image/buildenv/$(DUMMY)
build/image/testenv/$(DUMMY): build/image/buildenv/$(DUMMY)
testenv: build/image/testenv/$(DUMMY)
unit-test: unit-test-clean peer-docker testenv
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
unit-tests: unit-test
enable_ci_only_tests: testenv
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
verify: unit-test-clean peer-docker testenv
cd unit-test && JOB_TYPE=VERIFY docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
profile: unit-test-clean peer-docker testenv
cd unit-test && JOB_TYPE=PROFILE docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
# Generates a string to the terminal suitable for manual augmentation / re-issue, useful for running tests by hand
test-cmd:
@echo "go test -tags \"$(GO_TAGS)\" -ldflags \"$(GO_LDFLAGS)\""
docker: docker-thirdparty $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
native: peer orderer configtxgen cryptogen configtxlator
behave-deps: docker peer build/bin/block-listener configtxgen cryptogen
behave: behave-deps
@echo "Running behave tests"
@cd bddtests; behave $(BEHAVE_OPTS)
behave-peer-chaincode: build/bin/peer peer-docker orderer-docker
@cd peer/chaincode && behave
linter: buildenv
@echo "LINT: Running code checks.."
@$(DRUN) $(DOCKER_NS)/fabric-buildenv:$(DOCKER_TAG) ./scripts/golinter.sh
%/chaintool: Makefile
@echo "Installing chaintool"
@mkdir -p $(@D)
curl -fL $(CHAINTOOL_URL) > $@
chmod +x $@
# We (re)build a package within a docker context but persist the $GOPATH/pkg
# directory so that subsequent builds are faster
build/docker/bin/%: $(PROJECT_FILES)
$(eval TARGET = ${patsubst build/docker/bin/%,%,${@}})
@echo "Building $@"
@mkdir -p build/docker/bin build/docker/$(TARGET)/pkg
@$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/$(TARGET)/pkg):/opt/gopath/pkg \
$(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -tags "$(GO_TAGS)" -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.$(@F))
@touch $@
build/bin:
mkdir -p $@
changelog:
./scripts/changelog.sh v$(PREV_VERSION) v$(BASE_VERSION)
build/docker/gotools/bin/protoc-gen-go: build/docker/gotools
build/docker/gotools: gotools/Makefile
@mkdir -p $@/bin $@/obj
@$(DRUN) \
-v $(abspath $@):/opt/gotools \
-w /opt/gopath/src/$(PKGNAME)/gotools \
$(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \
make install BINDIR=/opt/gotools/bin OBJDIR=/opt/gotools/obj
# Both peer and peer-docker depend on ccenv and javaenv (all docker env images it supports).
build/bin/peer: build/image/ccenv/$(DUMMY) build/image/javaenv/$(DUMMY)
build/image/peer/$(DUMMY): build/image/ccenv/$(DUMMY) build/image/javaenv/$(DUMMY)
build/bin/%: $(PROJECT_FILES)
@mkdir -p $(@D)
@echo "$@"
$(CGO_FLAGS) GOBIN=$(abspath $(@D)) go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
@echo "Binary available as $@"
@touch $@
# payload definitions'
build/image/ccenv/payload: build/docker/gotools/bin/protoc-gen-go \
build/bin/chaintool \
build/goshim.tar.bz2
build/image/javaenv/payload: build/javashim.tar.bz2 \
build/protos.tar.bz2 \
settings.gradle
build/image/peer/payload: build/docker/bin/peer \
build/sampleconfig.tar.bz2
build/image/orderer/payload: build/docker/bin/orderer \
build/sampleconfig.tar.bz2
build/image/buildenv/payload: build/gotools.tar.bz2 \
build/docker/gotools/bin/protoc-gen-go
build/image/testenv/payload: build/docker/bin/orderer \
build/docker/bin/peer \
build/sampleconfig.tar.bz2 \
images/testenv/install-softhsm2.sh
build/image/tools/payload: build/docker/bin/cryptogen \
build/docker/bin/configtxgen \
build/docker/bin/configtxlator \
build/docker/bin/peer \
build/sampleconfig.tar.bz2
build/image/%/payload:
mkdir -p $@
cp $^ $@
.PRECIOUS: build/image/%/Dockerfile
build/image/%/Dockerfile: images/%/Dockerfile.in
@cat $< \
| sed -e 's/_BASE_NS_/$(BASE_DOCKER_NS)/g' \
| sed -e 's/_NS_/$(DOCKER_NS)/g' \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $@
@echo LABEL $(BASE_DOCKER_LABEL).version=$(PROJECT_VERSION) \\>>$@
@echo " " $(BASE_DOCKER_LABEL).base.version=$(BASEIMAGE_RELEASE)>>$@
build/image/%/$(DUMMY): Makefile build/image/%/payload build/image/%/Dockerfile
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
@echo "Building docker $(TARGET)-image"
$(DBUILD) -t $(DOCKER_NS)/fabric-$(TARGET) $(@D)
docker tag $(DOCKER_NS)/fabric-$(TARGET) $(DOCKER_NS)/fabric-$(TARGET):$(DOCKER_TAG)
@touch $@
build/gotools.tar.bz2: build/docker/gotools
(cd $</bin && tar -jc *) > $@
build/goshim.tar.bz2: $(GOSHIM_DEPS)
@echo "Creating $@"
@tar -jhc -C $(GOPATH)/src $(patsubst $(GOPATH)/src/%,%,$(GOSHIM_DEPS)) > $@
build/sampleconfig.tar.bz2: $(shell find sampleconfig -type f)
(cd sampleconfig && tar -jc *) > $@
build/javashim.tar.bz2: $(JAVASHIM_DEPS)
build/protos.tar.bz2: $(PROTOS)
build/%.tar.bz2:
@echo "Creating $@"
@tar -jc $^ > $@
# builds release packages for the host platform
release: $(patsubst %,release/%, $(MARCH))
# builds release packages for all target platforms
release-all: $(patsubst %,release/%, $(RELEASE_PLATFORMS))
release/%: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
release/windows-amd64: GOOS=windows
release/windows-amd64: GO_TAGS+= nopkcs11
release/windows-amd64: $(patsubst %,release/windows-amd64/bin/%, $(RELEASE_PKGS)) release/windows-amd64/install
release/darwin-amd64: GOOS=darwin
release/darwin-amd64: GO_TAGS+= nopkcs11
release/darwin-amd64: $(patsubst %,release/darwin-amd64/bin/%, $(RELEASE_PKGS)) release/darwin-amd64/install
release/linux-amd64: GOOS=linux
release/linux-amd64: GO_TAGS+= nopkcs11
release/linux-amd64: $(patsubst %,release/linux-amd64/bin/%, $(RELEASE_PKGS)) release/linux-amd64/install
release/%-amd64: DOCKER_ARCH=x86_64
release/%-amd64: GOARCH=amd64
release/linux-%: GOOS=linux
release/linux-ppc64le: GOARCH=ppc64le
release/linux-ppc64le: DOCKER_ARCH=ppc64le
release/linux-ppc64le: GO_TAGS+= nopkcs11
release/linux-ppc64le: $(patsubst %,release/linux-ppc64le/bin/%, $(RELEASE_PKGS)) release/linux-ppc64le/install
release/linux-s390x: GOARCH=s390x
release/linux-s390x: DOCKER_ARCH=s390x
release/linux-s390x: GO_TAGS+= nopkcs11
release/linux-s390x: $(patsubst %,release/linux-s390x/bin/%, $(RELEASE_PKGS)) release/linux-s390x/install
release/%/bin/configtxlator: $(PROJECT_FILES)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
$(CGO_FLAGS) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
release/%/bin/configtxgen: $(PROJECT_FILES)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
$(CGO_FLAGS) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
release/%/bin/cryptogen: $(PROJECT_FILES)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
$(CGO_FLAGS) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
release/%/bin/orderer: GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))
release/%/bin/orderer: $(PROJECT_FILES)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
$(CGO_FLAGS) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
release/%/bin/peer: GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))
release/%/bin/peer: $(PROJECT_FILES)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
$(CGO_FLAGS) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
release/%/install: $(PROJECT_FILES)
mkdir -p $(@D)/bin
@cat $(@D)/../templates/get-docker-images.in \
| sed -e 's/_NS_/$(DOCKER_NS)/g' \
| sed -e 's/_ARCH_/$(DOCKER_ARCH)/g' \
| sed -e 's/_VERSION_/$(PROJECT_VERSION)/g' \
| sed -e 's/_BASE_DOCKER_TAG_/$(BASE_DOCKER_TAG)/g' \
> $(@D)/bin/get-docker-images.sh
@chmod +x $(@D)/bin/get-docker-images.sh
.PHONY: dist
dist: dist-clean dist/$(MARCH)
dist-all: dist-clean $(patsubst %,dist/%, $(RELEASE_PLATFORMS))
dist/%: release/%
mkdir -p release/$(@F)/config
cp -r sampleconfig/*.yaml release/$(@F)/config
cd release/$(@F) && tar -czvf hyperledger-fabric-$(@F).$(PROJECT_VERSION).tar.gz *
.PHONY: protos
protos: buildenv
@$(DRUN) $(DOCKER_NS)/fabric-buildenv:$(DOCKER_TAG) ./scripts/compile_protos.sh
%-docker-clean:
$(eval TARGET = ${patsubst %-docker-clean,%,${@}})
-docker images -q $(DOCKER_NS)/fabric-$(TARGET) | xargs -I '{}' docker rmi -f '{}'
-@rm -rf build/image/$(TARGET) ||:
docker-clean: $(patsubst %,%-docker-clean, $(IMAGES))
.PHONY: clean
clean: docker-clean unit-test-clean release-clean
-@rm -rf build ||:
.PHONY: clean-all
clean-all: clean gotools-clean dist-clean
-@rm -rf /var/hyperledger/* ||:
.PHONY: dist-clean
dist-clean:
-@rm -rf release/windows-amd64/hyperledger-fabric-windows-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/darwin-amd64/hyperledger-fabric-darwin-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-amd64/hyperledger-fabric-linux-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-ppc64le/hyperledger-fabric-linux-ppc64le.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-s390x/hyperledger-fabric-linux-s390x.$(PROJECT_VERSION).tar.gz ||:
%-release-clean:
$(eval TARGET = ${patsubst %-release-clean,%,${@}})
-@rm -rf release/$(TARGET)
release-clean: $(patsubst %,%-release-clean, $(RELEASE_PLATFORMS))
.PHONY: unit-test-clean
unit-test-clean:
cd unit-test && docker-compose down