ECS image deployment package

更新时间:
复制 MD 格式

This topic explains how an ECS image deployment package works and guides you through creating and using one.

Background

  • Why use an ECS image deployment package?

    When deploying services, you often use ECS images to support deployments in multiple regions. However, because ECS images are region-specific, you must replicate these images in each target region and specify the corresponding image ID in the template for each region. This process, which includes image replication, mapping, and permission management, must be repeated for every new image version, which makes the process complex and tedious.

  • Benefits of an ECS image deployment package

    As a service provider, you only need to configure the association for the ECS image deployment package in the Compute Nest console.

    • Image replication: Compute Nest replicates your source image to a shared Compute Nest account and then replicates it across multiple regions under that account.

    • Image mapping: Compute Nest checks whether an ImageId is set in the template. If it is, you can associate the ImageId with an ECS image deployment package on the service details page. When a user deploys the service, Compute Nest identifies the deployment region and automatically replaces the ImageId in the template with the correct image ID for that region, which enables dynamic image mapping.

    • Permission management: The permissions of a deployment package are determined by the associated service. If a deployment package is not associated with any service, it is private and available only to the service provider. If it is associated with at least one public service, the deployment package becomes public. If it is associated only with private services, it remains private. In this case, if you add a whitelist to the service, the whitelist also applies to the deployment package.

Limitations

An ECS image deployment package can replace the image ID for the following cloud resources in templates.

ROS

If you use ROS for deployment, you must include the image ID, ImageId, in the Resource section of the ROS template.

Terraform

If you use Terraform for deployment, you must include the image ID, image_id, in the template.

  • Supported cloud resource types:

  • Resource property: image_id.

  • The value of the resource attribute must be a string (the image ID). Template input parameters or other built-in template functions are not allowed.

Create and use a deployment package

Prerequisites

Prepare an ECS image. Compute Nest supports custom images and Alibaba Cloud Marketplace images. Choose the type that fits your needs.

Create an ECS image deployment package

  1. Configure basic information for the deployment package.

    1. Log on to the Compute Nest console. In the left-side navigation pane, choose Service Deployment Package. On the Packages tab, click Create Deployment Package.

    2. In the Basic Information section, configure the following parameters.

      Parameter

      Description

      Deployment Package Name

      The name can contain Chinese characters, English letters, digits, and underscores (_). The name must be 3 to 128 characters long, where a Chinese character counts as two characters. The deployment package name cannot be changed after creation.

      Version Name

      The name can contain Chinese characters, English letters, digits, and underscores (_). The name must be 3 to 50 characters long, where a Chinese character counts as two characters.

      Description

      The description must be 10 to 500 characters long. A Chinese character counts as two characters.

      Resource Group

      Select the resource group to which the deployment package belongs.

      Resource groups allow you to group your cloud resources by usage, permissions, or ownership, enabling hierarchical resource management for multiple users and projects within an organization. For more information, see resource groups.

      Tag Settings

      Select or enter a complete tag key and tag value to add a tag to the deployment package. You can bind up to 20 tags to a resource. If no tag keys or values are available, you can create a custom tag. For more information, see Create and bind a custom tag.

  2. Configure the ECS image deployment package.

    1. In the Deployment Package Content section, set Deployment Package Type to ECS Image. For Image Type and Select Product, select the image that you prepared in the prerequisites.

    2. In the Distribution Settings section, Distribution Region. This example uses All Regions.

      Important

      You must select at least one distribution region for an ECS image deployment package.

    3. Click Publish Deployment Package.

      Once published, a deployment package version cannot be modified. To make changes, you must create a new version or a new deployment package.

      Note
      • To test the deployment package, click Save Deployment Package. After testing is complete, click Publish Deployment Package.

      • If the deployment package is not published, you cannot test it in the configured distribution regions. You can only test it in the region where the image resides.

  3. View the deployment package.

    1. Return to the Service deployment package page. Click the name of the newly created deployment package to go to the Deployment Package Details page and view the deployment progress.

    2. When the status changes to Available, click View to get the Distribution Results of the ECS image deployment package.

    Note

    Image distribution time can range from a few minutes to several hours, depending on the region and image size.

