ECS イメージはリージョン固有であるため、マルチリージョンでのサービスデプロイが複雑になります。具体的には、各ターゲットリージョンへイメージを手動でレプリケーションする必要があり、テンプレート内のイメージ ID をリージョンごとに更新し、権限を個別に管理する必要があります。さらに、新しいイメージバージョンをリリースするたびに、これらの作業をすべて繰り返す必要があります。
ECS イメージデプロイパッケージは、このプロセスを自動化します。デプロイパッケージを作成し、ソースイメージと関連付けると、Compute Nest が選択されたすべてのリージョンにおいて、イメージのレプリケーション、リージョンとイメージ ID のマッピング、および権限管理を実行します。
仕組み
ECS イメージデプロイパッケージを公開すると、Compute Nest は以下の 3 つの操作を自動的に実行します。
イメージレプリケーション — Compute Nest は、マルチリージョン配布に使用される Compute Nest 一般アカウントへ、ソース ECS イメージをレプリケーションします。
イメージマッピング — お客様がサービスをデプロイすると、Compute Nest はターゲットリージョンを検出し、テンプレート内の
ImageId値を、そのリージョンに対応する正しいイメージ ID に置き換えます。このマッピングは動的であり、各リージョンごとにテンプレートを更新する必要はありません。権限管理 — デプロイパッケージは、関連付けられたサービスから可視性を継承します。
関連付けられたサービス デプロイパッケージの可視性 なし 非公開(ご自身のみ利用可能) 少なくとも 1 つのパブリックサービス パブリック すべてのサービスが非公開 非公開 サービスにホワイトリストが設定されている 同一のホワイトリストが適用される
テンプレート要件
デプロイパッケージを作成する前に、ROS または Terraform テンプレートが以下の要件を満たしていることを確認してください。
パラメーター制約(ROS および Terraform の両方に適用): イメージ ID の値は静的な文字列リテラルである必要があります。入力パラメーターまたはビルトイン関数からこの値を指定することはできません。
| リソースタイプ | ROS パラメーター | ROS リソースタイプ | Terraform パラメーター | Terraform リソースタイプ |
|---|---|---|---|---|
| ECS インスタンス | ImageId | ALIYUN::ECS::Instance | image_id | alicloud_instance |
| ECS インスタンスグループ | ImageId | ALIYUN::ECS::InstanceGroup | — | — |
| Auto Scaling グループ | ImageId | ALIYUN::ESS::ScalingGroup | image_id | ALIYUN::ESS::ScalingGroup |
| E-HPC クラスター | ImageId | ALIYUN::EHPC::Cluster | — | — |
ROS テンプレートでは、ImageId を Resources セクションで指定します。Terraform テンプレートでは、リソースブロック内で image_id を指定します。
ECS イメージデプロイパッケージの作成
前提条件
開始する前に、以下の条件を満たしていることを確認してください。
ソースとして使用する ECS イメージ。Compute Nest は以下の 2 種類のイメージをサポートしています。
カスタムイメージ — お客様の Alibaba Cloud アカウントで作成した ECS イメージ。該当するイメージがない場合は、インスタンスからカスタムイメージを作成してください。
Alibaba Cloud Marketplace のイメージ — Alibaba Cloud Marketplace で提供されているイメージ。
上記のテンプレート要件を満たす ROS または Terraform テンプレート。
デプロイパッケージの作成および公開
Compute Nest コンソールにログインします。左側ナビゲーションウィンドウで、サービスデプロイパッケージ をクリックします。デプロイパッケージ セクションで、デプロイパッケージの作成 をクリックします。
デプロイパッケージ情報 セクションで、以下のパラメーターを設定します。
パラメーター 説明 デプロイパッケージ名 3~128 文字(英字、数字、アンダースコア (_) のみ)。作成後は変更できません。 バージョン名 3~50 文字(英字、数字、アンダースコア (_) のみ)。 説明 10~500 文字。 リソースグループ このデプロイパッケージのリソースグループ。リソースグループを使用すると、用途、権限、リージョンに基づいてリソースを整理できます。詳細については、「リソースグループの管理」をご参照ください。 タグ設定 デプロイパッケージにアタッチするタグ。パッケージあたり最大 20 タグまで設定可能です。詳細については、「カスタムタグの追加」をご参照ください。 ECS イメージデプロイパッケージの内容を設定します。
デプロイパッケージの内容 セクションで、デプロイパッケージタイプ を ECS イメージ に設定します。イメージタイプ および 製品の選択 は、事前に準備したイメージに基づいて設定します。
配信設定 セクションで、パッケージを配信するリージョンを選択します。> 重要: 少なくとも 1 つのリージョンを選択してください。
デプロイパッケージの公開 をクリックします。> 注: 公開前にパッケージをテストする場合は、まず デプロイパッケージの保存 をクリックしてください。テスト後に デプロイパッケージの公開 をクリックします。公開前のパッケージは、ソース ECS イメージが存在するリージョンでのみテスト可能であり、選択した配信リージョンではテストできません。バージョンが公開されると、その内容はロックされます。変更を行うには、新しいバージョンまたは新しいデプロイパッケージを作成してください。

