Skip to content

Commit

Permalink
feature: PaaS 容器部署适配 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Sep 14, 2021
1 parent 551e0ee commit 9963971
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 82 deletions.
104 changes: 104 additions & 0 deletions app_desc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
spec_version: 2
app_version: "{{APP_VERSION}}"
app:
region: default
bk_app_code: "bk_nodeman"
bk_app_name: 节点管理
market:
category: 运维工具
introduction: 通过节点管理,可以对蓝鲸体系中的gse agent进行管理,包括状态查询、版本更新、配置管理、健康检查、进程管理等。
display_options:
width: 1300
height: 720
is_win_maximize: True
open_mode: "new_tab"
modules:
default:
is_default: True
source_dir: src
language: Python
services:
- name: mysql
- name: bkrepo
env_variables:
- key: ENGINE_REGION
value: "open"
description: 暂时避开开发框架的问题,新版PaaS该值设置为default
- key: PIP_VERSION
value: "20.2.3"
description: 固化pip版本
processes:
web:
command: gunicorn wsgi -w 4 -b :5000 --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
plan: 4C2G5R
replicas: 5

svc_discovery:
bk_saas:
- bk_app_code: "bk_iam"
- bk_app_code: "bk_nodeman"
module_name: "backend"
- bk_app_code: "bk_nodeman"
module_name: "default"

backend:
is_default: False
source_dir: src
language: Python
services:
- name: rabbitmq
- name: redis
- name: bkrepo
shared_from: default
- name: mysql
shared_from: default
env_variables:
- key: REDIS_MODE
value: "standalone"
description: 后台配置的Redis模式
- key: BACKEND_CONFIG
value: "True"
description: 是否启用后台配置,用于同一份代码区分SaaS和后台的差异化配置
- key: ENGINE_REGION
value: "open"
description: 暂时避开开发框架的问题,新版PaaS该值设置为default
- key: PIP_VERSION
value: "20.2.3"
description: 固化pip版本
- key: IS_PAAS_DEPLOY
value: "True"
description: 是否基于PaaS部署

processes:
backend-web:
command: gunicorn --timeout 300 -w 4 -b :5000 -k gevent wsgi:application --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
plan: 4C2G5R
replicas: 5
celery-beat:
command: celery -A apps.backend beat -l info
plan: 4C2G5R
replicas: 1
worker-d:
command: celery -A apps.backend worker -Q default --autoscale=8,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-b:
command: celery -A apps.backend worker -Q backend --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-b-a:
command: celery -A apps.backend worker -Q backend_additional_task --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p:
command: celery -A apps.backend worker -Q pipeline,pipeline_priority -n pipeline_worker@%h --maxtasksperchild=50 --autoscale=16,2 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p-s:
command: celery -A apps.backend worker -Q service_schedule,service_schedule_priority -n schedule_worker@%h --maxtasksperchild=50 -c 50 -P eventlet -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p-a:
command: celery -A apps.backend worker -Q pipeline_additional_task,pipeline_additional_task_priority -n common_worker@%h -l info --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
4 changes: 2 additions & 2 deletions apps/node_man/handlers/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IamHandler(APIModel):
]

if settings.USE_IAM:
_iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_IAM_ESB_PAAS_HOST)
_iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)
else:
_iam = object

Expand Down Expand Up @@ -322,7 +322,7 @@ def fetch_redirect_url(self, params, username):
apply_info["related_resource_types"][0]["instances"] = instances
data["actions"].append(apply_info)
ok, message, result = IamHandler._iam._client.get_apply_url(bk_token="", bk_username=username, data=data)
return result or settings.BK_IAM_URL
return result or settings.BK_IAM_SAAS_HOST

@staticmethod
def return_resource_instance_creator(resource_id, instance_id, instance_name, creator):
Expand Down
2 changes: 1 addition & 1 deletion apps/node_man/iam_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class IamRegister(object):
]

def __init__(self):
self._iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_PAAS_INNER_HOST)
self._iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)

def register_system(self):
# ***需要将placeholder改为内网访问地址***
Expand Down
4 changes: 2 additions & 2 deletions apps/node_man/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
cmdb,
debug,
host,
install_channel,
job,
meta,
permission,
plugin,
policy,
tjj,
install_channel,
)
from apps.node_man.views.healthz import HealthzViewSet
from apps.node_man.views.host_v2 import HostV2ViewSet
from apps.node_man.views.plugin import GsePluginViewSet
from apps.node_man.views.plugin_v2 import PluginV2ViewSet

iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_PAAS_INNER_HOST)
iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)

router = routers.DefaultRouter(trailing_slash=True)

Expand Down
2 changes: 1 addition & 1 deletion blueking/component/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

APP_CODE = settings.APP_ID
SECRET_KEY = settings.APP_TOKEN
COMPONENT_SYSTEM_HOST = getattr(settings, "BK_PAAS_INNER_HOST", settings.BK_PAAS_HOST)
COMPONENT_SYSTEM_HOST = getattr(settings, "BK_COMPONENT_API_URL", settings.BK_PAAS_INNER_HOST)
DEFAULT_BK_API_VER = getattr(settings, "DEFAULT_BK_API_VER", "v2")
except Exception:
APP_CODE = ""
Expand Down
3 changes: 1 addition & 2 deletions common/api/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

from django.conf import settings

BK_PAAS_HOST = settings.BK_PAAS_INNER_HOST or settings.BK_PAAS_HOST or ""
ESB_PREFIX_V2 = os.getenv("ESB_PREFIX_V2") or "/api/c/compapi/v2/"


def gen_api_root(api_gw_env_key: str, suffix: str) -> str:
"""生成API根路径,首先从环境变量获取,若环境变量没有,则按默认规则拼接"""
return os.getenv(api_gw_env_key) or f"{BK_PAAS_HOST}/{ESB_PREFIX_V2}/{suffix}/"
return os.getenv(api_gw_env_key) or f"{settings.BK_COMPONENT_API_URL}/{ESB_PREFIX_V2}/{suffix}/"


# 蓝鲸平台模块域名
Expand Down
Loading

0 comments on commit 9963971

Please sign in to comment.