github.com/silveraid/fabric-ca@v1.1.0-preview.0.20180127000700-71974f53ab08/Makefile (about) 1 # Copyright IBM Corp All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # ------------------------------------------------------------- 16 # This makefile defines the following targets 17 # 18 # - all (default) - builds all targets and runs all tests 19 # - license - check all go files for license headers 20 # - fabric-ca-server - builds the fabric-ca-server executable 21 # - fabric-ca-client - builds the fabric-ca-client executable 22 # - unit-tests - Performs checks first and runs the go-test based unit tests 23 # - checks - runs all check conditions (license, format, imports, lint and vet) 24 # - docker[-clean] - ensures all docker images are available[/cleaned] 25 # - docker-fabric-ca - build the fabric-ca docker image 26 # - bench - Runs benchmarks in all the packages and stores the results in /tmp/bench.results 27 # - bench-cpu - Runs the benchmarks in the specified package with cpu profiling 28 # - bench-mem - Runs the benchmarks in the specified package with memory profiling 29 # - bench-clean - Removes all benchmark related files 30 # - benchcmp - Compares benchmarks results of current and previous release 31 # - clean - cleans the build area 32 33 PROJECT_NAME = fabric-ca 34 BASE_VERSION = 1.1.0-beta 35 PREV_VERSION = 1.1.0-alpha 36 IS_RELEASE = false 37 38 ARCH=$(shell uname -m) 39 40 ifneq ($(IS_RELEASE),true) 41 EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD) 42 PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION) 43 FABRIC_TAG ?= $(ARCH)-$(PREV_VERSION) 44 else 45 PROJECT_VERSION=$(BASE_VERSION) 46 FABRIC_TAG ?= $(ARCH)-$(BASE_VERSION) 47 endif 48 49 ifeq ($(ARCH),s390x) 50 PGVER=9.4 51 else 52 PGVER=9.5 53 endif 54 55 BASEIMAGE_RELEASE = 0.4.5 56 PKGNAME = github.com/hyperledger/$(PROJECT_NAME) 57 58 METADATA_VAR = Version=$(PROJECT_VERSION) 59 60 GO_SOURCE := $(shell find . -name '*.go') 61 GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/lib/metadata.%,$(METADATA_VAR)) 62 export GO_LDFLAGS 63 64 IMAGES = $(PROJECT_NAME) $(PROJECT_NAME)-orderer $(PROJECT_NAME)-peer $(PROJECT_NAME)-tools 65 FVTIMAGE = $(PROJECT_NAME)-fvt 66 67 path-map.fabric-ca-client := ./cmd/fabric-ca-client 68 path-map.fabric-ca-server := ./cmd/fabric-ca-server 69 70 include docker-env.mk 71 72 all: rename docker unit-tests 73 74 rename: .FORCE 75 @scripts/rename-repo 76 77 docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES)) 78 79 docker-fabric-ca: build/image/fabric-ca/$(DUMMY) 80 81 docker-fvt: $(patsubst %,build/image/%/$(DUMMY), $(FVTIMAGE)) 82 83 changelog: 84 ./scripts/changelog.sh v$(PREV_VERSION) HEAD v$(BASE_VERSION) 85 86 checks: license vet lint format imports 87 88 license: .FORCE 89 @scripts/check_license 90 91 format: .FORCE 92 @scripts/check_format 93 94 imports: .FORCE 95 @scripts/check_imports 96 97 lint: .FORCE 98 @scripts/check_lint 99 100 vet: .FORCE 101 @scripts/check_vet 102 103 docs: fabric-ca-client fabric-ca-server 104 @scripts/regenDocs 105 106 fabric-ca-client: bin/fabric-ca-client 107 fabric-ca-server: bin/fabric-ca-server 108 109 bin/%: $(GO_SOURCE) 110 @echo "Building ${@F} in bin directory ..." 111 @mkdir -p bin && go build -o bin/${@F} -ldflags "$(GO_LDFLAGS)" $(path-map.${@F}) 112 @echo "Built bin/${@F}" 113 114 # We (re)build a package within a docker context but persist the $GOPATH/pkg 115 # directory so that subsequent builds are faster 116 build/docker/bin/%: 117 @echo "Building $@" 118 @mkdir -p $(@D) build/docker/$(@F)/pkg 119 @$(DRUN) \ 120 -v $(abspath build/docker/bin):/opt/gopath/bin \ 121 -v $(abspath build/docker/$(@F)/pkg):/opt/gopath/pkg \ 122 $(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \ 123 go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(PKGNAME)/$(path-map.${@F}) 124 @touch $@ 125 126 build/image/%/$(DUMMY): Makefile build/image/%/payload 127 $(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}}) 128 $(eval DOCKER_NAME = $(DOCKER_NS)/$(TARGET)) 129 @echo "Building docker $(TARGET) image" 130 @cat images/$(TARGET)/Dockerfile.in \ 131 | sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \ 132 | sed -e 's/_FABRIC_TAG_/$(FABRIC_TAG)/g' \ 133 | sed -e 's/_TAG_/$(DOCKER_TAG)/g' \ 134 | sed -e 's/_PGVER_/$(PGVER)/g' \ 135 > $(@D)/Dockerfile 136 $(DBUILD) -t $(DOCKER_NAME) --build-arg FABRIC_CA_DYNAMIC_LINK=$(FABRIC_CA_DYNAMIC_LINK) $(@D) 137 docker tag $(DOCKER_NAME) $(DOCKER_NAME):$(DOCKER_TAG) 138 @touch $@ 139 140 build/image/fabric-ca/payload: \ 141 build/docker/bin/fabric-ca-client \ 142 build/docker/bin/fabric-ca-server \ 143 build/fabric-ca.tar.bz2 144 build/image/fabric-ca-fvt/payload: \ 145 build/docker/bin/fabric-ca-client \ 146 build/docker/bin/fabric-ca-server \ 147 build/fabric-ca-fvt.tar.bz2 148 build/image/fabric-ca-orderer/payload: \ 149 build/docker/bin/fabric-ca-client 150 build/image/fabric-ca-peer/payload: \ 151 build/docker/bin/fabric-ca-client 152 build/image/fabric-ca-tools/payload: \ 153 build/docker/bin/fabric-ca-client 154 build/image/%/payload: 155 @echo "Copying $^ to $@" 156 mkdir -p $@ 157 cp $^ $@ 158 159 build/fabric-ca.tar.bz2: $(shell git ls-files images/fabric-ca/payload) 160 161 build/fabric-ca-fvt.tar.bz2: $(shell find images/fabric-ca-fvt/payload/ -maxdepth 1) 162 163 build/%.tar.bz2: 164 @echo "Building $@" 165 @tar -jc -C images/$*/payload $(notdir $^) > $@ 166 167 unit-tests: checks fabric-ca-server fabric-ca-client 168 @scripts/run_tests 169 170 # Runs benchmarks in all the packages and stores the benchmarks in /tmp/bench.results 171 bench: checks fabric-ca-server fabric-ca-client 172 @scripts/run_benchmarks 173 174 # Runs benchmarks in the specified package with cpu profiling 175 # e.g. make bench-cpu pkg=github.com/hyperledger/fabric-ca/lib 176 bench-cpu: checks fabric-ca-server fabric-ca-client 177 @scripts/run_benchmarks -C -P $(pkg) 178 179 # Runs benchmarks in the specified package with memory profiling 180 # e.g. make bench-mem pkg=github.com/hyperledger/fabric-ca/lib 181 bench-mem: checks fabric-ca-server fabric-ca-client 182 @scripts/run_benchmarks -M -P $(pkg) 183 184 # e.g. make benchcmp prev_rel=v1.0.0 185 benchcmp: guard-prev_rel bench 186 @scripts/compare_benchmarks $(prev_rel) 187 188 guard-%: 189 @if [ "${${*}}" = "" ]; then \ 190 echo "Environment variable $* not set"; \ 191 exit 1; \ 192 fi 193 194 195 # Removes all benchmark related files (bench, bench-cpu, bench-mem and *.test) 196 bench-clean: 197 @scripts/run_benchmarks -R 198 199 container-tests: docker 200 201 load-test: docker-clean docker-fvt 202 @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 203 @test/fabric-ca-load-tester/runLoad.sh -B 204 @docker kill loadTest 205 206 fvt-tests: 207 @scripts/run_fvt_tests 208 209 ci-tests: docker-clean docker-fvt unit-tests docs 210 @docker run -v $(shell pwd):/opt/gopath/src/github.com/hyperledger/fabric-ca hyperledger/fabric-ca-fvt 211 212 %-docker-clean: 213 $(eval TARGET = ${patsubst %-docker-clean,%,${@}}) 214 -docker images -q $(DOCKER_NS)/$(TARGET):latest | xargs -I '{}' docker rmi -f '{}' 215 -@rm -rf build/image/$(TARGET) ||: 216 217 docker-clean: $(patsubst %,%-docker-clean, $(IMAGES) $(PROJECT_NAME)-fvt) 218 @rm -rf build/docker/bin/* ||: 219 220 .PHONY: clean 221 222 clean: docker-clean 223 -@rm -rf build bin ||: 224 225 .FORCE: