diff --git a/Kconfig b/Kconfig new file mode 100644 index 000000000..b7d2aa6e4 --- /dev/null +++ b/Kconfig @@ -0,0 +1,66 @@ +menu "Deploy (部署)" + choice + prompt "Method (部署方式)" + + config DOCKER_COMPOSE_DEPLOY + bool "docker-compose deploy (docker-compose部署)" + + config K8S_DEPLOY + bool "kubernetes deploy (kubernetes 部署)" + endchoice + choice + prompt "Mode (部署模式)" + + config DEV_MODE + bool "dev-mode(开发模式)" + + config PROD_MODE + bool "prod-mode(生产模式)" + endchoice +endmenu + +menu "API Server Config (API服务配置)" + config API_ENGINE_WEBROOT + string "WEBROOT (服务根路径)" + default "/engine" + config POSTGRES_USER + string "POSTGRES_USER (数据库用户名)" + default "admin" + config POSTGRES_PASSWORD + string "POSTGRES_PASSWORD (数据库密码)" + default "password" + config API_ENGINE_SERVICE_PORT + int "Service Port (服务端口)" + default 8085 + range 8000 10000 + config API_ENGINE_ADMIN_TOKEN + string "Admin Token(管理员Token)" + default "administrator" + config API_ENGINE_ADMIN_USERNAME + string "Admin Username (管理员用户名)" + default "admin" + config API_ENGINE_ADMIN_PASSWORD + string "Admin Password (管理员密码)" + default "pass" + config API_ENGINE_ADMIN_EMAIL + string "Admin email (管理员邮箱)" + default "admin@cello.com" + config API_DOCKER_HOST + string "Docker Host(Docker主机)" + default "unix://var/run/docker.sock" + config API_VERSION + string "Version (接口版本)" + default "master" +endmenu + +menu "Dashboard Config (控制台服务配置)" + config MOCK + bool "Whether mock api (是否采用假数据)" + default y + config PROXY + string "API Proxy (API代理)" + config DASHBOARD_SERVICE_PORT + int "Dashboard Service Port (控制台服务端口)" + default 8081 + range 8000 10000 +endmenu diff --git a/Makefile b/Makefile index 3f1404861..f1dcceba6 100755 --- a/Makefile +++ b/Makefile @@ -74,11 +74,14 @@ REPLACE_SLASH:=\/ # deploy method docker-compose/k8s export DEPLOY_METHOD?=docker-compose +-include .config -include .makerc/kubernetes -include .makerc/api-engine -include .makerc/dashboard -include .makerc/functions +.EXPORT_ALL_VARIABLES: + export ROOT_PATH = ${PWD} ROOT_PATH_REPLACE=$(subst $(SLASH),$(REPLACE_SLASH),$(ROOT_PATH)) @@ -95,7 +98,7 @@ WORKER_TYPE ?= docker # Specify the running mode, prod or dev MODE ?= prod -ifeq ($(MODE),prod) +ifeq ($(CONFIG_PROD_MODE),y) COMPOSE_FILE=docker-compose.yml export DEPLOY_TEMPLATE_NAME=deploy.tmpl export DEBUG?=False @@ -199,10 +202,10 @@ image-clean: clean ##@Clean all existing images to rebuild docker images | grep "hyperledger/cello-" | awk '{print $3}' | xargs docker rmi -f start-docker-compose: - docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} up -d --force-recreate + docker-compose -f bootup/docker-compose-files/${COMPOSE_FILE} up -d --force-recreate --remove-orphans start: ##@Service Start service - if [ "$(DEPLOY_METHOD)" = "docker-compose" ]; then \ + if [ "$(CONFIG_DOCKER_COMPOSE_DEPLOY)" = "y" ]; then \ make start-docker-compose; \ else \ make start-k8s; \ @@ -238,7 +241,7 @@ generate-mock: make -C src/dashboard generate-mock stop: ##@Service Stop service - if [ "$(DEPLOY_METHOD)" = "docker-compose" ]; then \ + if [ "$(CONFIG_DOCKER_COMPOSE_DEPLOY)" = "y" ]; then \ make stop-docker-compose; \ else \ make stop-k8s; \ @@ -257,6 +260,15 @@ setup-master: ##@Environment Setup dependency for master node setup-worker: ##@Environment Setup dependency for worker node cd scripts/worker_node && bash setup.sh $(WORKER_TYPE) +menuconfig: + MENUCONFIG_STYLE=aquatic python kconfig-lib/menuconfig.py + +oldconfig: + python kconfig-lib/oldconfig.py + +alldefconfig: + python kconfig-lib/alldefconfig.py + help: ##@other Show this help. @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) diff --git a/bootup/docker-compose-files/docker-compose-dev.yml b/bootup/docker-compose-files/docker-compose-dev.yml index fffb7a8cb..cfb0456ad 100644 --- a/bootup/docker-compose-files/docker-compose-dev.yml +++ b/bootup/docker-compose-files/docker-compose-dev.yml @@ -42,21 +42,21 @@ services: - postgres-server - redis environment: - - WEBROOT=${API_ENGINE_WEBROOT} + - WEBROOT=${CONFIG_API_ENGINE_WEBROOT} - DEBUG=True - - DB_USER=${POSTGRES_USER} - - DB_PASSWORD=${POSTGRES_PASSWORD} + - DB_USER=${CONFIG_POSTGRES_USER} + - DB_PASSWORD=${CONFIG_POSTGRES_PASSWORD} - DB_NAME=api-engine - DB_HOST=postgres-server - DB_PORT=5432 - - ADMIN_TOKEN=$API_ENGINE_ADMIN_TOKEN + - ADMIN_TOKEN=${CONFIG_API_ENGINE_ADMIN_TOKEN} - CELERY_BROKER_URL=redis://redis - - ADMIN_USERNAME=$API_ENGINE_ADMIN_USERNAME - - ADMIN_PASSWORD=$API_ENGINE_ADMIN_PASSWORD - - ADMIN_EMAIL=$API_ENGINE_ADMIN_EMAIL - - API_VERSION=$API_VERSION + - ADMIN_USERNAME=${CONFIG_API_ENGINE_ADMIN_USERNAME} + - ADMIN_PASSWORD=${CONFIG_API_ENGINE_ADMIN_PASSWORD} + - ADMIN_EMAIL=${CONFIG_API_ENGINE_ADMIN_EMAIL} + - API_VERSION=${CONFIG_API_VERSION} ports: - - "${API_ENGINE_SERVICE_PORT}:8080" + - "${CONFIG_API_ENGINE_SERVICE_PORT}:8080" volumes: - $ROOT_PATH/src/api-engine:/var/www/server - /var/run/docker.sock:/var/run/docker.sock @@ -71,18 +71,18 @@ services: - postgres-server - redis environment: - - WEBROOT=${API_ENGINE_WEBROOT} + - WEBROOT=${CONFIG_API_ENGINE_WEBROOT} - DEBUG=True - - DB_USER=${POSTGRES_USER} - - DB_PASSWORD=${POSTGRES_PASSWORD} + - DB_USER=${CONFIG_POSTGRES_USER} + - DB_PASSWORD=${CONFIG_POSTGRES_PASSWORD} - DB_NAME=api-engine - DB_HOST=postgres-server - DB_PORT=5432 - - ADMIN_TOKEN=$API_ENGINE_ADMIN_TOKEN + - ADMIN_TOKEN=${CONFIG_API_ENGINE_ADMIN_TOKEN} - CELERY_BROKER_URL=redis://redis - - API_VERSION=$API_VERSION + - API_VERSION=${CONFIG_API_VERSION} - RUN_MODE=task - - DOCKER_HOST=$API_DOCKER_HOST + - DOCKER_HOST=${CONFIG_API_DOCKER_HOST} volumes: - $ROOT_PATH/src/api-engine:/var/www/server - /var/run/docker.sock:/var/run/docker.sock @@ -94,6 +94,6 @@ services: - api-engine environment: - API_PROXY=http://api-engine:8080/engine - - SERVICE_PORT=$API_ENGINE_SERVICE_PORT + - SERVICE_PORT=${CONFIG_API_ENGINE_SERVICE_PORT} ports: - - "${DASHBOARD_SERVICE_PORT}:80" + - "${CONFIG_DASHBOARD_SERVICE_PORT}:80" diff --git a/bootup/docker-compose-files/docker-compose.yml b/bootup/docker-compose-files/docker-compose.yml index 0ef4282c5..589a98495 100644 --- a/bootup/docker-compose-files/docker-compose.yml +++ b/bootup/docker-compose-files/docker-compose.yml @@ -22,10 +22,10 @@ services: links: - api-engine ports: - - "${API_ENGINE_SERVICE_PORT}:80" + - "${CONFIG_API_ENGINE_SERVICE_PORT}:80" environment: - UWSGI_SERVER_HOST=api-engine - - URL_PREFIX=${API_ENGINE_WEBROOT} + - URL_PREFIX=${CONFIG_API_ENGINE_WEBROOT} volumes: - /opt/cello/api-engine/media:/var/www/media diff --git a/kconfig-lib/alldefconfig.py b/kconfig-lib/alldefconfig.py new file mode 100644 index 000000000..56c4caa92 --- /dev/null +++ b/kconfig-lib/alldefconfig.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2018-2019, Ulf Magnusson +# SPDX-License-Identifier: ISC + +""" +Writes a configuration file where all symbols are set to their their default +values. + +The default output filename is '.config'. A different filename can be passed in +the KCONFIG_CONFIG environment variable. + +Usage for the Linux kernel: + + $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/alldefconfig.py +""" +import kconfiglib + + +def main(): + kconf = kconfiglib.standard_kconfig(__doc__) + kconf.load_allconfig("alldef.config") + print(kconf.write_config()) + + +if __name__ == "__main__": + main() diff --git a/kconfig-lib/kconfiglib.py b/kconfig-lib/kconfiglib.py new file mode 100644 index 000000000..99132136b --- /dev/null +++ b/kconfig-lib/kconfiglib.py @@ -0,0 +1,7250 @@ +# Copyright (c) 2011-2019, Ulf Magnusson +# SPDX-License-Identifier: ISC + +""" +Overview +======== + +Kconfiglib is a Python 2/3 library for scripting and extracting information +from Kconfig (https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt) +configuration systems. + +See the homepage at https://github.com/ulfalizer/Kconfiglib for a longer +overview. + +Since Kconfiglib 12.0.0, the library version is available in +kconfiglib.VERSION, which is a (, , ) tuple, e.g. +(12, 0, 0). + + +Using Kconfiglib on the Linux kernel with the Makefile targets +============================================================== + +For the Linux kernel, a handy interface is provided by the +scripts/kconfig/Makefile patch, which can be applied with either 'git am' or +the 'patch' utility: + + $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | git am + $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | patch -p1 + +Warning: Not passing -p1 to patch will cause the wrong file to be patched. + +Please tell me if the patch does not apply. It should be trivial to apply +manually, as it's just a block of text that needs to be inserted near the other +*conf: targets in scripts/kconfig/Makefile. + +Look further down for a motivation for the Makefile patch and for instructions +on how you can use Kconfiglib without it. + +If you do not wish to install Kconfiglib via pip, the Makefile patch is set up +so that you can also just clone Kconfiglib into the kernel root: + + $ git clone git://github.com/ulfalizer/Kconfiglib.git + $ git am Kconfiglib/makefile.patch (or 'patch -p1 < Kconfiglib/makefile.patch') + +Warning: The directory name Kconfiglib/ is significant in this case, because +it's added to PYTHONPATH by the new targets in makefile.patch. + +The targets added by the Makefile patch are described in the following +sections. + + +make kmenuconfig +---------------- + +This target runs the curses menuconfig interface with Python 3. As of +Kconfiglib 12.2.0, both Python 2 and Python 3 are supported (previously, only +Python 3 was supported, so this was a backport). + + +make guiconfig +-------------- + +This target runs the Tkinter menuconfig interface. Both Python 2 and Python 3 +are supported. To change the Python interpreter used, pass +PYTHONCMD= to 'make'. The default is 'python'. + + +make [ARCH=] iscriptconfig +-------------------------------- + +This target gives an interactive Python prompt where a Kconfig instance has +been preloaded and is available in 'kconf'. To change the Python interpreter +used, pass PYTHONCMD= to 'make'. The default is 'python'. + +To get a feel for the API, try evaluating and printing the symbols in +kconf.defined_syms, and explore the MenuNode menu tree starting at +kconf.top_node by following 'next' and 'list' pointers. + +The item contained in a menu node is found in MenuNode.item (note that this can +be one of the constants kconfiglib.MENU and kconfiglib.COMMENT), and all +symbols and choices have a 'nodes' attribute containing their menu nodes +(usually only one). Printing a menu node will print its item, in Kconfig +format. + +If you want to look up a symbol by name, use the kconf.syms dictionary. + + +make scriptconfig SCRIPT=