サービスデプロイパッケージ ページに戻り、作成したデプロイパッケージを見つけ、その名前をクリックして デプロイパッケージの詳細 ページを開きます。配信には、リージョンおよびイメージサイズに応じて数分から数時間かかる場合があります。パッケージの状態が 利用可能 になったら、デプロイパッケージバージョン タブをクリックし、対象のバージョンを見つけ、[操作] 列の 表示 をクリックして、配信結果を確認します。
ECS イメージデプロイパッケージの使用
以下の例では、ECS イメージデプロイパッケージをサービステンプレートに関連付ける方法を示すために、プライベートサービスを作成します。
Compute Nest コンソールにログインします。左側ナビゲーションウィンドウで、マイサービス をクリックします。
作成済みサービス タブで、サービスの作成 をクリックします。
サービスの作成 ページで、サービス作成方法の選択 を カスタム起動 に、サービスタイプの選択 を プライベートサービス に設定し、次へ:設定の構成 をクリックします。

基本的なサービス情報を指定します。テンプレート セクションで、テンプレートを選択または入力します。この例では シナリオベースのテンプレート を使用します。
テンプレートに
ImageIdパラメーターが含まれている場合、デプロイパッケージの関連付け セクションで ECS イメージの関連付け を構成します。サンプルテンプレートこのサンプルテンプレートはテスト専用です。
ROSTemplateFormatVersion: '2015-09-01' Description: en: This template deploys custom image for single instance, supports creating new VPC and specifying VPC. zh-cn: Conditions: CreateVpcConditions: Fn::Equals: - true - Ref: WhetherCreateVpc IfAllocatePublicIP: Fn::Equals: - Ref: AllocatePublicIP - true Parameters: PayType: Type: String Label: en: ECS Instance Charge Type zh-cn: AssociationProperty: ChargeType AssociationPropertyMetadata: LocaleKey: InstanceChargeType Default: PostPaid AllowedValues: - PostPaid - PrePaid PayPeriodUnit: Type: String Label: en: Pay Period Unit zh-cn: AssociationProperty: PayPeriodUnit AssociationPropertyMetadata: Visible: Condition: Fn::Not: Fn::Equals: - ${PayType} - PostPaid Default: Month AllowedValues: - Month - Year PayPeriod: Type: Number Label: en: Period zh-cn: 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 zh-cn: AssociationProperty: ALIYUN::ECS::Instance::InstanceType AssociationPropertyMetadata: ZoneId: ${ZoneId} InstanceChargeType: ${InstanceChargeType} ZoneId: Type: String Label: en: Availability Zone zh-cn: AssociationProperty: ALIYUN::ECS::Instance::ZoneId WhetherCreateVpc: Type: Boolean Label: en: WhetherCreateVpc zh-cn: Default: false VpcCidrBlock: Type: String Label: en: VPC CIDR IPv4 Block zh-cn: Description: zh-cn: en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>' 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 zh-cn: Description: zh-cn: en: Must belong to the subnet segment of 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 zh-cn: AssociationProperty: ALIYUN::ECS::VPC::VPCId AssociationPropertyMetadata: Visible: Condition: Fn::Equals: - ${WhetherCreateVpc} - false Default: '' VSwitchId: Type: String Label: en: VSwitch ID zh-cn: AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId AssociationPropertyMetadata: VpcId: ${VpcId} ZoneId: ${ZoneId} Visible: Condition: Fn::Equals: - ${WhetherCreateVpc} - false Default: '' InstancePassword: Type: String Label: en: Instance Password zh-cn: Description: en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in) zh-cn: ConstraintDescription: en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in) zh-cn: AssociationProperty: ALIYUN::ECS::Instance::Password AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$' MinLength: 8 MaxLength: 30 NoEcho: true SystemDiskCategory: Type: String Label: en: System Disk Category zh-cn: AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory AssociationPropertyMetadata: LocaleKey: DiskCategory InstanceType: ${EcsInstanceType} AllowedValues: - cloud_efficiency - cloud_ssd - cloud_essd SystemDiskSize: Type: Number Label: zh-cn: en: System Disk Space (GB) Default: 200 DataDiskCategory: Type: String Label: zh-cn: en: Data disk type AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory AssociationPropertyMetadata: InstanceType: EcsInstanceType ZoneId: ZoneId LocaleKey: DiskCategory DataDiskSize: Type: Number Label: zh-cn: en: Data disk space Description: zh-cn: en: 'ECS Instance disk size, range of values: 20-32768, units: GB' Default: 200 MinValue: 20 MaxValue: 32768 AllocatePublicIP: Type: Boolean Label: zh-cn: en: allocate public ip Default: true InternetMaxBandwidthOut: Type: Number Label: zh-cn: en: Internet Max Bandwidth Out Description: zh-cn: en: no public ip if zero 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: # Specify a name for the security group based on the software name. #SecurityGroupName: nginx-sg VpcId: Fn::If: - CreateVpcConditions - Ref: EcsVpc - Ref: VpcId # Specify inbound rules of the security group based on the ports that are listened to by the software. By default, all ports are enabled in the outbound direction. #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 # You can adjust the size of the system disk based on your business requirements. SystemDiskSize: Ref: SystemDiskSize # The configurations of the data disk. DiskMappings: - Category: Ref: DataDiskCategory Size: Ref: DataDiskSize MaxAmount: 1 InstanceType: Ref: EcsInstanceType Password: Ref: InstancePassword # The public bandwidth. A value of 0 indicates that Internet access is disabled. 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 # The timeout period to run the command. Timeout: 300 InstanceRunCommand: Type: ALIYUN::ECS::RunCommand Properties: InstanceIds: Fn::GetAtt: - EcsInstanceGroup - InstanceIds CommandContent: Fn::Sub: - | #!/bin/bash # 1. If you use a data disk, you must format the data disk and mount it to the specified directory. In this example, the data disk is mounted to the /data directory. init_and_mount_data_disk() { local fs_type=$1 local mount_point=$2 # Query disk devices and exclude disk partitions. devices=(`lsblk -o NAME,FSTYPE --noheadings --nodeps | awk '$2 == "" {print $1}'`) # Query the disk devices that do not have file systems. 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 the /etc/fstab file 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 the /data directory. init_and_mount_data_disk ext4 /data # 2. Install the software or initialize the software. For example, specify a data disk directory as the data file directory. # yum install -y nginx # 3. If you need to start the software at startup, add and enable the corresponding system service. # systemctl enable nginx.service # 4. Configure the startup script or start the system service. # systemctl start nginx.service # 5. If the script is successfully executed, trigger a callback and stop waiting based on WaitCondition. ${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}" # If the script fails to be executed, run the following command to return FAILURE and the error message. # ${CurlCli} -d "{\"Data\" : \"error message\", \"status\" : \"FAILURE\"}" - CurlCli: Fn::GetAtt: - WaitConditionHandle - CurlCli Type: RunShellScript # Set the timeout period based on the command execution time. Unit: seconds. If the command execution times out, the deployment fails. Timeout: 300 # The outputs are defined based on the software requirements. # In this example, NGINX is used and the output is the public URL to access the website. #Outputs: # endpoint: # Condition: IfAllocatePublicIP # Description: # zh-cn: # en: Public IP Addresses # Value: # Fn::Sub: # - http://${ServerAddress} # - ServerAddress: # Fn::Select: # - 0 # - Fn::GetAtt: # - EcsInstanceGroup # - PublicIps Metadata: ALIYUN::ROS::Interface: ## The order of parameter groups determines the order of the parameters displayed on the page to create the service instance. ## If most instance types are supported, such as the instances of the x86 architecture, you can specify the zone configurations first by referring to the comments. # ParameterGroups: # - Parameters: # - ZoneId # Label: # default: # zh-cn: # en: Zone Configuration # - Parameters: # - WhetherCreateVpc # - VpcCidrBlock # - VSwitchCidrBlock # - VpcId # - VSwitchId # Label: # default: # zh-cn: # en: VPC Configuration # - Parameters: # - PayType # - PayPeriodUnit # - PayPeriod # Label: # default: # en: PayType Configuration # zh-cn: # - Parameters: # - EcsInstanceType # - InstancePassword # - SystemDiskCategory # - SystemDiskSize # - DataDiskCategory # - DataDiskSize # - AllocatePublicIP # - InternetMaxBandwidthOut # Label: # default: # en: Instance # zh-cn: ParameterGroups: - Parameters: - PayType - PayPeriodUnit - PayPeriod Label: default: en: PayType Configuration zh-cn: - Parameters: - EcsInstanceType Label: default: zh-cn: en: ECS インスタンスタイプの構成 - Parameters: - ZoneId Label: default: zh-cn: en: ゾーンの構成 - Parameters: - WhetherCreateVpc - VpcCidrBlock - VSwitchCidrBlock - VpcId - VSwitchId Label: default: zh-cn: en: VPC の構成 - Parameters: - InstancePassword - SystemDiskCategory - SystemDiskSize - DataDiskCategory - DataDiskSize - AllocatePublicIP - InternetMaxBandwidthOut Label: default: en: インスタンス zh-cn: TemplateTags: - acs:example:Independent software vendor (ISV) software deployment: This template is used to deploy a single instance with a data disk by using a custom image. A public IP address is optional.
デプロイパッケージの選択 をクリックします。ダイアログボックスで、デプロイパッケージおよびバージョンを選択し、OK をクリックします。テンプレート内のソースイメージ ID が、ECS イメージデプロイパッケージに置き換えられます。
重要- 下書きバージョン(未配信): 関連付けられたイメージは、作成されたリージョンでのみ使用可能です。- 正式バージョン(配信済み): 関連付けられたイメージは、作成されたリージョンおよび配信されたすべてのリージョンで使用可能です。

サービスを保存してテストします。テストが成功したら、サービスがレビュー基準を満たしていることを確認し、レビューのために提出します。
承認後、サービスを公開します。
お客様がリージョンでサービスインスタンスを作成すると、Compute Nest はそのリージョンに既に配信済みのイメージを自動的に使用します。
置換前のイメージ ID

置換後のイメージ ID

制限事項
テンプレート内で、ECS イメージデプロイパッケージのクラウドリソースを変更できます。
デプロイパッケージバージョンが公開されると、その内容は変更できません。イメージまたは配信リージョンを更新するには、新しいバージョンを作成してください。
次のステップ
サービスの作成 — Compute Nest サービスを作成するための完全な手順。
新規バージョンの作成 — 新しいデプロイパッケージバージョンを作成することで、配信リージョンまたはイメージ内容を更新します。
デプロイパッケージの削除 — 不要になったデプロイパッケージまたはバージョンを削除します。
サービスアップグレード設定の構成 — 新しいデプロイパッケージバージョンが利用可能になった際に、サービスがアップグレードをどのように処理するかを構成します。