更新时间:2023-03-16 GMT+08:00
分享

创建组件

概述

本文通过调用创建组件接口创建一个组件。

API的调用方法请参见3 如何调用API

操作步骤

  1. 创建组件。

    调用创建组件接口,请求示例如下:

    curl -k -H "Content-Type:application/json" -H "X-Environment-ID: $env_id" -H "X-Auth-Token:$Token" -X POST "https://{cae_endpoint}v1/{project_id}/cae/applications/{application_id}/components" -d '{
        "api_version": "v1",
        "kind": "Component",
        "metadata": {
            "name": "demo-jar",
            "annotations": {
                "version": "1.0.0"
            }
        },
        "spec": {
            "runtime": "Java8",
            "build": {
                "archive": {
                    "artifact_namespace": "target_namespace"
                },
                "parameters": {
                    "base_image": "openjdk:8u181-jdk-alpine",   
                    "build_env": "java-8"
                }
            },
            "source": {
                "type": "softwarePackage",
                "sub_type": "BinObs",
                "url": "https://xx/demo.jar"
            },
            "resource_limit": {
               "cpu_limit": "500m",
               "memory_limit": "1Gi"
            },
            "replica": 1
        }
    }'

    返回结果:

    {
        "api_version": "v1",
        "kind": "Component",
        "metadata": {
            "id": "908aabb3-0b50-4116-8e83-a6933ec1884c",
            "name": "demo-jar",
            "annotations": {
                "version": "1.0.0"
            },
            "created_at": "2022-07-05T08:28:24.4885176Z",
            "updated_at": "2022-07-05T08:28:24.4885176Z"
        },
        "spec": {
            "runtime": "Java8",
            "env_id": "50d18173-5df0-4db4-a2b6-8a428d42146b",
            "replica": 1,
            "source": {
                "type": "softwarePackage",
                "sub_type": "BinObs",
                "url": "https://xx/demo.jar"
            },
            "build": {
                "archive": {
                    "artifact_namespace": "target_namespace"
                },
                "parameters": {
                    "base_image": "xxx"
                }
            },
            "access_info": null,
            "image_url": "",
            "available_replica": 0,
            "status": "",
            "build_log_id": ""
        }
    }

    得到的job_id,可以通过job_id获取对应的创建的状态。

相关文档