-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.fabric.mk
451 lines (396 loc) · 13.8 KB
/
common.fabric.mk
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
446
447
448
449
450
451
# This makefile provides targets for local fabric networks. It's meant to
# be re-usable across projects.
include ${PROJECT_REL_DIR}/common.mk
# name of the chaincode
CC_NAME ?= com_luthersystems_chaincode_substrate01
# name of the chaincode package to install
CC_PKG_NAME ?= com_luthersystems_chaincode_substrate01
CC_FILE=${CC_PKG_NAME}-${CC_VERSION}.tar.gz
CC_PATH=chaincodes/${CC_FILE}
# path within cli docker container of chaincode
CC_MOUNT_PATH=/chaincodes/${CC_FILE}
SUBSTRATE_VERSION ?= latest
PHYLUM_VERSION_FILE=./build/phylum_version
# DOCKER_CHOWN_USER differs from CHOWN_USER because DOCKER_CHOWN_USER needs to
# use identifier numbers (insider docker there is no user defined with the
# proper name).
DOCKER_CHOWN_USER ?= $(shell id -u ${USER}):$(shell id -g ${USER})
# NETWORK_BUILDER is the entrypoint into the NETWORK_BUILDER_IMAGE for all
# commands.
NETWORK_BUILDER_IMAGE ?= luthersystems/fabric-network-builder
NETWORK_BUILDER_TARGET ?= docker-pull/${NETWORK_BUILDER_IMAGE}\:${NETWORK_BUILDER_VERSION}
NETWORK_BUILDER=${NETWORK_BUILDER_IMAGE}:${NETWORK_BUILDER_VERSION} --chown "${DOCKER_CHOWN_USER}"
SHIROCLIENT_IMAGE ?= luthersystems/shiroclient
SHIROCLIENT_TARGET ?= docker-pull/${SHIROCLIENT_IMAGE}\:${SHIROCLIENT_VERSION}
SHIROCLIENT_FABRIC_CONFIG_BASENAME=shiroclient
SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME=shiroclient_fast
# index.gateway_name[.msp_filter]...
PHYLA_GO ?=
CHAINCODE_GO ?= ${PHYLA_GO}
PHYLA_CCAAS ?=
PHYLA ?= ${PHYLA_GO} ${PHYLA_CCAAS}
GATEWAYS ?= 1.shiroclient_gw_a.a
START_GATEWAYS=$(addprefix start-gw-,${GATEWAYS})
NOTIFY_GATEWAYS=$(addprefix notify-gw-,${GATEWAYS})
FUNCTIONAL_TEST_PHYLA=$(addprefix functional-test-phylum-,${PHYLA})
SHIRO_INIT_PHYLA=$(addprefix shiro-init-phylum-,${PHYLA})
CHANNEL ?= luther
GENERATE_OPTS ?= --domain ${FABRIC_DOMAIN} --org-count=2 --peer-count=2
FABRIC_ORG ?= org1
FABRIC_DOMAIN ?= luther.systems
FABRIC_IMAGE_NAMES=peer orderer ccenv
FABRIC_IMAGE_NS=hyperledger
FABRIC_IMAGE_FQNS=$(patsubst %,${FABRIC_IMAGE_NS}/fabric-%,${FABRIC_IMAGE_NAMES})
FABRIC_CA_IMAGE_FQN=${FABRIC_IMAGE_NS}/fabric-ca
DBMODE ?= goleveldb
FABRIC_IMAGES=$(foreach fqn,${FABRIC_IMAGE_FQNS},${fqn}\:${FABRIC_IMAGE_TAG}) \
${FABRIC_CA_IMAGE_FQN}\:${FABRIC_CA_IMAGE_TAG}
FABRIC_IMAGE_TARGETS=$(addprefix docker-pull/,${FABRIC_IMAGES})
FABRIC_DOCKER_NETWORK=byfn
DOCKER_FABRIC_OPTS ?= -e SHIROCLIENT_CLIENT_DEMO_MODE=true
.PHONY: default
default: images
@
.PHONY: images
images: ${FABRIC_IMAGE_TARGETS} ${SHIROCLIENT_TARGET} ${NETWORK_BUILDER_TARGET}
@
.PHONY: clean-chaincodes
clean-chaincodes:
rm -rf chaincodes/*.{tar.gz,id} .env
.PHONY: clean
clean: clean-chaincodes
rm -rf build
.PHONY: pristine
pristine: clean clean-generated
.PHONY: clean-generated
clean-generated:
rm -rf \
base \
channel-artifacts \
configtx.yaml \
couchdb \
crypto-config \
crypto-config.yaml \
docker-compose-cli.yaml \
docker-compose-couch.yaml \
docker-compose-e2e-template.yaml \
docker-compose-e2e.yaml \
fabric-client.yaml \
fabric-client_fast.yaml \
fabric-client_template.yaml \
shiroclient.yaml \
shiroclient_fast.yaml \
scripts
.PHONY: go-test
go-test:
go test -race -cover -v ./...
$(MAKE) functional-tests
.PHONY: functional-tests
functional-tests: ${FUNCTIONAL_TEST_PHYLA}
functional-test-phylum-%: compile-phylum-%
# NOTE: shirotester path must be relative to properly work within docker container.
go run ${PROJECT_REL_DIR}/cmd/shirotester/main.go functional-tests --verbose phylum_$*/testfixtures/*.yaml
.PHONY: generate
generate: ${NETWORK_BUILDER_TARGET}
rm -rf ./crypto-config ./channel-artifacts
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
${NETWORK_BUILDER} --channel ${CHANNEL} --force generate \
--domain=${FABRIC_DOMAIN} \
--cc-name="${CC_NAME}" \
${GENERATE_OPTS}
.PHONY: generate-template
generate-template: ${NETWORK_BUILDER_TARGET}
rm -rf ./crypto-config ./channel-artifacts
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
${NETWORK_BUILDER} --channel ${CHANNEL} --force generate \
--domain=${FABRIC_DOMAIN} \
--cc-name="${CC_NAME}" \
${GENERATE_OPTS} --template
.PHONY: generate-assets
generate-assets: channel-artifacts/genesis.block
channel-artifacts/genesis.block: ${NETWORK_BUILDER_TARGET}
rm -rf ./crypto-config ./channel-artifacts
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
${NETWORK_BUILDER} --channel ${CHANNEL} --force generate \
--domain=${FABRIC_DOMAIN} \
--cc-name="${CC_NAME}" \
${GENERATE_OPTS} --no-template
.PHONY: couchdb-up
couchdb-up: DBMODE = couchdb
couchdb-up: fnb-up gateway-up
.PHONY: up
up: generate-chaincodes .env fnb-up gateway-up
@
.PHONY: fnb-up
fnb-up: ${NETWORK_BUILDER_TARGET} ${FABRIC_IMAGE_TARGETS}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
-e CHAINCODE_LOG_LEVEL \
-e CHAINCODE_OTLP_TRACER_ENDPOINT \
${NETWORK_BUILDER} --channel ${CHANNEL} --force -s "${DBMODE}" up \
--log-spec debug \
--cc-version "${SUBSTRATE_VERSION}"
.PHONY: fnb-extend
fnb-extend: ${NETWORK_BUILDER_TARGET} ${FABRIC_IMAGE_TARGETS}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
${NETWORK_BUILDER} --channel ${CHANNEL} --force -s "${DBMODE}" extend \
--domain-name=${FABRIC_DOMAIN}
.PHONY: fnb-shell
fnb-shell: ${NETWORK_BUILDER_TARGET} ${FABRIC_IMAGE_TARGETS}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
-e CHANNEL=${CHANNEL} \
-e FABRIC_DOMAIN=${FABRIC_DOMAIN} \
-e FABRIC_DBMODE="${DBMODE}" \
--entrypoint bash \
${NETWORK_BUILDER_IMAGE}:${NETWORK_BUILDER_VERSION}
.PHONY: gateway-up
gateway-up: ${START_GATEWAYS}
start-gw-%: parts=$(subst ., ,$*)
start-gw-%: idx=$(word 1,${parts})
start-gw-%: name=$(word 2,${parts})
start-gw-%: ccname=$(word 3,${parts})
start-gw-%: filter=$(word 4,${parts})
start-gw-%: port=$$(( 8081 + ${idx} ))
start-gw-%: metrics_port=$$(( 9601 + ${idx} ))
start-gw-%: filter_args=$(if ${filter},-f ${filter})
ifdef EXPOSE_GATEWAY
start-gw-%: port_fw=-p "${port}:${port}"
endif
start-gw-%: ${SHIROCLIENT_TARGET} build/volume/msp build/volume/enroll_user
${DOCKER_RUN} -d --name ${name} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-w "/tmp/fabric" \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-e SHIROCLIENT_GATEWAY_OTLP_TRACER_ENDPOINT \
${port_fw} \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_${ccname}.yaml \
--chaincode.version ${CC_VERSION}_${ccname} \
gateway ${filter_args}
.SECONDEXPANSION:
notify-gw-%: parts=$(subst ., ,$*)
notify-gw-%: name=$(word 2,${parts})
notify-gw-%: ccname=$(word 3,${parts})
notify-gw-%: ${SHIROCLIENT_TARGET} compile-phylum-$$(ccname) build/volume/msp build/volume/enroll_user ${PHYLUM_VERSION_FILE}
${DOCKER_RUN} --rm -t \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "$(abspath build/phylum_${ccname}/phylum.zip):/tmp/phylum.zip:ro" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-w "/tmp/fabric" \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_${ccname}.yaml \
--chaincode.version ${CC_VERSION}_${ccname} \
notify -g http://${name}:8082 "$(shell cat ${PHYLUM_VERSION_FILE})"
.PHONY: couchdb-down
couchdb-down: DBMODE = couchdb
couchdb-down: gateway-down fnb-down
# oracle-up and oracle-down are declared as phony targets so they can be used
# as dependencies and ordered correctly when processing other phony targets.
.PHONY: oracle-up
.PHONY: oracle-down
.PHONY: down
down: oracle-down gateway-down fnb-down clean-chaincodes
.PHONY: fnb-down
fnb-down: ${NETWORK_BUILDER_TARGET}
-rm -f "${PHYLUM_VERSION_FILE}"
-${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
${NETWORK_BUILDER} --channel ${CHANNEL} --force -s "${DBMODE}" down
.PHONY: gateway-down
gateway-down: gw_names=$(foreach g,${GATEWAYS},$(word 2,$(subst ., ,${g})))
gateway-down:
-docker stop ${gw_names}
.PHONY: sleep-%
sleep-%:
@sleep $*
.PHONY: install
install: ${NETWORK_BUILDER_TARGET}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
${NETWORK_BUILDER} --channel ${CHANNEL} --force install \
"${CC_NAME}" \
"${CC_VERSION}" \
"${PHYLA}" \
"${CC_MOUNT_PATH}"
.PHONY: generate-chaincode
generate-chaincodes: generate-go-chaincodes generate-ccaas-chaincodes
@
.PHONY: generate-go-chaincodes
generate-go-chaincodes: ${NETWORK_BUILDER_TARGET}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
${NETWORK_BUILDER} --force generatecc \
"${CC_NAME}" \
"${CC_VERSION}" \
"${CHAINCODE_GO}" \
"${CC_MOUNT_PATH}"
.PHONY: generate-ccaas-chaincodes
generate-ccaas-chaincodes: ${NETWORK_BUILDER_TARGET}
${DOCKER_RUN} -t \
${DOCKER_IN_DOCKER_MOUNT} \
-v "${CURDIR}:${CURDIR}" \
-w "${CURDIR}" \
-e FABRIC_LOGGING_SPEC \
${NETWORK_BUILDER} --force generatecc --ccaas\
"${CC_NAME}" \
"${CC_VERSION}" \
"${PHYLA_CCAAS}" \
"${CC_MOUNT_PATH}"
.PHONY: ${PHYLUM_VERSION_FILE}
${PHYLUM_VERSION_FILE}:
date +local-%s >${PHYLUM_VERSION_FILE}
.PHONY: ${PHYLUM_VERSION_FILE}_exists
${PHYLUM_VERSION_FILE}_exists:
@test -f ${PHYLUM_VERSION_FILE}
.PHONY: init
init: ${SHIRO_INIT_PHYLA} ${NOTIFY_GATEWAYS}
shiro-init-phylum-%: ${SHIROCLIENT_TARGET} compile-phylum-% build/volume/msp build/volume/enroll_user ${PHYLUM_VERSION_FILE}
${DOCKER_RUN} -t \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "$(abspath build/phylum_$*/phylum.zip):/tmp/phylum.zip:ro" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
init "$(shell cat ${PHYLUM_VERSION_FILE})" /tmp/phylum.zip
call_cmd-%:
@echo ${DOCKER_RUN} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-e SHIROCLIENT_LOG_LEVEL \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
--phylum.version latest \
call
enable_logging-%:
./logging-pbool-ctl.sh true \
${DOCKER_RUN} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
--phylum.version latest \
call set_app_control_property
disable_logging-%:
./logging-pbool-ctl.sh false \
${DOCKER_RUN} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
--phylum.version latest \
call set_app_control_property
metadump_cmd-%:
@echo ${DOCKER_RUN} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
--phylum.version latest \
metadump
get_phyla-%:
${DOCKER_RUN} \
-v "$(abspath build/volume/msp):/tmp/msp:rw" \
-v "$(abspath build/volume/enroll_user):/tmp/state-store:rw" \
-v "${CURDIR}:/tmp/fabric:ro" \
${DOCKER_FABRIC_OPTS} \
-e ORG="${FABRIC_ORG}" \
-e DOMAIN_NAME="${FABRIC_DOMAIN}" \
-w "/tmp/fabric" \
--network ${FABRIC_DOCKER_NETWORK} \
${SHIROCLIENT_IMAGE}:${SHIROCLIENT_VERSION} -v \
--config ${SHIROCLIENT_FABRIC_CONFIG_FAST_BASENAME}_$*.yaml \
--chaincode.version ${CC_VERSION}_$* \
--phylum.version latest \
call get_phyla '{}'
build/volume/msp:
mkdir -p $@
chmod a+w $@
build/volume/enroll_user:
mkdir -p $@
chmod a+w $@
.SECONDEXPANSION:
compile-phylum-%: $$(shell find -L phylum_$$* -name "*.lisp" -not -path "*/build/*" 2>/dev/null)
mkdir -p ./build/phylum_$*
rm -rf ./build/phylum_$*/src
mkdir -p ./build/phylum_$*/src
cp $^ ./build/phylum_$*/src/
cd ./build/phylum_$*/src && ls && rm -f ./../phylum.zip && zip ./../phylum.zip $(notdir $^)
chaincodes/:
mkdir -p chaincodes/
CHAINCODE_ID_FILES := $(wildcard ./chaincodes/*.id)
.env: $(CHAINCODE_ID_FILES)
@./scripts/env.sh