forked from hyperledger/fabric-ca
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
306 lines (240 loc) · 10.6 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
# 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
# - license - check all go files for license headers
# - fabric-ca-server - builds the fabric-ca-server executable
# - fabric-ca-client - builds the fabric-ca-client executable
# - unit-tests - runs the go-test based unit tests
# - checks - runs all check conditions (license, format, imports, lint and vet)
# - docker[-clean] - builds/cleans the fabric-ca docker image
# - docker-fvt[-clean] - builds/cleans the fabric-ca functional verification testing image
# - bench - Runs benchmarks in all the packages and stores the results in /tmp/bench.results
# - bench-cpu - Runs the benchmarks in the specified package with cpu profiling
# - bench-mem - Runs the benchmarks in the specified package with memory profiling
# - bench-clean - Removes all benchmark related files
# - benchcmp - Compares benchmarks results of current and previous release
# - release - builds fabric-ca-client binary for the host platform. Binary built with this target will not support pkcs11
# - release-all - builds fabric-ca-client binary for all target platforms. Binaries built with this target will not support pkcs11
# - dist - builds release package for the host platform
# - dist-all - builds release packages for all target platforms
# - clean - cleans the build area
# - release-clean - cleans the binaries for all target platforms
# - dist-clean - cleans release packages for all target platforms
# - clean-all - cleans the build area and release packages
# - docker-thirdparty - pulls thirdparty images (postgres)
# - gotools - Installs go tools, such as: golint, goimports, gocov
PROJECT_NAME = fabric-ca
ALPINE_VER ?= 3.10
DEBIAN_VER ?= stretch
BASE_VERSION = 2.0.0
PREV_VERSION = 2.0.0-alpha
IS_RELEASE = false
ARCH=$(shell go env GOARCH)
MARCH=$(shell go env GOOS)-$(shell go env GOARCH)
STABLE_TAG ?= $(ARCH)-$(BASE_VERSION)-stable
ifneq ($(IS_RELEASE),true)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION)
FABRIC_TAG ?= latest
else
PROJECT_VERSION=$(BASE_VERSION)
FABRIC_TAG ?= $(ARCH)-$(BASE_VERSION)
endif
ifeq ($(ARCH),s390x)
PG_VER=11
else
PG_VER=11
endif
PKGNAME = github.com/hyperledger/$(PROJECT_NAME)
METADATA_VAR = Version=$(PROJECT_VERSION)
# hardcode until release jobs migrate to new CI
# GO_VER = $(shell grep "GO_VER" ci.properties | cut -d '=' -f2-)
GO_VER = 1.13.4
GO_SOURCE := $(shell find . -name '*.go')
GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/lib/metadata.%,$(METADATA_VAR))
export GO_LDFLAGS
IMAGES = $(PROJECT_NAME)
FVTIMAGE = $(PROJECT_NAME)-fvt
RELEASE_PLATFORMS = linux-amd64 darwin-amd64 linux-ppc64le linux-s390x windows-amd64
RELEASE_PKGS = fabric-ca-client
TOOLS = build/tools
path-map.fabric-ca-client := cmd/fabric-ca-client
path-map.fabric-ca-server := cmd/fabric-ca-server
include docker-env.mk
include gotools.mk
all: rename docker unit-tests
rename: .FORCE
@scripts/rename-repo
docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
docker-fvt: $(patsubst %,build/image/%/$(DUMMY), $(FVTIMAGE))
# should be removed once CI scripts are updated
docker-all: docker
# should be removed once CI scripts are updated
docker-fabric-ca: docker
changelog:
./scripts/changelog.sh v$(PREV_VERSION) HEAD v$(BASE_VERSION)
checks: license vet lint format imports
license: .FORCE
@scripts/check_license
format: .FORCE
@scripts/check_format
imports: $(TOOLS)/goimports
@scripts/check_imports
lint: $(TOOLS)/golint
@scripts/check_lint
vet: .FORCE
@scripts/check_vet
docs: fabric-ca-client fabric-ca-server
@scripts/regenDocs
fabric-ca-client: bin/fabric-ca-client
fabric-ca-server: bin/fabric-ca-server
bin/%: $(GO_SOURCE)
@echo "Building ${@F} in bin directory ..."
@mkdir -p bin && go build -o bin/${@F} -tags "pkcs11" -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(path-map.${@F})
@echo "Built bin/${@F}"
build/image/fabric-ca/$(DUMMY):
@mkdir -p $(@D)
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
@echo "Docker: building $(TARGET) image"
$(DBUILD) -f images/$(TARGET)/Dockerfile \
--build-arg GO_VER=${GO_VER} \
--build-arg GO_TAGS=pkcs11 \
--build-arg GO_LDFLAGS="${DOCKER_GO_LDFLAGS}" \
--build-arg ALPINE_VER=${ALPINE_VER} \
-t $(BASE_DOCKER_NS)/$(TARGET) .
docker tag $(BASE_DOCKER_NS)/$(TARGET) \
$(DOCKER_NS)/$(TARGET):$(BASE_VERSION)
docker tag $(BASE_DOCKER_NS)/$(TARGET) \
$(DOCKER_NS)/$(TARGET):$(DOCKER_TAG)
@touch $@
build/image/fabric-ca-fvt/$(DUMMY):
@mkdir -p $(@D)
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
@echo "Docker: building $(TARGET) image"
$(DBUILD) -f images/$(TARGET)/Dockerfile \
--build-arg GO_VER=${GO_VER} \
--build-arg GO_TAGS=pkcs11 \
--build-arg GO_LDFLAGS="${DOCKER_GO_LDFLAGS}" \
--build-arg PG_VER=${PG_VER} \
-t $(BASE_DOCKER_NS)/$(TARGET) .
@touch $@
all-tests: gotools fabric-ca-server fabric-ca-client
@scripts/run_unit_tests
@scripts/run_integration_tests
unit-tests: gotools fabric-ca-server fabric-ca-client
@scripts/run_unit_tests
unit-test: unit-tests
int-tests: gotools fabric-ca-server fabric-ca-client
@scripts/run_integration_tests
# Runs benchmarks in all the packages and stores the benchmarks in /tmp/bench.results
bench: $(TOOLS)/benchcmp fabric-ca-server fabric-ca-client
@scripts/run_benchmarks
# Runs benchmarks in the specified package with cpu profiling
# e.g. make bench-cpu pkg=github.com/hyperledger/fabric-ca/lib
bench-cpu: $(TOOLS)/benchcmp fabric-ca-server fabric-ca-client
@scripts/run_benchmarks -C -P $(pkg)
# Runs benchmarks in the specified package with memory profiling
# e.g. make bench-mem pkg=github.com/hyperledger/fabric-ca/lib
bench-mem: $(TOOLS)/benchcmp fabric-ca-server fabric-ca-client
@scripts/run_benchmarks -M -P $(pkg)
# e.g. make benchcmp prev_rel=v1.0.0
benchcmp: $(TOOLS)/benchcmp guard-prev_rel bench
@scripts/compare_benchmarks $(prev_rel)
guard-%:
@if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
# Removes all benchmark related files (bench, bench-cpu, bench-mem and *.test)
bench-clean: $(TOOLS)/benchcmp
@scripts/run_benchmarks -R
container-tests: docker
load-test: docker-clean docker-fvt
@docker run -p 8888:8888 -p 8054:8054 -v $(shell pwd):/opt/gopath/src/github.com/hyperledger/fabric-ca -e FABRIC_CA_SERVER_PROFILE_PORT=8054 --name loadTest -td hyperledger/fabric-ca-fvt test/fabric-ca-load-tester/launchServer.sh 3
@test/fabric-ca-load-tester/runLoad.sh -B
@docker kill loadTest
ci-tests: all-tests docs fvt-tests
fvt-tests: docker-clean docker-fvt
@docker run -v $(shell pwd):/opt/gopath/src/github.com/hyperledger/fabric-ca ${DOCKER_NS}/fabric-ca-fvt
%-docker-clean:
$(eval TARGET = ${patsubst %-docker-clean,%,${@}})
-docker images -q $(DOCKER_NS)/$(TARGET):latest | xargs -I '{}' docker rmi -f '{}'
-docker images -q $(NEXUS_URL)/*:$(STABLE_TAG) | xargs -I '{}' docker rmi -f '{}'
-@rm -rf build/image/$(TARGET) ||:
docker-clean: $(patsubst %,%-docker-clean, $(IMAGES) $(PROJECT_NAME)-fvt)
@rm -rf build/docker/bin/* ||:
native: fabric-ca-client fabric-ca-server
release: $(patsubst %,release/%, $(MARCH))
release-all: $(patsubst %,release/%, $(RELEASE_PLATFORMS))
release/windows-amd64: GOOS=windows
release/windows-amd64: CC=/usr/bin/x86_64-w64-mingw32-gcc
release/windows-amd64: GO_TAGS+= caclient
release/windows-amd64: $(patsubst %,release/windows-amd64/bin/%, $(RELEASE_PKGS))
release/darwin-amd64: GOOS=darwin
release/darwin-amd64: CC=/usr/bin/clang
release/darwin-amd64: GO_TAGS+= caclient
release/darwin-amd64: $(patsubst %,release/darwin-amd64/bin/%, $(RELEASE_PKGS))
release/linux-amd64: GOOS=linux
release/linux-amd64: GO_TAGS+= caclient
release/linux-amd64: $(patsubst %,release/linux-amd64/bin/%, $(RELEASE_PKGS))
release/%-amd64: GOARCH=amd64
release/linux-%: GOOS=linux
release/linux-ppc64le: GOARCH=ppc64le
release/linux-ppc64le: GO_TAGS+= caclient
release/linux-ppc64le: CC=/usr/bin/powerpc64le-linux-gnu-gcc
release/linux-ppc64le: $(patsubst %,release/linux-ppc64le/bin/%, $(RELEASE_PKGS))
release/linux-s390x: GOARCH=s390x
release/linux-s390x: GO_TAGS+= caclient
release/linux-s390x: $(patsubst %,release/linux-s390x/bin/%, $(RELEASE_PKGS))
release/%/bin/fabric-ca-client: $(GO_SOURCE)
@echo "Building $@ for $(GOOS)-$(GOARCH)"
mkdir -p $(@D)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(path-map.$(@F))
# Pull thirdparty docker images
# Currently the target is available but unused. If you are implementing a new
# test using the ifrit DB runners, you must add the docker-thirdparty target
# to the test target you are running i.e. (unit-tests, int-tests, all-tests).
.PHONY: docker-thirdparty
docker-thirdparty:
docker pull postgres:9.6
docker pull mysql:5.7
.PHONY: dist
dist: dist-clean release
cd release/$(MARCH) && tar -czvf hyperledger-fabric-ca-$(MARCH).$(PROJECT_VERSION).tar.gz *
dist-all: dist-clean release-all $(patsubst %,dist/%, $(RELEASE_PLATFORMS))
dist/windows-amd64:
cd release/windows-amd64 && tar -czvf hyperledger-fabric-ca-windows-amd64.$(PROJECT_VERSION).tar.gz *
dist/darwin-amd64:
cd release/darwin-amd64 && tar -czvf hyperledger-fabric-ca-darwin-amd64.$(PROJECT_VERSION).tar.gz *
dist/linux-amd64:
cd release/linux-amd64 && tar -czvf hyperledger-fabric-ca-linux-amd64.$(PROJECT_VERSION).tar.gz *
dist/linux-ppc64le:
cd release/linux-ppc64le && tar -czvf hyperledger-fabric-ca-linux-ppc64le.$(PROJECT_VERSION).tar.gz *
dist/linux-s390x:
cd release/linux-s390x && tar -czvf hyperledger-fabric-ca-linux-s390x.$(PROJECT_VERSION).tar.gz *
.PHONY: clean
clean: docker-clean release-clean
-@rm -rf build bin ||:
.PHONY: clean-all
clean-all: clean dist-clean
%-release-clean:
$(eval TARGET = ${patsubst %-release-clean,%,${@}})
-@rm -rf release/$(TARGET)
release-clean: $(patsubst %,%-release-clean, $(RELEASE_PLATFORMS))
.PHONY: dist-clean
dist-clean:
-@rm -rf release/windows-amd64/hyperledger-fabric-ca-windows-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/darwin-amd64/hyperledger-fabric-ca-darwin-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-amd64/hyperledger-fabric-ca-linux-amd64.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-ppc64le/hyperledger-fabric-ca-linux-ppc64le.$(PROJECT_VERSION).tar.gz ||:
-@rm -rf release/linux-s390x/hyperledger-fabric-ca-linux-s390x.$(PROJECT_VERSION).tar.gz ||:
.FORCE:
generate-metrics-doc:
@echo "Generating metrics reference documentation..."
@./scripts/metrics_doc.sh