forked from hyperledger/fabric-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
274 lines (214 loc) · 7.56 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
#
# Copyright 2020 IBM All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
go_dir := $(base_dir)/pkg
node_dir := $(base_dir)/node
java_dir := $(base_dir)/java
scenario_dir := $(base_dir)/scenario
go_bin_dir := $(shell go env GOPATH)/bin
# PEER_IMAGE_PULL is where to pull peer image from, it can be set by external env variable
# In fabric-gateway main branch it should reflect the location of the latest fabric main branch image
PEER_IMAGE_PULL ?= hyperledger-fabric.jfrog.io/fabric-peer:amd64-2.5-stable
# PEER_IMAGE_TAG is what to tag the pulled peer image as, it will also be used in docker-compose to reference the image
# In fabric-gateway main branch this version tag should correspond to the version in the forthcoming Fabric development
# branch.
export PEER_IMAGE_TAG ?= 2.5
# TWO_DIGIT_VERSION specifies which chaincode images to pull, they will be tagged to be consistent with PEER_IMAGE_TAG
# In fabric-gateway main branch it should typically be the latest released chaincode version available in dockerhub.
TWO_DIGIT_VERSION ?= 2.5
export SOFTHSM2_CONF ?= $(base_dir)/softhsm2.conf
TMPDIR ?= /tmp
.PHONY: default
default:
@echo 'No default target.'
.PHONY: build
build: build-node build-java
.PHONY: build-node
build-node:
cd '$(node_dir)' && \
npm install && \
npm run build && \
rm -f fabric-gateway-dev.tgz && \
mv $$(npm pack) fabric-gateway-dev.tgz
.PHONY: build-java
build-java:
cd '$(java_dir)' && \
mvn -DskipTests install
.PHONY: unit-test
unit-test: generate lint unit-test-go unit-test-node unit-test-java
.PHONY: unit-test-go
unit-test-go:
cd '$(base_dir)' && \
go test -timeout 10s -race -coverprofile=cover.out '$(go_dir)/...'
.PHONY: unit-test-go-pkcs11
unit-test-go-pkcs11: setup-softhsm
cd '$(base_dir)' && \
go test -tags pkcs11 -timeout 10s -race -coverprofile=cover.out '$(go_dir)/...'
.PHONY: unit-test-node
unit-test-node: build-node
cd '$(node_dir)' && \
npm test
.PHONY: unit-test-java
unit-test-java:
cd '$(java_dir)' && \
mvn test
.PHONY: lint
lint: staticcheck golangci-lint
.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck -f stylish -tags=pkcs11 '$(go_dir)/...' '$(scenario_dir)/go'
.PHONY: install-golangci-lint
install-golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b '$(go_bin_dir)'
$(go_bin_dir)/golangci-lint:
$(MAKE) install-golangci-lint
.PHONY: golangci-lint
golangci-lint: $(go_bin_dir)/golangci-lint
golangci-lint run
.PHONY: scan
scan: scan-go scan-node scan-java
.PHONY: scan-go
scan-go: scan-go-govulncheck scan-go-nancy scan-go-osv-scanner
.PHONY: scan-go-govulncheck
scan-go-govulncheck:
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck -tags pkcs11 '$(go_dir)/...'
.PHONY: scan-go-nancy
scan-go-nancy:
go install github.com/sonatype-nexus-community/nancy@latest
go list -json -deps '$(go_dir)/...' | nancy sleuth
.PHONY: scan-go-osv-scanner
scan-go-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
echo "GoVersionOverride = '$$(go env GOVERSION | sed 's/^go//')'" > osv-scanner.toml
osv-scanner scan --lockfile='$(base_dir)/go.mod' || [ \( $$? -gt 1 \) -a \( $$? -lt 127 \) ]
.PHONY: scan-node
scan-node: scan-node-npm-audit scan-node-osv-scanner
.PHONY: scan-node-npm-audit
scan-node-npm-audit:
cd '$(node_dir)' && \
npm install --package-lock-only && \
npm audit --omit=dev
.PHONY: scan-node-osv-scanner
scan-node-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
cd '$(node_dir)' && \
npm install && \
npm run sbom && \
osv-scanner scan --sbom=sbom.json
.PHONY: scan-java
scan-java: scan-java-dependency-check scan-java-osv-scanner
.PHONY: scan-java-dependency-check
scan-java-dependency-check:
cd '$(java_dir)' && \
mvn dependency-check:check -P owasp
.PHONY: scan-java-osv-scanner
scan-java-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
osv-scanner scan --lockfile='$(java_dir)/pom.xml'
.PHONY: generate
generate:
go install go.uber.org/mock/mockgen@latest
go generate '$(go_dir)/...'
.PHONY: vendor-chaincode
vendor-chaincode:
cd '$(scenario_dir)/fixtures/chaincode/golang/basic' && \
GO111MODULE=on go mod vendor
cd '$(scenario_dir)/fixtures/chaincode/golang/private' && \
GO111MODULE=on go mod vendor
.PHONY: scenario-test-go
scenario-test-go: vendor-chaincode fabric-ca-client setup-softhsm
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v -args '$(scenario_dir)/features/'
.PHONY: scenario-test-go-no-hsm
scenario-test-go-no-hsm: vendor-chaincode
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v --godog.tags='~@hsm' -args '$(scenario_dir)/features/'
.PHONY: scenario-test-node
scenario-test-node: vendor-chaincode build-node fabric-ca-client setup-softhsm
cd '$(scenario_dir)/node' && \
rm -rf package-lock.json node_modules && \
npm install && \
npm test
.PHONY: scenario-test-node-no-hsm
scenario-test-node-no-hsm: vendor-chaincode build-node fabric-ca-client
cd '$(scenario_dir)/node' && \
rm -rf package-lock.json node_modules && \
npm install && \
npm run test:no-hsm
.PHONY: scenario-test-java
scenario-test-java: vendor-chaincode
cd '$(java_dir)' && \
mvn -Dmaven.javadoc.skip=true -DskipUnitTests verify
.PHONY: scenario-test
scenario-test: scenario-test-go scenario-test-node scenario-test-java
.PHONY: scenario-test-no-hsm
scenario-test-no-hsm: scenario-test-go-no-hsm scenario-test-node-no-hsm scenario-test-java
.PHONY: fabric-ca-client
fabric-ca-client:
go install -tags pkcs11 github.com/hyperledger/fabric-ca/cmd/fabric-ca-client@latest
.PHONY: setup-softhsm
setup-softhsm:
mkdir -p '$(TMPDIR)/softhsm'
echo 'directories.tokendir = $(TMPDIR)/softhsm' > '$(SOFTHSM2_CONF)'
softhsm2-util --init-token --slot 0 --label 'ForFabric' --pin 98765432 --so-pin 1234 || true
.PHONY: generate-docs
generate-docs:
pip install --quiet --upgrade --requirement '$(base_dir)/requirements.txt'
cd '$(base_dir)' && TZ=UTC mkdocs build --strict
.PHONY: generate-docs-node
generate-docs-node:
cd '$(node_dir)' && \
npm install && \
npm run generate-apidoc
.PHONY: generate-docs-java
generate-docs-java:
cd '$(java_dir)' && \
mvn javadoc:javadoc
.PHONY: test
test: shellcheck unit-test scenario-test
.PHONY: all
all: test
.PHONY: pull-latest-peer
pull-latest-peer:
docker pull '$(PEER_IMAGE_PULL)'
docker tag '$(PEER_IMAGE_PULL)' 'hyperledger/fabric-peer:$(PEER_IMAGE_TAG)'
# also need to retag the following images for the chaincode builder
for IMAGE in baseos ccenv javaenv nodeenv; do \
docker pull "hyperledger/fabric-$${IMAGE}:$(TWO_DIGIT_VERSION)"; \
docker tag "hyperledger/fabric-$${IMAGE}:$(TWO_DIGIT_VERSION)" "hyperledger/fabric-$${IMAGE}:$(PEER_IMAGE_TAG)"; \
done
.PHONY: clean
clean: clean-generated clean-node clean-java clean-docs
.PHONY: clean-node
clean-node:
rm -rf '$(node_dir)/package-lock.json' '$(node_dir)/node_modules'
.PHONY: clean-java
clean-java:
cd '$(java_dir)' && mvn clean
.PHONY: clean-generated
clean-generated:
find '$(go_dir)' -name '*_mock_test.go' -delete
.PHONY: clean-docs
clean-docs:
rm -rf '$(base_dir)/site'
rm -rf '$(node_dir)/apidocs'
rm -rf '$(java_dir)/target/site/apidocs'
.PHONY: shellcheck
shellcheck:
cd '$(base_dir)' && ./scripts/shellcheck.sh
.PHONY: format
format: format-go format-node format-java
.PHONY: format-go
format-go:
cd '$(base_dir)' && gofmt -l -s -w .
.PHONY: format-node
format-node:
cd '$(node_dir)' && npm run format:fix
.PHONY: format-java
format-java:
cd '$(java_dir)' && mvn spotless:apply