forked from hyperledger-cello/cello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·364 lines (298 loc) · 11.3 KB
/
Makefile
File metadata and controls
executable file
·364 lines (298 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# Copyright IBM Corp, All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# -------------------------------------------------------------
# This makefile defines the following targets, feel free to run "make help" to see help info
#
# - all (default): Builds all targets and runs all tests/checks
# - check: Setup as master node, and runs all tests/checks, will be triggered by CI
# - clean: Cleans the build area
# - doc|docs: Start a local web service to explore the documentation
# - docker[-clean]: Build/clean docker images locally
# - dockerhub: Build using dockerhub materials, to verify them
# - dockerhub-pull: Pulling service images from dockerhub
# - license: Checks sourrce files for Apache license header
# - help: Output the help instructions for each command
# - log: Check the recent log output of given service
# - logs: Check the recent log output of all services
# - reset: Clean up and remove local storage (only use for development)
# - restart: Stop the cello service and then start
# - setup-master: Setup the host as a master node, install pkg and download docker images
# - setup-worker: Setup the host as a worker node, install pkg and download docker images
# - start: Start the cello service
# - stop: Stop the cello service, and remove all service containers
# - start-nfs: Start the cello nfs service
# - stop-nfs: Stop the cello nfs service
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
ARCH := $(shell uname -m)
# changelog specific version tags
PREV_VERSION?=0.9.0
# Building image usage
DOCKER_NS ?= hyperledger
BASENAME ?= $(DOCKER_NS)/cello
VERSION ?= 0.9.0
IS_RELEASE=false
DOCKER_BASE_x86_64=python:3.6
DOCKER_BASE_ppc64le=ppc64le/python:3.6
DOCKER_BASE_s390x=s390x/python:3.6
DOCKER_BASE=$(DOCKER_BASE_$(ARCH))
BASE_VERSION ?= $(ARCH)-$(VERSION)
ifeq ($(IS_RELEASE),false)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
IMG_TAG=$(BASE_VERSION)-$(EXTRA_VERSION)
else
IMG_TAG=$(BASE_VERSION)
endif
# The Cello service listen interface, please use the public available IP.
SERVER_PUBLIC_IP ?= 127.0.0.1
LOCAL_STORAGE_PATH=/opt/cello
# Docker images needed to run cello services
DOCKER_IMAGES = ansible-agent api-engine nginx
DUMMY = .$(IMG_TAG)
ifeq ($(DOCKER_BASE), )
$(error "Architecture \"$(ARCH)\" is unsupported")
endif
# Frontend needed
SLASH:=/
REPLACE_SLASH:=\/
# deploy method docker-compose/k8s
export DEPLOY_METHOD?=docker-compose
export NEXT_VERSION?=False
-include .makerc/service
-include .makerc/email
-include .makerc/operator-dashboard
-include .makerc/user-dashboard
-include .makerc/worker-node
-include .makerc/keycloak
-include .makerc/parse-server
-include .makerc/kubernetes
-include .makerc/api-engine
export ROOT_PATH = ${PWD}
ROOT_PATH_REPLACE=$(subst $(SLASH),$(REPLACE_SLASH),$(ROOT_PATH))
# macOS has diff `sed` usage from Linux
SYSTEM=$(shell uname)
ifeq ($(SYSTEM), Darwin)
SED = sed -ix
else
SED = sed -i
endif
ifneq ($(wildcard /opt/cello/keycloak-mysql),)
INITIAL_CMD =
INITIAL_KEYCLOAK=false
else
ifeq ($(NEXT_VERSION),False)
INITIAL_CMD = make initial-keycloak
else
INITIAL_CMD = make initial-keycloak-next
endif
INITIAL_KEYCLOAK=true
endif
# Specify what type the worker node is setup as
WORKER_TYPE ?= docker
# Specify the running mode, prod or dev
MODE ?= prod
ifeq ($(MODE),prod)
COMPOSE_FILE=docker-compose.yml
export DEPLOY_TEMPLATE_NAME=deploy.tmpl
export DEBUG?=False
else
COMPOSE_FILE=docker-compose-dev.yml
export DEPLOY_TEMPLATE_NAME=deploy-dev.tmpl
export DEBUG?=True
endif
all: check
build/docker/%/$(DUMMY): ##@Build an image locally
$(eval TARGET = ${patsubst build/docker/%/$(DUMMY),%,${@}})
$(eval IMG_NAME = $(BASENAME)-$(TARGET))
@mkdir -p $(@D)
@echo "Building docker $(TARGET)"
@cat build_image/docker/$(TARGET)/Dockerfile.in \
| sed -e 's|_DOCKER_BASE_|$(DOCKER_BASE)|g' \
| sed -e 's|_NS_|$(DOCKER_NS)|g' \
| sed -e 's|_TAG_|$(IMG_TAG)|g' \
> $(@D)/Dockerfile
docker build -f $(@D)/Dockerfile \
-t $(IMG_NAME) \
-t $(IMG_NAME):$(IMG_TAG) \
. ;
@touch $@ ;
build/docker/%/.push: build/docker/%/$(DUMMY)
@docker login \
--username=$(DOCKER_HUB_USERNAME) \
--password=$(DOCKER_HUB_PASSWORD)
@docker push $(BASENAME)-$(patsubst build/docker/%/.push,%,$@):$(IMG_TAG)
docker: $(patsubst %,build/docker/%/$(DUMMY),$(DOCKER_IMAGES)) ##@Generate docker images locally
docker-operator-dashboard: build/docker/operator-dashboard/$(DUMMY)
docker-clean: stop image-clean ##@Clean all existing images
DOCKERHUB_IMAGES = baseimage engine operator-dashboard user-dashboard watchdog ansible-agent parse-server
dockerhub: $(patsubst %,dockerhub-%,$(DOCKERHUB_IMAGES)) ##@Building latest docker images as hosted in dockerhub
dockerhub-%: ##@Building latest images with dockerhub materials, to valid them
dir=$*; \
IMG=hyperledger/cello-$$dir; \
echo "Building $$IMG"; \
docker build \
-t $$IMG \
-t $$IMG:x86_64-latest \
build_image/dockerhub/latest/$$dir
dockerhub-pull: ##@Pull service images from dockerhub
cd scripts/master_node && bash download_images.sh
license:
bash scripts/check_license.sh
install: $(patsubst %,build/docker/%/.push,$(DOCKER_IMAGES))
check-js: ##@Code Check check js code format
docker-compose -f bootup/docker-compose-files/docker-compose-check-js.yaml up
check: ##@Code Check code format
@$(MAKE) license
find ./docs -type f -name "*.md" -exec egrep -l " +$$" {} \;
cd src/api-engine && tox && cd ${ROOT_PATH}
make docker
API_ENGINE_SSO_AUTH_URL=http://keycloak:8080/auth/ NEXT_VERSION=True SERVER_PUBLIC_IP=127.0.0.1 MODE=dev make start
sleep 10
make test-api
NEXT_VERSION=True MODE=dev make stop
test-case: ##@Code Run test case for flask server
@$(MAKE) -C src/operator-dashboard/test/ all
clean: ##@Code Clean tox result
rm -rf .tox .cache *.egg-info build/
find . -name "*.pyc" -o -name "__pycache__" | xargs rm -rf
# TODO (david_dornseier): As long as there are no release versions, always rewrite
# the entire changelog (bug)
changelog: ##@Update the changelog.md file in the root folder
#bash scripts/changelog.sh bd0c6db v$(PREV_VERSION)
bash scripts/changelog.sh v$(PREV_VERSION) HEAD
docs: doc
doc: ##@Create local online documentation and start serve
command -v mkdocs >/dev/null 2>&1 || pip install mkdocs
mkdocs serve -f mkdocs.yml
# Use like "make log service=dashboard"
log: ##@Log tail special service log, Use like "make log service=dashboard"
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} logs --tail=200 -f ${service}
logs: ##@Log tail for all service log
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} logs -f --tail=200
image-clean: clean ##@Clean all existing images to rebuild
echo "Clean all cello related images, may need to remove all containers before"
docker images | grep "hyperledger/cello-" | awk '{print $3}' | xargs docker rmi -f
initial-env: ##@Configuration Initial Configuration for dashboard
@envsubst < configs/env.tmpl > .env
initial-keycloak:
docker-compose -f bootup/docker-compose-files/docker-compose-initial.yml up --abort-on-container-exit
initial-keycloak-next:
docker-compose -f bootup/docker-compose-files/new_version/docker-compose-initial.yml up --abort-on-container-exit
check-environment:
if [ "$(SERVER_PUBLIC_IP)" = "" ] && [ "$(NEXT_VERSION)" = "False" ]; then \
echo "Environment variable SERVER_PUBLIC_IP not set"; \
echo "Please refer docs/setup_master.md for more details"; \
exit 1; \
fi
start-old:
echo "Start all services with bootup/docker-compose-files/${COMPOSE_FILE}... docker images must exist local now, otherwise, run 'make setup-master first' !"
if [ "$(MODE)" = "dev" ]; then \
make build-admin-js; \
fi
$(INITIAL_CMD)
if [ "$(INITIAL_KEYCLOAK)" = "true" ]; then \
OPERATOR_DASHBOARD_SSO_SECRET=`sed -n '/export OPERATOR_DASHBOARD_SSO_SECRET?=/ {s///p;q;}' .makerc/operator-dashboard` \
USER_DASHBOARD_SSO_SECRET=`sed -n '/export USER_DASHBOARD_SSO_SECRET?=/ {s///p;q;}' .makerc/user-dashboard` \
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} up -d --force-recreate; \
else \
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} up -d --force-recreate; \
fi
echo "Now you can visit operator-dashboard at localhost:8080, or user-dashboard at localhost:8081"
@$(MAKE) start-nfs
start: ##@Service Start service
@$(MAKE) check-environment
make initial-env
if [ "$(NEXT_VERSION)" = "False" ]; then \
make start-old; \
else \
make start-next; \
fi
start-next-docker:
docker-compose -f bootup/docker-compose-files/new_version/${COMPOSE_FILE} up -d --force-recreate
start-next:
if [ "$(DEPLOY_METHOD)" = "docker-compose" ]; then \
make start-next-docker; \
else \
make start-k8s; \
fi
stop-next-docker:
echo "Stop all services with bootup/docker-compose-files/${COMPOSE_FILE}..."
docker-compose -f bootup/docker-compose-files/new_version/${COMPOSE_FILE} stop
echo "Remove all services with ${COMPOSE_FILE}..."
docker-compose -f bootup/docker-compose-files/new_version/${COMPOSE_FILE} rm -f -a
stop-next:
if [ "$(DEPLOY_METHOD)" = "docker-compose" ]; then \
make stop-next-docker; \
else \
make stop-k8s; \
fi
start-k8s:
@$(MAKE) -C bootup/kubernetes init-yaml
@$(MAKE) -C bootup/kubernetes start
test-api:
@$(MAKE) -C tests/postman/ test-api
stop-k8s:
@$(MAKE) -C bootup/kubernetes stop
stop-old:
echo "Stop all services with bootup/docker-compose-files/${COMPOSE_FILE}..."
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} stop
echo "Remove all services with ${COMPOSE_FILE}..."
docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} rm -f -a
stop: ##@Service Stop service
if [ "$(NEXT_VERSION)" = "False" ]; then \
make stop-old; \
else \
make stop-next; \
fi
reset: clean ##@Environment clean up and remove local storage (only use for development)
echo "Clean up and remove all local storage..."
rm -rf ${LOCAL_STORAGE_PATH}/*
restart: stop start ##@Service Restart service
setup-master: ##@Environment Setup dependency for master node
cd scripts/master_node && bash setup.sh
setup-worker: ##@Environment Setup dependency for worker node
cd scripts/worker_node && bash setup.sh $(WORKER_TYPE)
build-admin-js: ##@Nodejs Build admin dashboard js files
@$(MAKE) initial-env
bash scripts/master_node/build_js.sh
build-user-dashboard-js: ##@Nodejs Build user dashboard js files
@$(MAKE) -C src/user-dashboard/ build-js
help: ##@other Show this help.
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
start-nfs: ##@Service start nfs service
docker-compose -f bootup/docker-compose-files/docker-compose-nfs.yml up -d --no-recreate
stop-nfs: ##@Service stop nfs service
docker-compose -f bootup/docker-compose-files/docker-compose-nfs.yml down
HELP_FUN = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "usage: make [target]\n\n"; \
for (sort keys %help) { \
print "${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }
.PHONY: \
all \
check \
clean \
changelog \
doc \
docker \
dockerhub \
docker-clean \
license \
log \
logs \
restart \
setup-master \
setup-worker \
start \
stop