Skip to content

Commit

Permalink
feat: 沙盒开发测试环境 (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepSheepChen authored Nov 1, 2024
1 parent e53fed3 commit 412f2c0
Show file tree
Hide file tree
Showing 27 changed files with 1,721 additions and 53 deletions.
57 changes: 48 additions & 9 deletions apiserver/paasng/paas_wl/bk_app/dev_sandbox/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.

from typing import List
from typing import Dict, List

from django.conf import settings

from .entities import IngressPathBackend, ServicePortPair

_ingress_service_conf = [
_dev_sandbox_ingress_service_conf = [
# dev sandbox 中 devserver 的路径与端口映射
{
"path_prefix": "/devserver/",
Expand All @@ -30,23 +30,62 @@
"target_port": settings.DEV_SANDBOX_DEVSERVER_PORT,
},
# dev sandbox 中 saas 应用的路径与端口映射
{"path_prefix": "/", "service_port_name": "app", "port": 80, "target_port": settings.CONTAINER_PORT},
{"path_prefix": "/app/", "service_port_name": "app", "port": 80, "target_port": settings.CONTAINER_PORT},
]


DEV_SANDBOX_SVC_PORT_PAIRS: List[ServicePortPair] = [
ServicePortPair(name=conf["service_port_name"], port=conf["port"], target_port=conf["target_port"])
for conf in _ingress_service_conf
for conf in _dev_sandbox_ingress_service_conf
]

_code_editor_ingress_service_conf = [
# code editor 的路径与端口映射
{
"path_prefix": "/code-editor/",
"service_port_name": "code-editor",
"port": 10251,
"target_port": settings.CODE_EDITOR_PORT,
},
]

CODE_SVC_PORT_PAIRS: List[ServicePortPair] = [
ServicePortPair(name=conf["service_port_name"], port=conf["port"], target_port=conf["target_port"])
for conf in _code_editor_ingress_service_conf
]


def get_ingress_path_backends(service_name: str) -> List[IngressPathBackend]:
"""get ingress path backends from _ingress_service_conf with service_name"""
def get_ingress_path_backends(
service_name: str, service_confs: List[Dict], dev_sandbox_code: str = ""
) -> List[IngressPathBackend]:
"""get ingress path backends from service_confs with service_name and dev_sandbox_code
:param service_name: Service name
:param dev_sandbox_code: dev sandbox code.
:param service_confs: service configs
"""
if not dev_sandbox_code:
return [
IngressPathBackend(
path_prefix=conf["path_prefix"],
service_name=service_name,
service_port_name=conf["service_port_name"],
)
for conf in service_confs
]

return [
IngressPathBackend(
path_prefix=conf["path_prefix"],
path_prefix=f"/dev_sandbox/{dev_sandbox_code}{conf['path_prefix']}",
service_name=service_name,
service_port_name=conf["service_port_name"],
)
for conf in _ingress_service_conf
for conf in service_confs
]


def get_dev_sandbox_ingress_path_backends(service_name: str, dev_sandbox_code: str = "") -> List[IngressPathBackend]:
return get_ingress_path_backends(service_name, _dev_sandbox_ingress_service_conf, dev_sandbox_code)


def get_code_editor_ingress_path_backends(service_name: str, dev_sandbox_code: str = "") -> List[IngressPathBackend]:
return get_ingress_path_backends(service_name, _code_editor_ingress_service_conf, dev_sandbox_code)
31 changes: 31 additions & 0 deletions apiserver/paasng/paas_wl/bk_app/dev_sandbox/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
# Licensed under the MIT License (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions and
# limitations under the License.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.

from blue_krill.data_types.enum import EnumField, StrStructuredEnum


class SourceCodeFetchMethod(StrStructuredEnum):
HTTP = EnumField("HTTP")
GIT = EnumField("GIT")
BK_REPO = EnumField("BK_REPO")


class DevSandboxStatus(StrStructuredEnum):
"""沙箱状态"""

ACTIVE = EnumField("active", label="活跃")
ERROR = EnumField("error", label="错误")
Loading

0 comments on commit 412f2c0

Please sign in to comment.