Пример #1
0
    def __init_market_app(self, tenant, region, user, app,
                          tenant_service_group_id, service_origin):
        """
        初始化应用市场创建的应用默认数据
        """
        is_slug = bool(app["image"].startswith('goodrain.me/runner')
                       and app["language"] not in ("dockerfile", "docker"))

        tenant_service = TenantServiceInfo()
        tenant_service.tenant_id = tenant.tenant_id
        tenant_service.service_id = make_uuid()
        tenant_service.service_cname = app_service.generate_service_cname(
            tenant, app["service_cname"], region)
        tenant_service.service_alias = "gr" + tenant_service.service_id[-6:]
        tenant_service.creater = user.pk
        if is_slug:
            tenant_service.image = app["image"]
        else:
            tenant_service.image = app.get("share_image", app["image"])
        tenant_service.cmd = app.get("cmd", "")
        tenant_service.service_region = region
        tenant_service.service_key = app["service_key"]
        tenant_service.desc = "market app "
        tenant_service.category = "app_publish"
        tenant_service.setting = ""
        tenant_service.extend_method = app["extend_method"]
        tenant_service.env = ","
        tenant_service.min_node = app["extend_method_map"]["min_node"]
        tenant_service.min_memory = app["extend_method_map"]["min_memory"]
        tenant_service.min_cpu = baseService.calculate_service_cpu(
            region, tenant_service.min_memory)
        tenant_service.inner_port = 0
        tenant_service.version = app["version"]
        if is_slug:
            if app.get("service_slug", None):
                tenant_service.namespace = app["service_slug"]["namespace"]
        else:
            if app.get("service_image", None):
                tenant_service.namespace = app["service_image"]["namespace"]
        tenant_service.update_version = 1
        tenant_service.port_type = "multi_outer"
        tenant_service.create_time = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        tenant_service.deploy_version = ""
        tenant_service.git_project_id = 0
        tenant_service.service_type = "application"
        tenant_service.total_memory = tenant_service.min_node * tenant_service.min_memory
        tenant_service.volume_mount_path = ""
        tenant_service.host_path = ""
        tenant_service.code_from = ""
        tenant_service.language = ""
        tenant_service.service_source = "market"
        tenant_service.create_status = "creating"
        tenant_service.service_origin = service_origin
        tenant_service.tenant_service_group_id = tenant_service_group_id
        self.__init_service_source(tenant_service, app)
        # 存储并返回
        tenant_service.save()
        return tenant_service
Пример #2
0
 def __init_compose_service(self, tenant, user, service_cname, image,
                            region):
     """
     初始化docker compose创建的应用默认数据
     """
     tenant_service = TenantServiceInfo()
     tenant_service.tenant_id = tenant.tenant_id
     tenant_service.service_id = make_uuid()
     tenant_service.service_cname = app_service.generate_service_cname(
         tenant, service_cname, region)
     tenant_service.service_alias = "gr" + tenant_service.service_id[-6:]
     tenant_service.creater = user.pk
     tenant_service.image = image
     tenant_service.service_region = region
     tenant_service.service_key = "0000"
     tenant_service.desc = "docker compose application"
     tenant_service.category = "app_publish"
     tenant_service.setting = ""
     tenant_service.extend_method = "stateless"
     tenant_service.env = ","
     tenant_service.min_node = 1
     tenant_service.min_memory = 128
     tenant_service.min_cpu = baseService.calculate_service_cpu(region, 128)
     tenant_service.inner_port = 0
     tenant_service.version = "latest"
     tenant_service.namespace = "goodrain"
     tenant_service.update_version = 1
     tenant_service.port_type = "multi_outer"
     tenant_service.create_time = datetime.datetime.now().strftime(
         '%Y-%m-%d %H:%M:%S')
     tenant_service.deploy_version = ""
     tenant_service.git_project_id = 0
     tenant_service.service_type = "application"
     tenant_service.total_memory = 128
     tenant_service.volume_mount_path = ""
     tenant_service.host_path = "/grdata/tenant/" + tenant.tenant_id + "/service/" + tenant_service.service_id
     tenant_service.code_from = "image_manual"
     tenant_service.language = "docker-compose"
     tenant_service.service_source = AppConstants.DOCKER_COMPOSE
     tenant_service.create_status = "creating"
     # 保存并返回
     tenant_service.save()
     return tenant_service