Use an ECS image deployment package

This section uses a private service as an example and focuses on configuring the ECS image deployment package when you create a service.

  1. Log on to the Compute Nest console.

  2. In the left-side navigation pane, click My Services. On the Created Services tab of the My Services page, click Create Service.

  3. On the Create New Service page, select Custom launch as the creation method, select Private Service as the service type, and click Next: Configure Settings.

  4. On the Configure Service page, fill in the basic service information, and then provide a template. This section uses an ROS template as an example.

  5. If the Template Content includes the image ID ImageId, the Deployment package association section appears, where you can Set image association.

    The system automatically parses the image information from the template, displaying the Image to be replaced as centos_7 and the Associated resource as EcsInstanceGroup`. Click Select deployment package to complete the association.

    Sample template

    Note

    This sample template is for testing purposes only.

    ROSTemplateFormatVersion: '2015-09-01'
    Description:
      en: This template deploys a single instance from a custom image with a data disk.
        It supports creating a new VPC or specifying an existing one. A public IP is optional.
    Conditions:
      CreateVpcConditions:
        Fn::Equals:
        - true
        - Ref: WhetherCreateVpc
      IfAllocatePublicIP:
        Fn::Equals:
        - Ref: AllocatePublicIP
        - true
    Parameters:
      PayType:
        Type: String
        Label:
          en: ECS Instance Charge Type
        AssociationProperty: ChargeType
        AssociationPropertyMetadata:
          LocaleKey: InstanceChargeType
        Default: PostPaid
        AllowedValues:
          - PostPaid
          - PrePaid
      PayPeriodUnit:
        Type: String
        Label:
          en: Pay Period Unit
        AssociationProperty: PayPeriodUnit
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Not:
                Fn::Equals:
                  - ${PayType}
                  - PostPaid
        Default: Month
        AllowedValues:
          - Month
          - Year
      PayPeriod:
        Type: Number
        Label:
          en: Period
        AssociationProperty: PayPeriod
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Not:
                Fn::Equals:
                  - ${PayType}
                  - PostPaid
        Default: 1
        AllowedValues:
          - 1
          - 2
          - 3
          - 4
          - 5
          - 6
          - 7
          - 8
          - 9
      EcsInstanceType:
        Type: String
        Label:
          en: Instance Type
        AssociationProperty: ALIYUN::ECS::Instance::InstanceType
        AssociationPropertyMetadata:
          ZoneId: ${ZoneId}
          InstanceChargeType: ${InstanceChargeType}
      ZoneId:
        Type: String
        Label:
          en: Availability Zone
        AssociationProperty: ALIYUN::ECS::Instance::ZoneId
      WhetherCreateVpc:
        Type: Boolean
        Label:
          en: Create New VPC
        Default: false
      VpcCidrBlock:
        Type: String
        Label:
          en: VPC IPv4 CIDR Block
        Description:
          en: 'The IPv4 CIDR block for the VPC. You can use the following CIDR blocks or their
            subnets: 10.0.0.0/8172.16.0.0/12192.168.0.0/16'
        AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
              - ${WhetherCreateVpc}
              - true
        Default: 192.168.0.0/16
      VSwitchCidrBlock:
        Type: String
        Label:
          en: VSwitch CIDR Block
        Description:
          en: Must be a subnet of the VPC.
        AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
        AssociationPropertyMetadata:
          VpcCidrBlock: VpcCidrBlock
          Visible:
            Condition:
              Fn::Equals:
              - ${WhetherCreateVpc}
              - true
        Default: 192.168.1.0/24
      VpcId:
        Type: String
        Label:
          en: VPC ID
        AssociationProperty: ALIYUN::ECS::VPC::VPCId
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
              - ${WhetherCreateVpc}
              - false
        Default: ''
      VSwitchId:
        Type: String
        Label:
          en: VSwitch ID
        AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
        AssociationPropertyMetadata:
          VpcId: ${VpcId}
          ZoneId: ${ZoneId}
          Visible:
            Condition:
              Fn::Equals:
              - ${WhetherCreateVpc}
              - false
        Default: ''
      InstancePassword:
        Type: String
        Label:
          en: Instance Password
        Description:
          en: The login password for the instance. It must be 8 to 30 characters long and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
        ConstraintDescription:
          en: The password must be 8 to 30 characters long and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
        AssociationProperty: ALIYUN::ECS::Instance::Password
        AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
        MinLength: 8
        MaxLength: 30
        NoEcho: true
      SystemDiskCategory:
        Type: String
        Label:
          en: System Disk Category
        AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
        AssociationPropertyMetadata:
          LocaleKey: DiskCategory
          InstanceType: ${EcsInstanceType}
        AllowedValues:
        - cloud_efficiency
        - cloud_ssd
        - cloud_essd
      SystemDiskSize:
        Type: Number
        Label:
          en: System Disk Size (GB)
        Default: 200
      DataDiskCategory:
        Type: String
        Label:
          en: Data Disk Type
        AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
        AssociationPropertyMetadata:
          InstanceType: EcsInstanceType
          ZoneId: ZoneId
          LocaleKey: DiskCategory
      DataDiskSize:
        Type: Number
        Label:
          en: Data Disk Size (GB)
        Description:
          en: 'The size of the ECS instance data disk, in GiB. The value must be in the range of 20 to 32,768.'
        Default: 200
        MinValue: 20
        MaxValue: 32768
      AllocatePublicIP:
        Type: Boolean
        Label:
          en: Allocate Public IP
        Default: true
      InternetMaxBandwidthOut:
        Type: Number
        Label:
          en: Internet Max Bandwidth Out (Mbit/s)
        Description:
          en: The value must be in the range of 0 to 100. A value of 0 means no public IP is allocated.
        AssociationPropertyMetadata:
          Visible:
            Condition:
              Fn::Equals:
              - ${AllocatePublicIP}
              - true
        Default: 5
        MinValue: 0
        MaxValue: 100
    Resources:
      EcsVpc:
        Type: ALIYUN::ECS::VPC
        Condition: CreateVpcConditions
        Properties:
          CidrBlock:
            Ref: VpcCidrBlock
          VpcName:
            Ref: ALIYUN::StackName
      EcsVSwitch:
        Type: ALIYUN::ECS::VSwitch
        Condition: CreateVpcConditions
        Properties:
          ZoneId:
            Ref: ZoneId
          VpcId:
            Ref: EcsVpc
          CidrBlock:
            Ref: VSwitchCidrBlock
      EcsSecurityGroup:
        Type: ALIYUN::ECS::SecurityGroup
        Properties:
          # Set the security group name based on the software name.
          #SecurityGroupName: nginx-sg
          VpcId:
            Fn::If:
            - CreateVpcConditions
            - Ref: EcsVpc
            - Ref: VpcId
          # Set inbound rules based on the ports listened to by the software.
          # By default, all outbound ports are open in a security group.
          #SecurityGroupIngress:
          #  - PortRange: 80/80
          #    Priority: 1
          #    SourceCidrIp: 0.0.0.0/0
          #    IpProtocol: tcp
      EcsInstanceGroup:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          ZoneId:
            Ref: ZoneId
          VpcId:
            Fn::If:
            - CreateVpcConditions
            - Ref: EcsVpc
            - Ref: VpcId
          VSwitchId:
            Fn::If:
            - CreateVpcConditions
            - Ref: EcsVSwitch
            - Ref: VSwitchId
          SecurityGroupId:
            Ref: EcsSecurityGroup
          ImageId: centos_7
          IoOptimized: optimized
          InstanceChargeType:
            Ref: PayType
          PeriodUnit:
            Ref: PayPeriodUnit
          Period:
            Ref: PayPeriod
          SystemDiskCategory:
            Ref: SystemDiskCategory
          # Adjust the system disk size as needed.
          SystemDiskSize:
            Ref: SystemDiskSize
          # Data disk configuration.
          DiskMappings:
          - Category:
              Ref: DataDiskCategory
            Size:
              Ref: DataDiskSize
          MaxAmount: 1
          InstanceType:
            Ref: EcsInstanceType
          Password:
            Ref: InstancePassword
          # Public bandwidth. A value of 0 means no public IP.
          InternetMaxBandwidthOut:
            Fn::If:
            - IfAllocatePublicIP
            - Ref: InternetMaxBandwidthOut
            - 0
          InstanceName:
            Fn::Join:
            - '-'
            - - Ref: ALIYUN::StackName
              - '[1,4]'
      WaitConditionHandle:
        Type: ALIYUN::ROS::WaitConditionHandle
        Properties: {}
      WaitCondition:
        Type: ALIYUN::ROS::WaitCondition
        Properties:
          Count: 1
          Handle:
            Ref: WaitConditionHandle
          # Timeout for command execution to complete.
          Timeout: 300
      InstanceRunCommand:
        Type: ALIYUN::ECS::RunCommand
        Properties:
          InstanceIds:
            Fn::GetAtt:
            - EcsInstanceGroup
            - InstanceIds
          CommandContent:
            Fn::Sub:
            - |
              #!/bin/bash
              # 1. If a data disk is used, format and mount it to a specified directory.
              #    This example assumes it is mounted to /data.
              init_and_mount_data_disk() {
                local fs_type=$1
                local mount_point=$2
                # Find disk devices (excluding partitions).
                devices=(`lsblk -o NAME,FSTYPE --noheadings --nodeps | awk '$2 == "" {print $1}'`)
                # Find disk devices that do not have a file system.
                for device in ${!devices[@]};
                do
                  lsblk -o NAME,FSTYPE --noheadings  | awk '$2 != "" {print $1}' | grep ${!device}
                  if [[ $? -eq 1 ]]; then
                    data_disk=${!device}
                    break
                  fi
                done
                # Create a file system for the data disk.
                mkfs -t ${!fs_type} /dev/${!data_disk}
                cp /etc/fstab /etc/fstab.bak
                mkdir ${!mount_point}
                # Update /etc/fstab and mount the disk.
                echo `blkid /dev/${!data_disk} | awk '{print $2}' | sed 's/\\\"//g'` ${!mount_point} ext4 defaults 0 0 >> /etc/fstab
                mount -a
              }
              # Mount the disk to /data.
              init_and_mount_data_disk ext4 /data
              # 2. Install software or perform initial configuration, such as pointing data file directories to the data disk.
              # yum install -y nginx
              # 3. To enable auto-start on boot, add and enable the system service.
              # systemctl enable nginx.service
              # 4. Configure the startup script or start the system service.
              # systemctl start nginx.service
              # 5. On success, send a callback to end the WaitCondition.
              ${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
              # If the script fails at any point, use the following command to return FAILURE and an error message.
              # ${CurlCli} -d "{\"Data\" : \"error message\", \"status\" : \"FAILURE\"}"
            - CurlCli:
                Fn::GetAtt:
                - WaitConditionHandle
                - CurlCli
          Type: RunShellScript
          # Set the timeout in seconds based on the expected command execution time.
          # If the command times out, the deployment fails.
          Timeout: 300
    # Outputs are defined according to software requirements.
    # The following is an example for NGINX, which outputs the public access address of the website.
    #Outputs:
    #  endpoint:
    #    Condition: IfAllocatePublicIP
    #    Description:
    #      en: Public IP Addresses
    #    Value:
    #      Fn::Sub:
    #        - http://${ServerAddress}
    #        - ServerAddress:
    #            Fn::Select:
    #              - 0
    #              - Fn::GetAtt:
    #                  - EcsInstanceGroup
    #                  - PublicIps
    Metadata:
      ALIYUN::ROS::Interface:
    ## The order of the parameter groups determines the parameter arrangement on the service instance creation page.
    ## If most instance types are applicable (e.g., x86 architecture), you can place the availability zone selection first, as shown in the comments.
    #    ParameterGroups:
    #      - Parameters:
    #          - ZoneId
    #        Label:
    #          default:
    #            en: Zone Configuration
    #      - Parameters:
    #          - WhetherCreateVpc
    #          - VpcCidrBlock
    #          - VSwitchCidrBlock
    #          - VpcId
    #          - VSwitchId
    #        Label:
    #          default:
    #            en: VPC Configuration
    #      - Parameters:
    #          - PayType
    #          - PayPeriodUnit
    #          - PayPeriod
    #        Label:
    #          default:
    #            en: Billing Configuration
    #      - Parameters:
    #          - EcsInstanceType
    #          - InstancePassword
    #          - SystemDiskCategory
    #          - SystemDiskSize
    #          - DataDiskCategory
    #          - DataDiskSize
    #          - AllocatePublicIP
    #          - InternetMaxBandwidthOut
    #        Label:
    #          default:
    #            en: Instance Configuration
        ParameterGroups:
        - Parameters:
            - PayType
            - PayPeriodUnit
            - PayPeriod
          Label:
            default:
              en: Billing Configuration
        - Parameters:
          - EcsInstanceType
          Label:
            default:
              en: ECS Instance Type Configuration
        - Parameters:
          - ZoneId
          Label:
            default:
              en: Zone Configuration
        - Parameters:
          - WhetherCreateVpc
          - VpcCidrBlock
          - VSwitchCidrBlock
          - VpcId
          - VSwitchId
          Label:
            default:
              en: VPC Configuration
        - Parameters:
          - InstancePassword
          - SystemDiskCategory
          - SystemDiskSize
          - DataDiskCategory
          - DataDiskSize
          - AllocatePublicIP
          - InternetMaxBandwidthOut
          Label:
            default:
              en: Detailed Instance Configuration
        TemplateTags:
        - acs:example:ISV software deployment:Single-instance custom image with optional data disk and public IP.
    
  6. Click Select Deployment Package, select a deployment package and version, and then click OK to associate the ECS image deployment package.

    Important
    • If you select a draft version, the ECS image in that version is not distributed. The image is available only in the region where it was created.

    • If you select a published version, the ECS image is available in the source region and all distributed regions.

    In this example, the image to be replaced is centos_7. In the dialog box, select the deployment package SpringBootEcsImage and choose Version 1.

  7. After you create and test the service, ensure it meets the review criteria of Compute Nest and then submit it for review. For more information, see Review criteria.

  8. After the service is approved, publish it. For more information, see Publish a service.

    After a service instance is created, the image ID is automatically replaced with the corresponding distribution result from the deployment package.

    • Before replacement:

      SecurityGroupId:
                Ref: EcsSecurityGroup
              ImageId: centos_7
              IoOptimized: optimized
              InstanceChargeType:
                Ref: InstanceChargeType
    • After replacement:

      InternetMaxBandwidthOut:
                Ref: InternetMaxBandwidthOut
              ImageId: m-bp1dxxx
              PeriodUnit:
                Ref: PayPeriodUnit

Related documents

  • For more information about how to create a service in Compute Nest, see Create a service.

  • If you no longer need a deployment package or a specific version, you can delete it. For more information, see Delete a deployment package.

  • To change a deployment package's content, distribution regions, or other details, create a new version. For more information, see Create a new version.

  • To configure upgrade settings for a deployment package, see Configure service upgrades.