When you create a service template, you can use the package association feature to include packages from file-type deployments. This topic describes the package association feature.
How it works
The package association feature lets you define a placeholder in your service template and associate it with a file deployment. When you create a service instance, Compute Nest automatically detects the placeholder and replaces it with the file URL from the deployment that matches the service instance's region.
Procedure
Define a placeholder in the template.
Before you configure a package association, you must define a placeholder. These placeholders have two primary uses: in general-purpose templates or for a
MigrateTaskresource in a database template.Package association placeholders use the following formats:
(Recommended) If the deployment's file URL is a private URL, use the following format:
{{ computenest::file::xxx }}.If the deployment's file URL is a public URL, use the following format:
{{ computenest::publicfile::xxx }}
Notexxxrepresents a custom identifier that cannot contain spaces.Define a placeholder in a general-purpose template.
The following example shows how to define placeholders in a template. In this example, a
UserDatascript downloads the files and renames them to TestFirst.txt and TestSecond.tar.NoteWhen you define a package association placeholder in a template, we recommend enclosing the placeholder in single (
'') or double ("") quotation marks.If you use the
wgetcommand to download a file, we recommend adding the -O parameter to specify the output filename.
TiDBServer: Type: ALIYUN::ECS::InstanceGroup Properties: …… UserData: Fn::Sub: - | #!/bin/sh sleep 10 wget '{{ computenest::file::DemoFirst }}' -O TestFirst.txt wget '{{ computenest::file::DemoSecond }}' -O TestSecond.tar ……Define a placeholder in a
MigrateTaskresource.SQLDump: Type: ALIYUN::RDS::MigrateTask Properties: …… DBName: mytest DBInstanceId: Fn::GetAtt: - Database - DBInstanceId OssObjectPositions: {{ computenest::file::DemoFirst }}
Configure package association.
On the service creation page, in the Deployment Package Association section, click Select Deployment Package under Set Package Association.
In the Select Deployment (Package Association) dialog box, select the file deployment and version to associate.
If you do not have a file deployment, create one first. For more information, see Create a deployment. The placeholder, such as
{{ computenest::file::testfile }}, appears at the top of the dialog box. You can only select file-type deployments. You can add a description as needed.Click OK. The Deployment Association area also contains the Set Image Association (to configure the image to be replaced, such as
centos_7, associated resources, such asECSInstances, and the corresponding deployment), Set Container Image Association (to configure association identifiers and the corresponding deployment), and Set Helm Association settings. If the current template has no Helm configuration, the message "The current template has no Helm association" is displayed.
Examples
When you create a service instance, Compute Nest automatically replaces the placeholders in the template with the file URLs from the associated deployments. Compute Nest selects the URL for each placeholder based on the service instance's region.
The following code shows the result after Compute Nest replaces a placeholder in a general-purpose template.
If the deployment's file URL is a private URL, the result is as follows.
Conditions: {} Resources: ECSInstances: Type: 'ALIYUN::ECS::InstanceGroup' Properties: UserData: | #!/bin/sh mkdir /root/lzq cd /root/lzq wget 'https://computenest-artifacts-cn-wulanchabu.oss-cn-wulanchabu-internal.aliyuncs.com/xxx/cn-zhangjiakou/xxx/示例文本.txt' wget 'https://computenest-artifacts-cn-wulanchabu.oss-cn-wulanchabu-internal.aliyuncs.com/xxx/cn-guangzhou/xxx/changes.txt' wget {{DemoThird}} SystemDiskCategory:If the deployment's file URL is a public URL, the result is as follows.
Properties: UserData: | #!/bin/sh mkdir /root/lzq cd /root/lzq wget 'https://computenest-artifacts-cn-wulanchabu.oss-cn-wulanchabu.aliyuncs.com/xxx/cn-beijing/xxx/1976虚拟背景.jpg' wget {{DemoThird}} SystemDiskCategory: Ref: SystemDiskCategory VpcId:
NoteBecause the service instance is deployed in the China (Ulanqab) region, Compute Nest replaces the placeholder with the file URL for that region.
For a
MigrateTaskresource, Compute Nest formats the file deployment URL as required by theOssObjectPositionsparameter.The OssObjectPositions parameter consists of three parts separated by colons (
:): the OSS endpoint, the OSS bucket name, and the object key of the backup file. For example,oss-ap-southeast-1.aliyuncs.com:rdsmssqlsingapore:autotest_2008R2_TestMigration_FULL.bak. For more information, see ALIYUN::RDS::MigrateTask. Compute Nest automatically converts the file deployment URL to this format.}, "OssObjectPositions": "oss-cn-hangzhou-internal.aliyuncs.com:computenest-artifacts-cn-hangzhou:xxx/cn-zhangjiakou/xxx/示例文本.txt", "DBInstanceId": {NoteBecause the service instance is deployed in the China (Hangzhou) region, Compute Nest replaces the placeholder with the file URL for that region.