跳转到主要内容

创建镜像

支持通过 SDK 使用不同的构建方式创建 siflow 平台镜像 sdk 代码示例如下:
from siflow import SiFlow
from siflow.types import ImageBuildConfigRequest, InstanceRequest, ImageBuildConfigArgRequest

# export SIFLOW_ACCESS_KEY_ID=xxx
# export SIFLOW_ACCESS_KEY_SECRET=xxx

client = SiFlow(region="xx", cluster="xx")

image_build_config1 = ImageBuildConfigRequest(
    commit_id="1234",
    build_method="baseSiflowImage",
    basic_image_type="custom",
    basic_image_url="registry-ap-southeast.scitix.ai/ai-infra/ubuntu:0.1.4-qwer",
    description="CICD Method 1"
)

dockerfile_arg = [
    ImageBuildConfigArgRequest(
        hidden=True,
        key="VERSION",
        value="0.0.1",
    ),
    ImageBuildConfigArgRequest(
        hidden=True,
        key="NAME",
        value="ubuntu",
    )
]

image_build_config2 = ImageBuildConfigRequest(
    commit_id="1234",
    build_method="baseDockerfile",
    dockerfile_content="FROM ubuntu:20.04\nCMD [\"echo\", \"Hello from minimal Ubuntu!\"]",
    #dockerfile_path="examples/Dockerfile",
    description="CICD Method 2",
    dockerfile_arg=dockerfile_arg
)

image_build_config3 = ImageBuildConfigRequest(
    commit_id="1234",
    build_method="baseThirdImage",
    docker_hub_url="mysql:8.0",
    description="CICD Method 3"
)

image_build_config4 = ImageBuildConfigRequest(
    commit_id="1234",
    build_method="baseExistImage",
    docker_hub_url="registry-ap-southeast.scitix.ai/ai-infra/ubuntu:0.1.4-qwer",
    description="CICD Method 4"
)

instances_config = [
    InstanceRequest(
        name="sci.c23-2",
        countPerPod=10
    )
]

imageInfo = client.images.create(
    name="test",
    version="0.0.8",
    major_category="siflow",
    minor_category="cicd",
    image_build_type="custom",
    image_build_region="xx",
    image_build_cluster="xx",
    image_build_config=image_build_config2,
    resource_pool="build-image-cpu",
    instances=instances_config
)
print(imageInfo)
参数说明:
参数名类型是否必填说明
namestr镜像名称
versionstr镜像版本
minor_categorystr镜像分类(class)
image_build_typestr镜像类型(custom 为自定义镜像,preset 为内置镜像)
image_build_regionstr构建镜像的资源地域
image_build_clusterstr构建镜像的资源集群
image_build_configobj构建配置
resource_poolstr使用专属构建资源池时必填;请联系管理员确认资源池名称
instancesobj使用专属构建资源池时必填;指定要使用的实例名称和实例数量

instances_config = [ 
  InstanceRequest(
    name=“sci.c23-2”,
    countPerPod=10
  )
]
image_build_config:
参数名类型是否必填说明
commit_idstr镜像构建代码的 commit id
build_methodstr构建方式:
- baseSiflowImage
- baseDockerfile
- baseThirdImage
- baseExistImage
basic_image_typestr基础镜像类型(custom/preset),使用 baseSiflowImage 构建时必填
basic_image_urlstr基础镜像 URL,使用 baseSiflowImage 方式构建时必填
dockerfile_contentstrDockerfile 内容;使用 baseDockerfile 构建时,dockerfile_path 或本字段须提供其一
dockerfile_pathstrDockerfile 的绝对路径。使用 baseDockerfile 构建时,本字段或 dockerfile_content 须提供其一
docker_hub_urlstr第三方镜像 URL,使用 baseThirdImage 或 baseExistImage 构建时必填
descriptionstr镜像描述详情
pipstr安装 pip,格式为:requests==2.31.0, flask==2.3.3
aptstr安装 apt 软件包,格式为:curl=7.68.0-1ubuntu2.25, wget=1.20.3-1ubuntu2.1
dockerfile_arglist[obj]使用 baseDockerfile 方式构建镜像时的构建参数
dockerfile_arg:
参数名类型是否必填说明
keystr构建参数键
valuestr构建参数值
hiddenbool是否隐藏构建参数值;未指定时默认为 false

