github.com/bestbeforetoday/fabric-ca@v2.0.0-alpha+incompatible/Makefile (about) 1 # Copyright IBM Corp All Rights Reserved. 2 # Copyright London Stock Exchange Group All Rights Reserved. 3 # 4 # SPDX-License-Identifier: Apache-2.0 5 # 6 # ------------------------------------------------------------- 7 # This makefile defines the following targets 8 # 9 # - all (default) - builds all targets and runs all tests 10 # - license - check all go files for license headers 11 # - fabric-ca-server - builds the fabric-ca-server executable 12 # - fabric-ca-client - builds the fabric-ca-client executable 13 # - unit-tests - runs the go-test based unit tests 14 # - checks - runs all check conditions (license, format, imports, lint and vet) 15 # - docker[-clean] - builds/cleans the fabric-ca docker image 16 # - docker-fvt[-clean] - builds/cleans the fabric-ca functional verification testing image 17 # - bench - Runs benchmarks in all the packages and stores the results in /tmp/bench.results 18 # - bench-cpu - Runs the benchmarks in the specified package with cpu profiling 19 # - bench-mem - Runs the benchmarks in the specified package with memory profiling 20 # - bench-clean - Removes all benchmark related files 21 # - benchcmp - Compares benchmarks results of current and previous release 22 # - release - builds fabric-ca-client binary for the host platform. Binary built with this target will not support pkcs11 23 # - release-all - builds fabric-ca-client binary for all target platforms. Binaries built with this target will not support pkcs11 24 # - dist - builds release package for the host platform 25 # - dist-all - builds release packages for all target platforms 26 # - clean - cleans the build area 27 # - release-clean - cleans the binaries for all target platforms 28 # - dist-clean - cleans release packages for all target platforms 29 # - clean-all - cleans the build area and release packages 30 # - docker-thirdparty - pulls thirdparty images (postgres) 31 32 PROJECT_NAME = fabric-ca 33 ALPINE_VER ?= 3.9 34 DEBIAN_VER ?= stretch 35 BASE_VERSION = 2.0.0-alpha 36 PREV_VERSION = 1.4.0 37 IS_RELEASE = true 38 39 ARCH=$(shell go env GOARCH) 40 MARCH=$(shell go env GOOS)-$(shell go env GOARCH) 41 STABLE_TAG ?= $(ARCH)-$(BASE_VERSION)-stable 42 43 ifneq ($(IS_RELEASE),true) 44 EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD) 45 PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION) 46 FABRIC_TAG ?= latest 47 else 48 PROJECT_VERSION=$(BASE_VERSION) 49 FABRIC_TAG ?= $(ARCH)-$(BASE_VERSION) 50 endif 51 52 ifeq ($(ARCH),s390x) 53 PG_VER=9.6 54 else 55 PG_VER=9.5 56 endif 57 58 BASEIMAGE_RELEASE = 0.4.15 59 PKGNAME = github.com/hyperledger/$(PROJECT_NAME) 60 61 METADATA_VAR = Version=$(PROJECT_VERSION) 62 63 GO_VER = $(shell grep "GO_VER" ci.properties |cut -d'=' -f2-) 64 GO_SOURCE := $(shell find . -name '*.go') 65 GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/lib/metadata.%,$(METADATA_VAR)) 66 export GO_LDFLAGS 67 68 IMAGES = $(PROJECT_NAME) 69 FVTIMAGE = $(PROJECT_NAME)-fvt 70 71 RELEASE_PLATFORMS = linux-amd64 darwin-amd64 linux-ppc64le linux-s390x windows-amd64 72 RELEASE_PKGS = fabric-ca-client 73 74 path-map.fabric-ca-client := cmd/fabric-ca-client 75 path-map.fabric-ca-server := cmd/fabric-ca-server 76 77 include docker-env.mk 78 79 all: rename docker unit-tests 80 81 rename: .FORCE 82 @scripts/rename-repo 83 84 docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES)) 85 86 docker-fvt: $(patsubst %,build/image/%/$(DUMMY), $(FVTIMAGE)) 87 88 # should be removed once CI scripts are updated 89 docker-all: docker 90 91 # should be removed once CI scripts are updated 92 docker-fabric-ca: docker 93 94 changelog: 95 ./scripts/changelog.sh v$(PREV_VERSION) HEAD v$(BASE_VERSION) 96 97 checks: license vet lint format imports 98 99 license: .FORCE 100 @scripts/check_license 101 102 format: .FORCE 103 @scripts/check_format 104 105 imports: .FORCE 106 @scripts/check_imports 107 108 lint: .FORCE 109 @scripts/check_lint 110 111 vet: .FORCE 112 @scripts/check_vet 113 114 docs: fabric-ca-client fabric-ca-server 115 @scripts/regenDocs 116 117 fabric-ca-client: bin/fabric-ca-client 118 fabric-ca-server: bin/fabric-ca-server 119 120 bin/%: $(GO_SOURCE) 121 @echo "Building ${@F} in bin directory ..." 122 @mkdir -p bin && go build -o bin/${@F} -tags "pkcs11" -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(path-map.${@F}) 123 @echo "Built bin/${@F}" 124 125 build/image/fabric-ca/$(DUMMY): 126 @mkdir -p $(@D) 127 $(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}}) 128 @echo "Docker: building $(TARGET) image" 129 $(DBUILD) -f images/$(TARGET)/Dockerfile \ 130 --build-arg GO_VER=${GO_VER} \ 131 --build-arg GO_TAGS=pkcs11 \ 132 --build-arg GO_LDFLAGS="${DOCKER_GO_LDFLAGS}" \ 133 --build-arg ALPINE_VER=${ALPINE_VER} \ 134 -t $(BASE_DOCKER_NS)/$(TARGET) . 135 docker tag $(BASE_DOCKER_NS)/$(TARGET) \ 136 $(DOCKER_NS)/$(TARGET):$(BASE_VERSION) 137 docker tag $(BASE_DOCKER_NS)/$(TARGET) \ 138 $(DOCKER_NS)/$(TARGET):$(DOCKER_TAG) 139 @touch $@ 140 141 build/image/fabric-ca-fvt/$(DUMMY): 142 @mkdir -p $(@D) 143 $(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}}) 144 @echo "Docker: building $(TARGET) image" 145 $(DBUILD) -f images/$(TARGET)/Dockerfile \ 146 --build-arg BASEIMAGE_RELEASE=${BASEIMAGE_RELEASE} \ 147 --build-arg GO_TAGS=pkcs11 \ 148 --build-arg GO_LDFLAGS="${DOCKER_GO_LDFLAGS}" \ 149 --build-arg PG_VER=${PG_VER} \ 150 -t $(BASE_DOCKER_NS)/$(TARGET) . 151 @touch $@ 152 153 154 all-tests: checks fabric-ca-server fabric-ca-client 155 @scripts/run_unit_tests 156 @scripts/run_integration_tests 157 158 unit-tests: fabric-ca-server fabric-ca-client 159 @scripts/run_unit_tests 160 161 unit-test: unit-tests 162 163 int-tests: checks fabric-ca-server fabric-ca-client 164 @scripts/run_integration_tests 165 166 # Runs benchmarks in all the packages and stores the benchmarks in /tmp/bench.results 167 bench: checks fabric-ca-server fabric-ca-client 168 @scripts/run_benchmarks 169 170 # Runs benchmarks in the specified package with cpu profiling 171 # e.g. make bench-cpu pkg=github.com/hyperledger/fabric-ca/lib 172 bench-cpu: checks fabric-ca-server fabric-ca-client 173 @scripts/run_benchmarks -C -P $(pkg) 174 175 # Runs benchmarks in the specified package with memory profiling 176 # e.g. make bench-mem pkg=github.com/hyperledger/fabric-ca/lib 177 bench-mem: checks fabric-ca-server fabric-ca-client 178 @scripts/run_benchmarks -M -P $(pkg) 179 180 # e.g. make benchcmp prev_rel=v1.0.0 181 benchcmp: guard-prev_rel bench 182 @scripts/compare_benchmarks $(prev_rel) 183 184 guard-%: 185 @if [ "${${*}}" = "" ]; then \ 186 echo "Environment variable $* not set"; \ 187 exit 1; \ 188 fi 189 190 191 # Removes all benchmark related files (bench, bench-cpu, bench-mem and *.test) 192 bench-clean: 193 @scripts/run_benchmarks -R 194 195 container-tests: docker 196 197 load-test: docker-clean docker-fvt 198 @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 199 @test/fabric-ca-load-tester/runLoad.sh -B 200 @docker kill loadTest 201 202 ci-tests: all-tests docs fvt-tests 203 204 fvt-tests: docker-clean docker-fvt 205 @docker run -v $(shell pwd):/opt/gopath/src/github.com/hyperledger/fabric-ca ${DOCKER_NS}/fabric-ca-fvt 206 207 %-docker-clean: 208 $(eval TARGET = ${patsubst %-docker-clean,%,${@}}) 209 -docker images -q $(DOCKER_NS)/$(TARGET):latest | xargs -I '{}' docker rmi -f '{}' 210 -docker images -q $(NEXUS_URL)/*:$(STABLE_TAG) | xargs -I '{}' docker rmi -f '{}' 211 -@rm -rf build/image/$(TARGET) ||: 212 213 docker-clean: $(patsubst %,%-docker-clean, $(IMAGES) $(PROJECT_NAME)-fvt) 214 @rm -rf build/docker/bin/* ||: 215 216 native: fabric-ca-client fabric-ca-server 217 218 release: $(patsubst %,release/%, $(MARCH)) 219 release-all: $(patsubst %,release/%, $(RELEASE_PLATFORMS)) 220 221 release/windows-amd64: GOOS=windows 222 release/windows-amd64: CC=/usr/bin/x86_64-w64-mingw32-gcc 223 release/windows-amd64: GO_TAGS+= caclient 224 release/windows-amd64: $(patsubst %,release/windows-amd64/bin/%, $(RELEASE_PKGS)) 225 226 release/darwin-amd64: GOOS=darwin 227 release/darwin-amd64: CC=/usr/bin/clang 228 release/darwin-amd64: GO_TAGS+= caclient 229 release/darwin-amd64: $(patsubst %,release/darwin-amd64/bin/%, $(RELEASE_PKGS)) 230 231 release/linux-amd64: GOOS=linux 232 release/linux-amd64: GO_TAGS+= caclient 233 release/linux-amd64: $(patsubst %,release/linux-amd64/bin/%, $(RELEASE_PKGS)) 234 235 release/%-amd64: GOARCH=amd64 236 237 release/linux-%: GOOS=linux 238 239 release/linux-ppc64le: GOARCH=ppc64le 240 release/linux-ppc64le: GO_TAGS+= caclient 241 release/linux-ppc64le: CC=/usr/bin/powerpc64le-linux-gnu-gcc 242 release/linux-ppc64le: $(patsubst %,release/linux-ppc64le/bin/%, $(RELEASE_PKGS)) 243 244 release/linux-s390x: GOARCH=s390x 245 release/linux-s390x: GO_TAGS+= caclient 246 release/linux-s390x: $(patsubst %,release/linux-s390x/bin/%, $(RELEASE_PKGS)) 247 248 release/%/bin/fabric-ca-client: $(GO_SOURCE) 249 @echo "Building $@ for $(GOOS)-$(GOARCH)" 250 mkdir -p $(@D) 251 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(abspath $@) -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(path-map.$(@F)) 252 253 # Pull thirdparty docker images 254 # Currently the target is available but unused. If you are implementing a new 255 # test using the ifrit DB runners, you must add the docker-thirdparty target 256 # to the test target you are running i.e. (unit-tests, int-tests, all-tests). 257 # Note: There is no MySQL image for s390x, so you must take this into account. 258 # Integration tests are run on x86, unit tests on s390x and x86. 259 .PHONY: docker-thirdparty 260 docker-thirdparty: 261 docker pull postgres:9.6 262 docker pull mysql:5.7 263 264 .PHONY: dist 265 dist: dist-clean release 266 cd release/$(MARCH) && tar -czvf hyperledger-fabric-ca-$(MARCH).$(PROJECT_VERSION).tar.gz * 267 dist-all: dist-clean release-all $(patsubst %,dist/%, $(RELEASE_PLATFORMS)) 268 dist/windows-amd64: 269 cd release/windows-amd64 && tar -czvf hyperledger-fabric-ca-windows-amd64.$(PROJECT_VERSION).tar.gz * 270 dist/darwin-amd64: 271 cd release/darwin-amd64 && tar -czvf hyperledger-fabric-ca-darwin-amd64.$(PROJECT_VERSION).tar.gz * 272 dist/linux-amd64: 273 cd release/linux-amd64 && tar -czvf hyperledger-fabric-ca-linux-amd64.$(PROJECT_VERSION).tar.gz * 274 dist/linux-ppc64le: 275 cd release/linux-ppc64le && tar -czvf hyperledger-fabric-ca-linux-ppc64le.$(PROJECT_VERSION).tar.gz * 276 dist/linux-s390x: 277 cd release/linux-s390x && tar -czvf hyperledger-fabric-ca-linux-s390x.$(PROJECT_VERSION).tar.gz * 278 279 .PHONY: clean 280 clean: docker-clean release-clean 281 -@rm -rf build bin ||: 282 283 .PHONY: clean-all 284 clean-all: clean dist-clean 285 286 %-release-clean: 287 $(eval TARGET = ${patsubst %-release-clean,%,${@}}) 288 -@rm -rf release/$(TARGET) 289 release-clean: $(patsubst %,%-release-clean, $(RELEASE_PLATFORMS)) 290 291 .PHONY: dist-clean 292 dist-clean: 293 -@rm -rf release/windows-amd64/hyperledger-fabric-ca-windows-amd64.$(PROJECT_VERSION).tar.gz ||: 294 -@rm -rf release/darwin-amd64/hyperledger-fabric-ca-darwin-amd64.$(PROJECT_VERSION).tar.gz ||: 295 -@rm -rf release/linux-amd64/hyperledger-fabric-ca-linux-amd64.$(PROJECT_VERSION).tar.gz ||: 296 -@rm -rf release/linux-ppc64le/hyperledger-fabric-ca-linux-ppc64le.$(PROJECT_VERSION).tar.gz ||: 297 -@rm -rf release/linux-s390x/hyperledger-fabric-ca-linux-s390x.$(PROJECT_VERSION).tar.gz ||: 298 299 .FORCE: