Skip to content

Commit

Permalink
Merge pull request #170 from hightall/issue169
Browse files Browse the repository at this point in the history
feat: add menuconfig support for server deployment config
  • Loading branch information
hightall authored Jul 30, 2020
2 parents 5a5468c + 2bf9deb commit aa8a09c
Show file tree
Hide file tree
Showing 8 changed files with 10,959 additions and 23 deletions.
66 changes: 66 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -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
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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
Expand Down Expand Up @@ -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; \
Expand Down Expand Up @@ -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; \
Expand All @@ -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)

Expand Down
34 changes: 17 additions & 17 deletions bootup/docker-compose-files/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
4 changes: 2 additions & 2 deletions bootup/docker-compose-files/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions kconfig-lib/alldefconfig.py
Original file line number Diff line number Diff line change
@@ -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=<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()
Loading

0 comments on commit aa8a09c

Please sign in to comment.