获取镜像列表

支持通过 SDK 查询镜像列表
from siflow import SiFlow
from siflow.types import ImageBuildConfigRequest

# export SIFLOW_ACCESS_KEY_ID=xxx
# export SIFLOW_ACCESS_KEY_SECRET=xxx

client = SiFlow(region="xx", cluster="xx")
images = client.images.list(
    page=1,
    pageSize=5,
    minor_category="",  # class
    image_build_type="custom",  # preset/custom
    image_build_cluster="",
    image_build_region="",
    keyword=""
)
for image in images:
    print(image)
参数说明:
参数名类型是否必填说明
pageint分页参数
pageSizeint分页参数
minor_categorystr镜像分类(class)
image_build_typestr镜像类型(custom 为自定义镜像,preset 为内置镜像)
image_build_regionstr构建镜像的资源地域
image_build_clusterstr构建镜像的资源集群
keywordstr镜像名称或镜像版本(支持模糊搜索)

镜像共享

通过 SDK 新创建的镜像可以共享给所有组用户或特定指定用户
from siflow import SiFlow

# export SIFLOW_ACCESS_KEY_ID=xxx
# export SIFLOW_ACCESS_KEY_SECRET=xxx

client = SiFlow(region="ap-southeast", cluster="aries")

share = client.images.share(
    image_id=xxx,
    is_show_all_users=False,
    users=["bslu", "bslu1"]
)

print(share)
参数名类型是否必填说明
image_idint镜像 ID,可通过查询镜像列表获取
is_show_all_usersbool普通用户不允许将该参数设置为 true,建议留空。对于管理员用户,设置为 true 时共享给所有组成员,设置为 false 时共享给指定用户。
userslist[str]is_show_all_users=false 时必填,指定要共享的用户列表;当 is_show_all_users=true 时本字段将被忽略
# succeed
{
    "msg": "request succeed!",
    "status": true,
    "traceID": "9392e9724a48e3170dd1011d838071e6"
}

# failed
{
    "msg": "bslu2 not exist in org ai-infra, err : record not found",
    "status": false,
    "traceID": "04e0c47aeee2a4c4b7967894c550486a"
}
参数名类型说明
statusbool是否成功
msgstr结果详情
traceIDstrTraceid

结构定义

RegisterImageResponse

参数名类型说明
idint
namestr镜像名称
major_categorystr”siflow”
minor_categorystr镜像分类(class)
versionstr镜像版本
ownerstr镜像创建者
descriptionstr镜像详情
is_deletedbool是否删除
image_build_typestr镜像类型(custom 为自定义镜像,preset 为内置镜像)
image_build_org_namestr镜像创建者所属租户
image_build_job_namestr构建镜像的作业名称
image_build_regionstr构建镜像的资源地域
image_build_clusterstr构建镜像的资源集群
created_atstr镜像创建时间

ImageListResponse

参数名类型说明
idint
namestr镜像名称
versionstr镜像版本
major_categorystr”siflow”
minor_categorystr镜像分类(class)
ownerstr镜像创建者
descriptionstr镜像详情
is_deletedbool是否删除
image_build_typestr镜像类型(custom 为自定义镜像,preset 为内置镜像)
image_build_org_namestr镜像创建者所属租户
image_build_job_namestr构建镜像的作业名称
image_build_regionstr构建镜像的资源地域
image_build_clusterstr构建镜像的资源集群
created_atstr镜像创建时间
updated_atstr镜像修改时间
is_show_all_usersbool是否对所有组成员可见
usersList[str]可见用户列表
cluster_images_urlstr镜像 URL
show_clustersList[str]已部署的集群列表
no_show_clustersList[str]尚未部署的集群列表