创建镜像
支持通过 SDK 使用不同的构建方式创建 siflow 平台镜像
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="base_siflow_image",
build_method="baseSiflowImage",
basic_image_type="custom",
basic_image_url="registry-cn-beijing.siflow.cn/siflow/llama-factory:0.0.3-f81b76c",
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="base_dockerfile",
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="base_third_image",
build_method="baseThirdImage",
docker_hub_url="mysql:8.0",
description="CICD Method 3"
)
image_build_config4 = ImageBuildConfigRequest(
commit_id="base_exist_image",
build_method="baseExistImage",
docker_hub_url="registry-cn-beijing.siflow.cn/siflow/llama-factory:0.0.3-f81b76c",
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)
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| name | str | 是 | 镜像名称 |
| version | str | 是 | 镜像版本 |
| minor_category | str | 是 | 镜像分类(class) |
| image_build_type | str | 是 | 镜像类型(custom 为自定义镜像,preset 为内置镜像) |
| image_build_region | str | 是 | 构建镜像的资源地域 |
| image_build_cluster | str | 是 | 构建镜像的资源集群 |
| image_build_config | obj | 是 | 构建配置 |
| resource_pool | str | 是 | 使用专属构建资源池时必填;请联系管理员确认资源池名称 |
| instances | obj | 是 | 使用专属构建资源池时必填;指定要使用的实例名称和实例数量 |
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| commit_id | str | 是 | 镜像构建代码的 commit id |
| build_method | str | 是 | 构建方式: - baseSiflowImage - baseDockerfile - baseThirdImage - baseExistImage |
| basic_image_type | str | 否 | 基础镜像类型(custom/preset),使用 baseSiflowImage 构建时必填 |
| basic_image_url | str | 否 | 基础镜像 URL,使用 baseSiflowImage 方式构建时必填 |
| dockerfile_content | str | 否 | Dockerfile 内容;使用 baseDockerfile 构建时,dockerfile_path 或本字段须提供其一 |
| dockerfile_path | str | 否 | Dockerfile 的绝对路径。使用 baseDockerfile 构建时,本字段或 dockerfile_content 须提供其一 |
| docker_hub_url | str | 否 | 第三方镜像 URL,使用 baseThirdImage 或 baseExistImage 构建时必填 |
| description | str | 否 | 镜像描述详情 |
| pip | str | 否 | 安装 pip,格式为:requests==2.31.0, flask==2.3.3 |
| apt | str | 否 | 安装 apt 软件包,格式为:curl=7.68.0-1ubuntu2.25, wget=1.20.3-1ubuntu2.1 |
| dockerfile_arg | list[obj] | 否 | 使用 baseDockerfile 方式构建镜像时的构建参数 |
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| key | str | 是 | 构建参数键 |
| value | str | 是 | 构建参数值 |
| hidden | bool | 否 | 是否隐藏构建参数值;未指定时默认为 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)
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| page | int | 否 | 分页参数 |
| pageSize | int | 否 | 分页参数 |
| minor_category | str | 否 | 镜像分类(class) |
| image_build_type | str | 否 | 镜像类型(custom 为自定义镜像,preset 为内置镜像) |
| image_build_region | str | 否 | 构建镜像的资源地域 |
| image_build_cluster | str | 否 | 构建镜像的资源集群 |
| keyword | str | 否 | 镜像名称或镜像版本(支持模糊搜索) |
镜像共享
通过 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=["xxx", "xxx1"]
)
print(share)
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| image_id | int | 是 | 镜像 ID,可通过查询镜像列表获取 |
| is_show_all_users | bool | 是 | 普通用户不允许将该参数设置为 true,建议留空。对于管理员用户,设置为 true 时共享给所有组成员,设置为 false 时共享给指定用户。 |
| users | list[str] | 否 | is_show_all_users=false 时必填,指定要共享的用户列表;当 is_show_all_users=true 时本字段将被忽略 |
# succeed
{
"msg": "request succeed!",
"status": true,
"traceID": "9392e9724a48e3170dd1011d838071e6"
}
# failed
{
"msg": "xxx not exist in org xxx, err : record not found",
"status": false,
"traceID": "04e0c47aeee2a4c4b7967894c550486a"
}
| 参数名 | 类型 | 说明 |
|---|---|---|
| status | bool | 是否成功 |
| msg | str | 结果详情 |
| traceID | str | Traceid |
结构定义
RegisterImageResponse
| 参数名 | 类型 | 说明 |
|---|---|---|
| id | int | |
| name | str | 镜像名称 |
| major_category | str | ”siflow” |
| minor_category | str | 镜像分类(class) |
| version | str | 镜像版本 |
| owner | str | 镜像创建者 |
| description | str | 镜像详情 |
| is_deleted | bool | 是否删除 |
| image_build_type | str | 镜像类型(custom 为自定义镜像,preset 为内置镜像) |
| image_build_org_name | str | 镜像创建者所属租户 |
| image_build_job_name | str | 构建镜像的作业名称 |
| image_build_region | str | 构建镜像的资源地域 |
| image_build_cluster | str | 构建镜像的资源集群 |
| created_at | str | 镜像创建时间 |
ImageListResponse
| 参数名 | 类型 | 说明 |
|---|---|---|
| id | int | |
| name | str | 镜像名称 |
| version | str | 镜像版本 |
| major_category | str | ”siflow” |
| minor_category | str | 镜像分类(class) |
| owner | str | 镜像创建者 |
| description | str | 镜像详情 |
| is_deleted | bool | 是否删除 |
| image_build_type | str | 镜像类型(custom 为自定义镜像,preset 为内置镜像) |
| image_build_org_name | str | 镜像创建者所属租户 |
| image_build_job_name | str | 构建镜像的作业名称 |
| image_build_region | str | 构建镜像的资源地域 |
| image_build_cluster | str | 构建镜像的资源集群 |
| created_at | str | 镜像创建时间 |
| updated_at | str | 镜像修改时间 |
| is_show_all_users | bool | 是否对所有组成员可见 |
| users | List[str] | 可见用户列表 |
| cluster_images_url | str | 镜像 URL |
| show_clusters | List[str] | 已部署的集群列表 |
| no_show_clusters | List[str] | 尚未部署的集群列表 |
