-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::RunPacker.json
102 lines (102 loc) · 4.1 KB
/
ACS::ECS::RunPacker.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::RunPacker",
"name-zh-cn": "在ECS实例中执行Packer模板",
"en": "Run Packer template on ECS instance",
"zh-cn": "在ECS实例中执行Packer模板"
},
"Parameters": {
"regionId": {
"Description": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String",
"Default": "{{ ACS::RegionId }}"
},
"instanceId": {
"Description": {
"en": "The ID of ECS instance",
"zh-cn": "ECS实例ID"
},
"Type": "String"
},
"sourceType": {
"Description": {
"en": "The type of file storage",
"zh-cn": "文件存储方式"
},
"Type": "String",
"AllowedValues": [
"oss",
"https",
"github"
]
},
"sourcePath": {
"Description": {
"en": "You must specify a URL where the file is stored",
"zh-cn": "您必须指定一个用于存储文件的URL"
},
"Type": "String"
},
"tokenInfo": {
"Description": {
"en": "Specify a token to download file.It is only required when downloading file from GitHub",
"zh-cn": "指定一个token来下载文件,只有从GitHub下载文件时会用到"
},
"Type": "String",
"Default": " "
},
"templateFile": {
"Description": {
"en": "The name of Packer template to run. For example: example.json",
"zh-cn": "要执行的Packer模板文件"
},
"Type": "String"
},
"mode": {
"Type": "String",
"Description": {
"en": "Packer template execution mode",
"zh-cn": "Packer模板执行的模式"
},
"AllowedValues": [
"validate",
"fix",
"build"
],
"Default": "build"
}
},
"Tasks": [
{
"Name": "runPackerTemplate",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Executes Packer template",
"zh-cn": "执行Packer模板"
},
"Properties": {
"regionId": "{{ regionId }}",
"instanceId": "{{ instanceId }}",
"commandType": "RunShellScript",
"timeout": 3600,
"commandContent": "#/bin/bash\ncurrent_version=`aliyun-service -v`\nspecified_version=1.0.2.497\npath=/root/packer_workspace\n\nif [[ $current_version > $specified_version ]]; then\n\n echo \"Downloading packer template.\";\n acs-plugin-manager --exec -P oosutil --params download_content,{{sourceType}},'{{sourcePath}}',\\''{{ tokenInfo }}'\\',$path\n test -e /usr/bin/unzip || sudo yum -y install unzip\n test -e $path/packer || acs-plugin-manager --exec -P oosutil --params download_content,https,'https://oos-public-{{regionId}}.oss-{{regionId}}.aliyuncs.com/x64/packer_1.6.2_linux_amd64.zip',\\'''\\',$path && unzip -o $path/packer_1.6.2_linux_amd64.zip -d $path/\n\n echo \"Packer run {{ templateFile }}.\"\n cd $path\n ./packer {{ mode }} ./{{ templateFile }}\n\nelse\n version='{{ ACS::OOSUtilVersion }}'\n oosutil_path=/usr/local/share/aliyun-oosutil/$version\n test -e $oosutil_path || mkdir -p $oosutil_path\n cd $oosutil_path && test -e oosutil_linux || wget -q \"https://oos-public-{{regionId}}.oss-{{regionId}}-internal.aliyuncs.com/oosutil/$version/linux/oosutil_linux\"\n chmod +x oosutil_linux\n\n echo \"Downloading packer template.\";\n ./oosutil_linux download_content {{sourceType}} '{{sourcePath}}' \\''{{ tokenInfo }}'\\' $path\n test -e /usr/bin/unzip || sudo yum -y install unzip\n test -e $path/packer || ./oosutil_linux download_content https 'https://oos-public-{{regionId}}.oss-{{regionId}}.aliyuncs.com/x64/packer_1.6.2_linux_amd64.zip' \\'''\\' $path && unzip -o $path/packer_1.6.2_linux_amd64.zip -d $path/\n\n echo \"Packer run {{ templateFile }}.\"\n cd $path\n ./packer {{ mode }} ./{{ templateFile }}\nfi"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
}
],
"Outputs": {
"commandOutput": {
"Type": "String",
"Value": "{{ runPackerTemplate.commandOutput }}"
}
}
}