forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
275 lines (224 loc) · 9.31 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
# Copyright IBM Corp All Rights Reserved.
# Copyright London Stock Exchange Group All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -------------------------------------------------------------
# This makefile defines the following targets
#
# - all (default) - builds all targets and runs all tests/checks
# - checks - runs all tests/checks
# - peer - builds a native fabric peer binary
# - orderer - builds a native fabric orderer binary
# - unit-test - runs the go-test based unit tests
# - test-cmd - generates a "go test" string suitable for manual customization
# - behave - runs the behave test
# - behave-deps - ensures pre-requisites are availble for running behave manually
# - gotools - installs go tools like golint
# - linter - runs all code checks
# - 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]
# - protos - generate all protobuf artifacts based on .proto files
# - clean - cleans the build area
# - dist-clean - superset of 'clean' that also removes persistent state
PROJECT_NAME = hyperledger/fabric
BASE_VERSION = 1.0.0
IS_RELEASE = false
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)
CHAINTOOL_RELEASE=v0.10.3
BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
# defined in common/metadata/metadata.go
METADATA_VAR = Version=$(PROJECT_VERSION)
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))
CHAINTOOL_URL ?= https://github.com/hyperledger/fabric-chaintool/releases/download/$(CHAINTOOL_RELEASE)/chaintool
export GO_LDFLAGS
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)
MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*)
PROJECT_FILES = $(shell git ls-files)
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka couchdb
pkgmap.configtxgen := $(PKGNAME)/common/configtx/tool/configtxgen
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: linter unit-test behave
.PHONY: gotools
gotools:
mkdir -p build/bin
cd gotools && $(MAKE) install BINDIR=$(GOPATH)/bin
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: build/bin/configtxgen
buildenv: build/image/buildenv/$(DUMMY)
build/image/testenv/$(DUMMY): build/image/buildenv/$(DUMMY)
testenv: build/image/testenv/$(DUMMY)
couchdb: build/image/couchdb/$(DUMMY)
unit-test: peer-docker testenv couchdb
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
unit-tests: unit-test
# Generates a string to the terminal suitable for manual augmentation / re-issue, useful for running tests by hand
test-cmd:
@echo "go test -ldflags \"$(GO_LDFLAGS)\""
docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
native: peer orderer
BEHAVE_ENVIRONMENTS = kafka orderer orderer-1-kafka-1 orderer-1-kafka-3
BEHAVE_ENVIRONMENT_TARGETS = $(patsubst %,bddtests/environments/%, $(BEHAVE_ENVIRONMENTS))
.PHONY: behave-environments $(BEHAVE_ENVIRONMENT_TARGETS)
behave-environments: $(BEHAVE_ENVIRONMENT_TARGETS)
$(BEHAVE_ENVIRONMENT_TARGETS):
@docker-compose --file $@/docker-compose.yml build
behave-deps: docker peer build/bin/block-listener behave-environments
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) hyperledger/fabric-buildenv:$(DOCKER_TAG) ./scripts/golinter.sh
%/chaintool: Makefile
@echo "Installing chaintool"
@mkdir -p $(@D)
curl -L $(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 \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.$(@F))
@touch $@
build/bin:
mkdir -p $@
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 \
hyperledger/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 -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 \
peer/core.yaml \
build/msp-sampleconfig.tar.bz2 \
common/configtx/tool/configtx.yaml
build/image/orderer/payload: build/docker/bin/orderer \
build/msp-sampleconfig.tar.bz2 \
orderer/orderer.yaml \
common/configtx/tool/configtx.yaml
build/image/buildenv/payload: build/gotools.tar.bz2 \
build/docker/gotools/bin/protoc-gen-go
build/image/testenv/payload: build/docker/bin/orderer \
orderer/orderer.yaml \
common/configtx/tool/configtx.yaml \
build/docker/bin/peer \
peer/core.yaml \
build/msp-sampleconfig.tar.bz2 \
images/testenv/install-softhsm2.sh
build/image/zookeeper/payload: images/zookeeper/docker-entrypoint.sh
build/image/kafka/payload: images/kafka/docker-entrypoint.sh \
images/kafka/kafka-run-class.sh
build/image/couchdb/payload: images/couchdb/docker-entrypoint.sh \
images/couchdb/local.ini \
images/couchdb/vm.args
build/image/%/payload:
mkdir -p $@
cp $^ $@
.PRECIOUS: build/image/%/Dockerfile
build/image/%/Dockerfile: images/%/Dockerfile.in
@cat $< \
| 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 $(PROJECT_NAME)-$(TARGET) $(@D)
docker tag $(PROJECT_NAME)-$(TARGET) $(PROJECT_NAME)-$(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/javashim.tar.bz2: $(JAVASHIM_DEPS)
build/protos.tar.bz2: $(PROTOS)
build/msp-sampleconfig.tar.bz2: $(MSP_SAMPLECONFIG)
build/%.tar.bz2:
@echo "Creating $@"
@tar -jc $^ > $@
.PHONY: protos
protos: buildenv
@$(DRUN) hyperledger/fabric-buildenv:$(DOCKER_TAG) ./scripts/compile_protos.sh
%-docker-clean:
$(eval TARGET = ${patsubst %-docker-clean,%,${@}})
-docker images -q $(PROJECT_NAME)-$(TARGET) | xargs -I '{}' docker rmi -f '{}'
-@rm -rf build/image/$(TARGET) ||:
docker-clean: $(patsubst %,%-docker-clean, $(IMAGES))
.PHONY: clean
clean: docker-clean
-@rm -rf build ||:
.PHONY: dist-clean
dist-clean: clean gotools-clean
-@rm -rf /var/hyperledger/* ||: