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