Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. # Copyright IBM Corp, All Rights Reserved.
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. #
  5. #
  6. # -------------------------------------------------------------
  7. # This makefile defines the following targets
  8. #
  9. # - all (default): Builds all targets and runs all tests/checks
  10. # - check: Setup as master node, and runs all tests/checks, will be triggered by CI
  11. # - clean: Cleans the build area
  12. # - doc: Start a local web service to explore the documentation
  13. # - docker[-clean]: Build/clean docker images locally
  14. # - dockerhub: Build using dockerhub materials, to verify them
  15. # - dockerhub-pull: Pulling service images from dockerhub
  16. # - license: Checks sourrce files for Apache license header
  17. # - help: Output the help instructions for each command
  18. # - log: Check the recent log output of all services
  19. # - restart: Stop the cello service and then start
  20. # - setup-master: Setup the host as a master node, install pkg and download docker images
  21. # - setup-worker: Setup the host as a worker node, install pkg and download docker images
  22. # - start: Start the cello service
  23. # - stop: Stop the cello service, and remove all service containers
  24. GREEN := $(shell tput -Txterm setaf 2)
  25. WHITE := $(shell tput -Txterm setaf 7)
  26. YELLOW := $(shell tput -Txterm setaf 3)
  27. RESET := $(shell tput -Txterm sgr0)
  28. ARCH := $(shell uname -m)
  29. # changelog specific version tags
  30. PREV_VERSION?=0.8.0
  31. # Building image usage
  32. DOCKER_NS ?= hyperledger
  33. BASENAME ?= $(DOCKER_NS)/cello
  34. VERSION ?= latest
  35. IS_RELEASE=false
  36. DOCKER_BASE_x86_64=ubuntu:xenial
  37. DOCKER_BASE_ppc64le=ppc64le/ubuntu:xenial
  38. DOCKER_BASE_s390x=s390x/debian:jessie
  39. DOCKER_BASE=$(DOCKER_BASE_$(ARCH))
  40. BASE_VERSION ?= $(ARCH)-$(VERSION)
  41. ifeq ($(IS_RELEASE),false)
  42. EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
  43. IMG_TAG=$(BASE_VERSION)
  44. else
  45. IMG_TAG=$(BASE_VERSION)
  46. endif
  47. # Docker images needed to run cello services
  48. DOCKER_IMAGES =baseimage operator-dashboard user-dashboard
  49. DUMMY = .$(IMG_TAG)
  50. ifeq ($(DOCKER_BASE), )
  51. $(error "Architecture \"$(ARCH)\" is unsupported")
  52. endif
  53. # Frontend needed
  54. SLASH:=/
  55. REPLACE_SLASH:=\/
  56. -include .makerc/email
  57. -include .makerc/operator-dashboard
  58. -include .makerc/user-dashboard
  59. -include .makerc/worker-node
  60. export ROOT_PATH = ${PWD}
  61. ROOT_PATH_REPLACE=$(subst $(SLASH),$(REPLACE_SLASH),$(ROOT_PATH))
  62. # macOS has diff `sed` usage from Linux
  63. SYSTEM=$(shell uname)
  64. ifeq ($(SYSTEM), Darwin)
  65. SED = sed -ix
  66. else
  67. SED = sed -i
  68. endif
  69. ifeq (${THEME}, basic) # basic theme doesn't need js compiling
  70. START_OPTIONS = initial-env
  71. else
  72. BUILD_JS=
  73. # ifeq (${THEME}, react) # react needs compiling js first
  74. # ifneq ($(wildcard ./src/${STATIC_FOLDER}/dist),)
  75. # BUILD_JS=
  76. # else
  77. # BUILD_JS=build-admin-js build-user-dashboard-js
  78. # endif
  79. # else
  80. # ifneq ($(wildcard ./src/${STATIC_FOLDER}/dist),)
  81. # BUILD_JS=
  82. # else
  83. # BUILD_JS=build-admin-js build-user-dashboard-js
  84. # endif
  85. # endif
  86. START_OPTIONS = initial-env $(BUILD_JS)
  87. endif
  88. all: check
  89. build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
  90. build/docker/nginx/$(DUMMY): build/docker/nginx/$(DUMMY)
  91. build/docker/mongo/$(DUMMY): build/docker/mongo/$(DUMMY)
  92. build/docker/engine/$(DUMMY): build/docker/engine/$(DUMMY)
  93. build/docker/operator-dashboard/$(DUMMY): build/docker/operator-dashboard/$(DUMMY)
  94. #build/docker/ansible-agent/$(DUMMY): build/docker/ansible-agent/$(DUMMY)
  95. build/docker/watchdog/$(DUMMY): build/docker/watchdog/$(DUMMY)
  96. build/docker/user-dashboard/$(DUMMY): build/docker/user-dashboard/$(DUMMY)
  97. build/docker/%/$(DUMMY): ##@Build an image locally
  98. $(eval TARGET = ${patsubst build/docker/%/$(DUMMY),%,${@}})
  99. $(eval IMG_NAME = $(BASENAME)-$(TARGET))
  100. @mkdir -p $(@D)
  101. @echo "Building docker $(TARGET)"
  102. @cat docker/$(TARGET)/Dockerfile.in \
  103. | sed -e 's|_DOCKER_BASE_|$(DOCKER_BASE)|g' \
  104. | sed -e 's|_NS_|$(DOCKER_NS)|g' \
  105. | sed -e 's|_TAG_|$(IMG_TAG)|g' \
  106. > $(@D)/Dockerfile
  107. docker build -f $(@D)/Dockerfile \
  108. -t $(IMG_NAME) \
  109. -t $(IMG_NAME):$(IMG_TAG) \
  110. . ;
  111. @touch $@ ;
  112. build/docker/%/.push: build/docker/%/$(DUMMY)
  113. @docker login \
  114. --username=$(DOCKER_HUB_USERNAME) \
  115. --password=$(DOCKER_HUB_PASSWORD)
  116. @docker push $(BASENAME)-$(patsubst build/docker/%/.push,%,$@):$(IMG_TAG)
  117. docker: $(patsubst %,build/docker/%/$(DUMMY),$(DOCKER_IMAGES)) ##@Generate docker images locally
  118. docker-operator-dashboard: build/docker/operator-dashboard/$(DUMMY)
  119. docker-user-dashboard: build/docker/user-dashboard/$(DUMMY)
  120. docker-clean: stop image-clean ##@Clean all existing images
  121. DOCKERHUB_IMAGES = engine operator-dashboard user-dashboard watchdog
  122. dockerhub: $(patsubst %,dockerhub-%,$(DOCKERHUB_IMAGES)) ##@Building latest images with dockerhub materials, to valid them
  123. dockerhub-%: ##@Building latest images with dockerhub materials, to valid them
  124. dir=$*; \
  125. IMG=hyperledger/cello-$$dir; \
  126. echo "Building $$IMG"; \
  127. docker build \
  128. -t $$IMG \
  129. -t $$IMG:x86_64-latest \
  130. dockerhub/latest/$$dir
  131. dockerhub-pull: ##@Pull service images from dockerhub
  132. cd scripts/master_node && bash download_images.sh
  133. license:
  134. bash scripts/check_license.sh
  135. install: $(patsubst %,build/docker/%/.push,$(DOCKER_IMAGES))
  136. check-js: ##@Code Check check js code format
  137. docker-compose -f docker-compose-check-js.yaml up
  138. check: setup-master docker-operator-dashboard ##@Code Check code format
  139. @$(MAKE) license
  140. find ./docs -type f -name "*.md" -exec egrep -l " +$$" {} \;
  141. tox
  142. @$(MAKE) check-js
  143. @$(MAKE) test-case
  144. make start && sleep 60 && make stop
  145. test-case: ##@Code Run test case for flask server
  146. @$(MAKE) -C test/ all
  147. clean: ##@Code Clean tox result
  148. rm -rf .tox .cache *.egg-info build/
  149. find . -name "*.pyc" -o -name "__pycache__" | xargs rm -rf
  150. # TODO (david_dornseier): As long as there are no release versions, always rewrite
  151. # the entire changelog (bug)
  152. changelog: ##@Update the changelog.md file in the root folder
  153. #bash scripts/changelog.sh bd0c6db v$(PREV_VERSION)
  154. bash scripts/changelog.sh v$(PREV_VERSION) HEAD
  155. doc: ##@Create local online documentation and start serve
  156. pip install mkdocs
  157. mkdocs serve
  158. # Use like "make log service=dashboard"
  159. log: ##@Log tail special service log, Use like "make log service=dashboard"
  160. docker-compose logs --tail=200 -f ${service}
  161. logs: ##@Log tail for all service log
  162. docker-compose logs -f --tail=200
  163. image-clean: clean ##@Clean all existing images to rebuild
  164. echo "Clean all cello related images, may need to remove all containers before"
  165. docker images | grep "hyperledger/cello-" | awk '{print $3}' | xargs docker rmi -f
  166. initial-env: ##@Configuration Initial Configuration for dashboard
  167. @envsubst < env.tmpl > .env
  168. start: ##@Service Start service
  169. @$(MAKE) $(START_OPTIONS)
  170. echo "Start all services... docker images must exist local now, otherwise, run 'make setup-master first' !"
  171. docker-compose -f ${DEPLOY_COMPOSE_FILE} up -d --no-recreate
  172. stop: ##@Service Stop service
  173. echo "Stop all services..."
  174. docker-compose -f ${DEPLOY_COMPOSE_FILE} stop
  175. echo "Remove all services..."
  176. docker-compose rm -f -a
  177. restart: stop start ##@Service Restart service
  178. setup-master: ##@Environment Setup dependency for master node
  179. cd scripts/master_node && bash setup.sh
  180. setup-worker: ##@Environment Setup dependency for worker node
  181. cd scripts/worker_node && bash setup.sh
  182. build-admin-js: ##@Nodejs Build admin dashboard js files
  183. @$(MAKE) initial-env
  184. bash scripts/master_node/build_js.sh
  185. build-user-dashboard-js: ##@Nodejs Build user dashboard js files
  186. @$(MAKE) -C user-dashboard/ build-js
  187. watch-mode: ##@Nodejs Run watch mode with js files for react
  188. bash scripts/master_node/watch_mode.sh
  189. npm-install: ##@Nodejs Install modules with npm package management
  190. bash scripts/master_node/npm_install.sh
  191. # @$(MAKE) -C user-dashboard/ npm-install
  192. help: ##@other Show this help.
  193. @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
  194. HELP_FUN = \
  195. %help; \
  196. while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
  197. print "usage: make [target]\n\n"; \
  198. for (sort keys %help) { \
  199. print "${WHITE}$$_:${RESET}\n"; \
  200. for (@{$$help{$$_}}) { \
  201. $$sep = " " x (32 - length $$_->[0]); \
  202. print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
  203. }; \
  204. print "\n"; }
  205. .PHONY: \
  206. all \
  207. check \
  208. clean \
  209. changelog \
  210. doc \
  211. docker \
  212. dockerhub \
  213. docker-clean \
  214. license \
  215. log \
  216. logs \
  217. restart \
  218. setup-master \
  219. setup-worker \
  220. start \
  221. stop