-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::DownloadFile.json
197 lines (197 loc) · 6.54 KB
/
ACS::ECS::DownloadFile.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::DownloadFile",
"name-zh-cn": "到ECS实例中下载文件",
"en": "Download the file to the ECS instance",
"zh-cn": "到ECS实例中下载文件"
},
"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",
"local"
]
},
"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": ""
},
"destinationDir": {
"Description": {
"en": "Target directory for file download in instance",
"zh-cn": "文件在实例中的下载目录"
},
"Type": "String"
},
"timeout": {
"Description": {
"en": "Timeout for file download",
"zh-cn": "文件下载超时时间"
},
"Type": "Number",
"Default": 600
},
"fileOwner": {
"Description": {
"en": "The owner of the file",
"zh-cn": "文件所有者"
},
"Type": "String",
"Default": ""
},
"fileGroup": {
"Description": {
"en": "The group of the file",
"zh-cn": "文件所属组"
},
"Type": "String",
"Default": ""
},
"fileMode": {
"Description": {
"en": "The mode of the file",
"zh-cn": "文件权限"
},
"Type": "String",
"Default": ""
},
"overwrite": {
"Description": {
"en": "Overwrite the existing file",
"zh-cn": "覆盖已存在的文件"
},
"Type": "Boolean",
"Default": true
}
},
"Tasks": [
{
"Name": "queryInstanceOSType",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Queries ECS instance OS type",
"zh-cn": "获取实例操作系统类型"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
}
},
"Outputs": {
"OSType": {
"Type": "String",
"ValueSelector": "Instances.Instance[].OSType"
}
}
},
{
"Name": "downloadLinuxFile",
"When": {
"Fn::Equals": [
"{{ queryInstanceOSType.OSType }}",
"linux"
]
},
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Execute download file command on linux instance",
"zh-cn": "在linux类型实例上执行下载文件命令"
},
"Properties": {
"instanceId": "{{ instanceId }}",
"regionId": "{{ regionId }}",
"timeout": "{{ timeout }}",
"commandType": "RunShellScript",
"commandContent": "#/bin/bash\n\nfileName=$(echo \"{{sourcePath}}\" | awk -F'?' '{print$1}' | awk -F'/' '{print$NF}')\ndestinationFile=\"{{destinationDir}}/${fileName}\"\n\nif [ ! -d \"{{destinationDir}}\" ]; then\n mkdir -p \"{{destinationDir}}\"\nfi\n\nif [ '{{ overwrite }}' = 'true' ] || [ ! -f \"$destinationFile\" ]; then\n if [ '{{sourceType}}' = 'local' ]; then\n wget \"{{sourcePath}}\" -O \"$destinationFile\" -q\n echo \"$destinationFile execute success.\"\n else\n acs-plugin-manager --exec -P oosutil --params download_content,{{sourceType}},'\"{{sourcePath}}\"',\\''{{ tokenInfo }}'\\','{{destinationDir}}'\n fi\nelse\n echo \"File already exists.\"\n exit 1\nfi\n\nif [ '{{fileMode}}' != '' ] ; then\n chmod '{{fileMode}}' \"$destinationFile\"\nfi\n\nif [ '{{fileGroup}}' != '' ] ; then\n chgrp {{fileGroup}} \"$destinationFile\"\nfi\n\nif [ '{{fileOwner}}' != '' ] ; then\n chown {{fileOwner}} \"$destinationFile\"\nfi"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "downloadWindowsFile",
"When": {
"Fn::Equals": [
"{{ queryInstanceOSType.OSType }}",
"windows"
]
},
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Executes download file command on windows instance",
"zh-cn": "在windows类型实例上执行下载文件命令"
},
"Properties": {
"instanceId": "{{ instanceId }}",
"regionId": "{{ regionId }}",
"timeout": "{{ timeout }}",
"commandType": "RunPowerShellScript",
"commandContent": "$sourcePath = \"{{ sourcePath }}\"\n$destinationDir = \"{{ destinationDir }}\"\n$fileName = ($sourcePath -split '\\?')[0] | Split-Path -Leaf\n$destinationFile = Join-Path $destinationDir $fileName\n\nif (-not (Test-Path -Path $destinationDir)) {\n New-Item -ItemType Directory -Path $destinationDir\n}\n\nif (\"{{overwrite}}\" -eq \"true\" -or !(Test-Path $destinationFile))\n{\n if (\"{{sourceType}}\" -eq \"local\")\n {\n Invoke-WebRequest -Uri $sourcePath -OutFile $destinationFile\n Write-Host \"$destinationFile execute success.\"\n }\n else\n {\n acs-plugin-manager.exe --exec -P oosutil_win --params \"download_content,{{ sourceType }},$sourcePath,'`{{ tokenInfo }}`',$destinationDir\"\n if ($LASTEXITCODE -ne 0){\n exit $LASTEXITCODE;\n }\n }\n}\nelse\n{\n Write-Host \"File already exists.\"\n Exit 1\n}"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
}
],
"Outputs": {
"commandOutput": {
"Type": "String",
"Value": {
"Fn::If": [
{
"Fn::Equals": [
"linux",
"{{ queryInstanceOSType.OSType }}"
]
},
"{{ downloadLinuxFile.commandOutput }}",
"{{ downloadWindowsFile.commandOutput }}"
]
}
}
}
}