github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/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 non-integration tests/checks
    10  #   - basic-checks - performs basic checks like license, spelling, trailing spaces and linter
    11  #   - check-deps - check for vendored dependencies that are no longer used
    12  #   - checks - runs all non-integration tests/checks
    13  #   - clean-all - superset of 'clean' that also removes persistent state
    14  #   - clean - cleans the build area
    15  #   - configtxgen - builds a native configtxgen binary
    16  #   - configtxlator - builds a native configtxlator binary
    17  #   - cryptogen - builds a native cryptogen binary
    18  #   - desk-check - runs linters and verify to test changed packages
    19  #   - dist-clean - clean release packages for all target platforms
    20  #   - docker[-clean] - ensures all docker images are available[/cleaned]
    21  #   - docker-list - generates a list of docker images that 'make docker' produces
    22  #   - docker-tag-latest - re-tags the images made by 'make docker' with the :latest tag
    23  #   - docker-tag-stable - re-tags the images made by 'make docker' with the :stable tag
    24  #   - docker-thirdparty - pulls thirdparty images (kafka,zookeeper,couchdb)
    25  #   - gotools - installs go tools like golint
    26  #   - help-docs - generate the command reference docs
    27  #   - idemixgen - builds a native idemixgen binary
    28  #   - integration-test-prereqs - setup prerequisites for integration tests
    29  #   - integration-test - runs the integration tests
    30  #   - license - checks go source files for Apache license header
    31  #   - linter - runs all code checks
    32  #   - native - ensures all native binaries are available
    33  #   - orderer - builds a native fabric orderer binary
    34  #   - orderer-docker[-clean] - ensures the orderer container is available[/cleaned]
    35  #   - peer - builds a native fabric peer binary
    36  #   - peer-docker[-clean] - ensures the peer container is available[/cleaned]
    37  #   - profile - runs unit tests for all packages in coverprofile mode (slow)
    38  #   - protos - generate all protobuf artifacts based on .proto files
    39  #   - publish-images - publishes release docker images to nexus3 or docker hub.
    40  #   - release-all - builds release packages for all target platforms
    41  #   - release - builds release packages for the host platform
    42  #   - tools-docker[-clean] - ensures the tools container is available[/cleaned]
    43  #   - unit-test-clean - cleans unit test state (particularly from docker)
    44  #   - unit-test - runs the go-test based unit tests
    45  #   - verify - runs unit tests for only the changed package tree
    46  
    47  ALPINE_VER ?= 3.12
    48  BASE_VERSION = 2.2.2
    49  
    50  # 3rd party image version
    51  # These versions are also set in the runners in ./integration/runners/
    52  COUCHDB_VER ?= 3.1
    53  KAFKA_VER ?= 5.3.1
    54  ZOOKEEPER_VER ?= 5.3.1
    55  
    56  # Disable implicit rules
    57  .SUFFIXES:
    58  MAKEFLAGS += --no-builtin-rules
    59  
    60  BUILD_DIR ?= build
    61  
    62  EXTRA_VERSION ?= $(shell git rev-parse --short HEAD)
    63  PROJECT_VERSION=$(BASE_VERSION)-snapshot-$(EXTRA_VERSION)
    64  
    65  # TWO_DIGIT_VERSION is derived, e.g. "2.0", especially useful as a local tag
    66  # for two digit references to most recent baseos and ccenv patch releases
    67  TWO_DIGIT_VERSION = $(shell echo $(BASE_VERSION) | cut -d '.' -f 1,2)
    68  
    69  PKGNAME = github.com/hyperledger/fabric
    70  ARCH=amd64
    71  MARCH=linux-amd64
    72  
    73  # defined in common/metadata/metadata.go
    74  METADATA_VAR = Version=$(BASE_VERSION)
    75  METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
    76  METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
    77  METADATA_VAR += DockerNamespace=$(DOCKER_NS)
    78  
    79  GO_VER = 1.14.12
    80  GO_TAGS ?=
    81  
    82  RELEASE_EXES = orderer $(TOOLS_EXES)
    83  RELEASE_IMAGES = baseos ccenv orderer peer tools
    84  RELEASE_PLATFORMS = darwin-amd64 linux-amd64 windows-amd64
    85  TOOLS_EXES = configtxgen configtxlator cryptogen discover idemixgen peer
    86  
    87  pkgmap.configtxgen    := $(PKGNAME)/cmd/configtxgen
    88  pkgmap.configtxlator  := $(PKGNAME)/cmd/configtxlator
    89  pkgmap.cryptogen      := $(PKGNAME)/cmd/cryptogen
    90  pkgmap.discover       := $(PKGNAME)/cmd/discover
    91  pkgmap.idemixgen      := $(PKGNAME)/cmd/idemixgen
    92  pkgmap.orderer        := $(PKGNAME)/cmd/orderer
    93  pkgmap.peer           := $(PKGNAME)/cmd/peer
    94  
    95  .DEFAULT_GOAL := all
    96  
    97  include docker-env.mk
    98  include gotools.mk
    99  
   100  .PHONY: all
   101  all: check-go-version native docker checks
   102  
   103  .PHONY: checks
   104  checks: basic-checks unit-test integration-test
   105  
   106  .PHONY: basic-checks
   107  basic-checks: check-go-version license spelling references trailing-spaces linter check-metrics-doc filename-spaces
   108  
   109  .PHONY: desk-checks
   110  desk-check: checks verify
   111  
   112  .PHONY: help-docs
   113  help-docs: native
   114  	@scripts/generateHelpDocs.sh
   115  
   116  .PHONY: spelling
   117  spelling: gotool.misspell
   118  	@scripts/check_spelling.sh
   119  
   120  .PHONY: references
   121  references:
   122  	@scripts/check_references.sh
   123  
   124  .PHONY: license
   125  license:
   126  	@scripts/check_license.sh
   127  
   128  .PHONY: trailing-spaces
   129  trailing-spaces:
   130  	@scripts/check_trailingspaces.sh
   131  
   132  .PHONY: gotools
   133  gotools: gotools-install
   134  
   135  .PHONY: check-go-version
   136  check-go-version:
   137  	@scripts/check_go_version.sh $(GO_VER)
   138  
   139  .PHONY: integration-test
   140  integration-test: integration-test-prereqs
   141  	./scripts/run-integration-tests.sh
   142  
   143  .PHONY: integration-test-prereqs
   144  integration-test-prereqs: gotool.ginkgo baseos-docker ccenv-docker docker-thirdparty
   145  
   146  .PHONY: unit-test
   147  unit-test: unit-test-clean docker-thirdparty-couchdb
   148  	./scripts/run-unit-tests.sh
   149  
   150  .PHONY: unit-tests
   151  unit-tests: unit-test
   152  
   153  # Pull thirdparty docker images based on the latest baseimage release version
   154  # Also pull ccenv-1.4 for compatibility test to ensure pre-2.0 installed chaincodes
   155  # can be built by a peer configured to use the ccenv-1.4 as the builder image.
   156  .PHONY: docker-thirdparty
   157  docker-thirdparty: docker-thirdparty-couchdb
   158  	docker pull confluentinc/cp-zookeeper:${ZOOKEEPER_VER}
   159  	docker pull confluentinc/cp-kafka:${KAFKA_VER}
   160  	docker pull hyperledger/fabric-ccenv:1.4
   161  
   162  .PHONY: docker-thirdparty-couchdb
   163  docker-thirdparty-couchdb:
   164  	docker pull couchdb:${COUCHDB_VER}
   165  
   166  .PHONY: verify
   167  verify: export JOB_TYPE=VERIFY
   168  verify: unit-test
   169  
   170  .PHONY: profile
   171  profile: export JOB_TYPE=PROFILE
   172  profile: unit-test
   173  
   174  .PHONY: linter
   175  linter: check-deps gotool.goimports
   176  	@echo "LINT: Running code checks.."
   177  	./scripts/golinter.sh
   178  
   179  .PHONY: check-deps
   180  check-deps:
   181  	@echo "DEP: Checking for dependency issues.."
   182  	./scripts/check_deps.sh
   183  
   184  .PHONY: check-metrics-docs
   185  check-metrics-doc:
   186  	@echo "METRICS: Checking for outdated reference documentation.."
   187  	./scripts/metrics_doc.sh check
   188  
   189  .PHONY: generate-metrics-docs
   190  generate-metrics-doc:
   191  	@echo "Generating metrics reference documentation..."
   192  	./scripts/metrics_doc.sh generate
   193  
   194  .PHONY: protos
   195  protos: gotool.protoc-gen-go
   196  	@echo "Compiling non-API protos..."
   197  	./scripts/compile_protos.sh
   198  
   199  .PHONY: native
   200  native: $(RELEASE_EXES)
   201  
   202  .PHONY: $(RELEASE_EXES)
   203  $(RELEASE_EXES): %: $(BUILD_DIR)/bin/%
   204  
   205  $(BUILD_DIR)/bin/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%)
   206  $(BUILD_DIR)/bin/%:
   207  	@echo "Building $@"
   208  	@mkdir -p $(@D)
   209  	GOBIN=$(abspath $(@D)) go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
   210  	@touch $@
   211  
   212  .PHONY: docker
   213  docker: $(RELEASE_IMAGES:%=%-docker)
   214  
   215  .PHONY: $(RELEASE_IMAGES:%=%-docker)
   216  $(RELEASE_IMAGES:%=%-docker): %-docker: $(BUILD_DIR)/images/%/$(DUMMY)
   217  
   218  $(BUILD_DIR)/images/ccenv/$(DUMMY):   BUILD_CONTEXT=images/ccenv
   219  $(BUILD_DIR)/images/baseos/$(DUMMY):  BUILD_CONTEXT=images/baseos
   220  $(BUILD_DIR)/images/peer/$(DUMMY):    BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
   221  $(BUILD_DIR)/images/orderer/$(DUMMY): BUILD_ARGS=--build-arg GO_TAGS=${GO_TAGS}
   222  
   223  $(BUILD_DIR)/images/%/$(DUMMY):
   224  	@echo "Building Docker image $(DOCKER_NS)/fabric-$*"
   225  	@mkdir -p $(@D)
   226  	$(DBUILD) -f images/$*/Dockerfile \
   227  		--build-arg GO_VER=$(GO_VER) \
   228  		--build-arg ALPINE_VER=$(ALPINE_VER) \
   229  		$(BUILD_ARGS) \
   230  		-t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT)
   231  	docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(BASE_VERSION)
   232  	docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(TWO_DIGIT_VERSION)
   233  	docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
   234  	@touch $@
   235  
   236  # builds release packages for the host platform
   237  .PHONY: release
   238  release: check-go-version $(MARCH:%=release/%)
   239  
   240  # builds release packages for all target platforms
   241  .PHONY: release-all
   242  release-all: check-go-version $(RELEASE_PLATFORMS:%=release/%)
   243  
   244  .PHONY: $(RELEASE_PLATFORMS:%=release/%)
   245  $(RELEASE_PLATFORMS:%=release/%): GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%)
   246  $(RELEASE_PLATFORMS:%=release/%): release/%: $(foreach exe,$(RELEASE_EXES),release/%/bin/$(exe))
   247  
   248  # explicit targets for all platform executables
   249  $(foreach platform, $(RELEASE_PLATFORMS), $(RELEASE_EXES:%=release/$(platform)/bin/%)):
   250  	$(eval platform = $(patsubst release/%/bin,%,$(@D)))
   251  	$(eval GOOS = $(word 1,$(subst -, ,$(platform))))
   252  	$(eval GOARCH = $(word 2,$(subst -, ,$(platform))))
   253  	@echo "Building $@ for $(GOOS)-$(GOARCH)"
   254  	mkdir -p $(@D)
   255  	GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
   256  
   257  .PHONY: dist
   258  dist: dist-clean dist/$(MARCH)
   259  
   260  .PHONY: dist-all
   261  dist-all: dist-clean $(RELEASE_PLATFORMS:%=dist/%)
   262  dist/%: release/%
   263  	mkdir -p release/$(@F)/config
   264  	cp -r sampleconfig/*.yaml release/$(@F)/config
   265  	cd release/$(@F) && tar -czvf hyperledger-fabric-$(@F).$(PROJECT_VERSION).tar.gz *
   266  
   267  .PHONY: docker-list
   268  docker-list: $(RELEASE_IMAGES:%=%-docker-list)
   269  %-docker-list:
   270  	@echo $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
   271  
   272  .PHONY: docker-clean
   273  docker-clean: $(RELEASE_IMAGES:%=%-docker-clean)
   274  %-docker-clean:
   275  	-@for image in "$$(docker images --quiet --filter=reference='$(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)')"; do \
   276  		[ -z "$$image" ] || docker rmi -f $$image; \
   277  	done
   278  	-@rm -rf $(BUILD_DIR)/images/$* || true
   279  
   280  .PHONY: docker-tag-latest
   281  docker-tag-latest: $(RELEASE_IMAGES:%=%-docker-tag-latest)
   282  %-docker-tag-latest:
   283  	docker tag $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS)/fabric-$*:latest
   284  
   285  .PHONY: docker-tag-stable
   286  docker-tag-stable: $(RELEASE_IMAGES:%=%-docker-tag-stable)
   287  %-docker-tag-stable:
   288  	docker tag $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG) $(DOCKER_NS)/fabric-$*:stable
   289  
   290  .PHONY: publish-images
   291  publish-images: $(RELEASE_IMAGES:%=%-publish-images)
   292  %-publish-images:
   293  	@docker login $(DOCKER_HUB_USERNAME) $(DOCKER_HUB_PASSWORD)
   294  	@docker push $(DOCKER_NS)/fabric-$*:$(PROJECT_VERSION)
   295  
   296  .PHONY: clean
   297  clean: docker-clean unit-test-clean release-clean
   298  	-@rm -rf $(BUILD_DIR)
   299  
   300  .PHONY: clean-all
   301  clean-all: clean gotools-clean dist-clean
   302  	-@rm -rf /var/hyperledger/*
   303  	-@rm -rf docs/build/
   304  
   305  .PHONY: dist-clean
   306  dist-clean:
   307  	-@for platform in $(RELEASE_PLATFORMS) ""; do \
   308  		[ -z "$$platform" ] || rm -rf release/$${platform}/hyperledger-fabric-$${platform}.$(PROJECT_VERSION).tar.gz; \
   309  	done
   310  
   311  .PHONY: release-clean
   312  release-clean: $(RELEASE_PLATFORMS:%=%-release-clean)
   313  %-release-clean:
   314  	-@rm -rf release/$*
   315  
   316  .PHONY: unit-test-clean
   317  unit-test-clean:
   318  
   319  .PHONY: filename-spaces
   320  spaces:
   321  	@scripts/check_file_name_spaces.sh