-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS-ECS-LocalBuildAndDeployOnSingleECS.json
460 lines (460 loc) · 14.9 KB
/
ACS-ECS-LocalBuildAndDeployOnSingleECS.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Build and deploy applications on a single ECS",
"zh-cn": "在单个ECS上构建并部署应用",
"name-en": "ACS-ECS-LocalBuildAndDeployOnSingleECS",
"name-zh-cn": "单ECS本地构建部署"
},
"Parameters": {
"platform": {
"Type": "String",
"Label": {
"en": "Platform",
"zh-cn": "平台"
},
"AssociationProperty": "ALIYUN::OOS::GitPlatform::Name",
"Default": "github",
"Description": {
"en": "ECS in mainland China may experience unstable GitHub connection. It is recommended to use Gitee first.",
"zh-cn": "中国内地ECS可能会出现GitHub连接不稳定,建议优先使用Gitee。"
},
"AllowedValues": [
"github",
"gitee"
]
},
"owner": {
"Type": "String",
"Label": {
"en": "Owner",
"zh-cn": "所有者"
},
"AssociationProperty": "ALIYUN::OOS::GitAccount::Name",
"AssociationPropertyMetadata": {
"Platform": "${platform}"
}
},
"organization": {
"Type": "String",
"Label": {
"en": "Organization",
"zh-cn": "组织"
},
"Default": "",
"AssociationProperty": "ALIYUN::OOS::GitOrganization::Name",
"AssociationPropertyMetadata": {
"Platform": "${platform}",
"Owner": "${owner}"
}
},
"repository": {
"Type": "String",
"Label": {
"en": "Repository",
"zh-cn": "仓库"
},
"AssociationProperty": "ALIYUN::OOS::GitRepository::Name",
"AssociationPropertyMetadata": {
"Platform": "${platform}",
"Organization": "${organization}",
"Owner": "${owner}"
}
},
"instanceId": {
"Label": {
"en": "InstanceId",
"zh-cn": "ECS实例ID"
},
"Description": {
"en": "The ID of ECS instance",
"zh-cn": "ECS实例ID"
},
"Type": "String",
"Default": "",
"AssociationPropertyMetadata": {
"Visible": {
"Condition": {
"Fn::Equals": [
"${platform}",
null
]
}
}
}
},
"branch": {
"Label": {
"en": "Branch",
"zh-cn": "分支"
},
"AssociationProperty": "ALIYUN::OOS::GitBranch::Name",
"AssociationPropertyMetadata": {
"Platform": "${platform}",
"Organization": "${organization}",
"Owner": "${owner}",
"RepoFullName": "${repository}"
},
"Type": "String"
},
"downloadPath": {
"Label": {
"en": "Download Path",
"zh-cn": "下载路径"
},
"Description": {
"en": "The path to download the code. If not set, it will be downloaded to /root/workspace/{current execution ID}. If you need to specify a path, please ensure that the path you provide does not have files, otherwise it will fail to pull.",
"zh-cn": "将代码下载到您的ECS上的路径。【不填默认下载到/root/workspace/{当前执行的ID}。如您需指定路径,请确保您提供的路径下没有文件,否则会拉取失败。】"
},
"Type": "String",
"Default": ""
},
"isDockerBuild": {
"Label": {
"en": "IsDockerBuild",
"zh-cn": "是否使用Docker构建"
},
"Description": {
"en": "If yes, it will detect if Docker is already installed on your ECS, and if not, it will be installed automatically for you.",
"zh-cn": "如果选择是,会检测您的ECS上是否已安装Docker,如果没有会为您自动安装。"
},
"Type": "Boolean",
"Default": false
},
"buildOption": {
"Label": {
"en": "buildOption",
"zh-cn": "构建部署模式"
},
"Description": {
"en": "For automated mode, you only need to provide the relevant information, and the execution will automatically complete the docker build image and the docker run startup container. You can also choose custom scripting mode to manually write build deployment scripts.",
"zh-cn": "对于自动化模式,您仅需提供相关信息,执行会自动完成docker build构建镜像和docker run启动容器。您也可以选择自定义脚本模式,手动编写构建部署脚本。"
},
"Type": "String",
"Default": "Automation",
"AllowedValues": [
"Automation",
"Script"
],
"AssociationPropertyMetadata": {
"Visible": {
"Condition": {
"Fn::Equals": [
"${isDockerBuild}",
true
]
}
},
"ValueLabelMapping": {
"Automation": "自动化模式",
"Script": "自定义脚本模式"
}
}
},
"dockerFilePath": {
"Label": {
"en": "Dockerfile Path",
"zh-cn": "Dockerfile路径"
},
"Description": {
"en": "Please drop down to select the Dockerfile in the code.",
"zh-cn": "请下拉选择代码中的Dockerfile。"
},
"Type": "String",
"Default": "",
"AssociationProperty": "ALIYUN::OOS::GitContent::Content",
"AssociationPropertyMetadata": {
"Platform": "${platform}",
"Owner": "${owner}",
"OrgId": "${organization}",
"RepoFullName": "${repository}",
"Branch": "${branch}",
"Visible": {
"Condition": {
"Fn::Equals": [
"${buildOption}",
"Automation"
]
}
},
"Required": {
"Condition": {
"Fn::Equals": [
"${buildOption}",
"Automation"
]
}
}
}
},
"contextPath": {
"Label": {
"en": "Context Path",
"zh-cn": "上下文路径"
},
"Description": {
"en": "Context Path as the path of the context directory relative to the root directory of the code repository",
"zh-cn": "docker build命令执行的上下文路径, 填写相对于代码库根目录的路径,如.或./config/。如不填写,默认为Dockerfile文件所在目录。"
},
"Type": "String",
"Default": "",
"AssociationPropertyMetadata": {
"Visible": {
"Condition": {
"Fn::Equals": [
"${buildOption}",
"Automation"
]
}
}
}
},
"dockerRunOptions": {
"Label": {
"en": "DockerRunOptions",
"zh-cn": "Docker运行选项"
},
"Description": {
"en": "DockerRunOptions, represents the options of the command \"docker run\", such as \"-p 80:80\". These will be added to the docker run command. Note that --name is not open for specification, OOS will automatically generate the default container name.",
"zh-cn": "docker run命令的选项, 例如\"-p 80:80\",这些选项会被添加到docker run命令中。注意,--name不开放指定,由OOS自动生成默认容器名。"
},
"Type": "String",
"AllowedPattern": "^(?!.*--name).*$",
"Default": "",
"AssociationPropertyMetadata": {
"Visible": {
"Condition": {
"Fn::Equals": [
"${buildOption}",
"Automation"
]
}
}
}
},
"buildAndDeployScript": {
"Label": {
"en": "buildAndDeployScript",
"zh-cn": "构建部署脚本"
},
"Description": {
"en": "Script execution takes the root directory of the code as its working directory.",
"zh-cn": "脚本执行会以您指定的下载路径作为工作路径。"
},
"Type": "String",
"MaxLength": 16384,
"AssociationProperty": "ALIYUN::OOS::Command::CommandContent",
"Default": "",
"AssociationPropertyMetadata": {
"Visible": {
"Condition": {
"Fn::Not": {
"Fn::Equals": [
"${buildOption}",
"Automation"
]
}
}
},
"CommandType": "RunShellScript",
"Value": [
{
"Condition": {
"Fn::And": [
{
"Fn::Equals": [
"${isDockerBuild}",
true
]
},
{
"Fn::Equals": [
"${buildOption}",
"Script"
]
}
]
},
"Value": "##### 请注意不要在这里填写Dockerfile内容,这里应该填写用于构建部署的shell命令,可参考下面的示例。\n##### Please do not fill in the Dockerfile content here, but fill in the build command, refer to the example below.\n\n### Build latest image\n# docker build -f Dockerfile -t myapp:latest .\n# container_name=\"my-container\"\n\n### Stop the previous version of the container (if any)\n# container_id=$(docker ps -aq -f name=${container_name}) \n# if [ -n \"$container_id\" ]; then\n# docker stop $container_id\n# docker rm $container_id\n# fi\n\n### Start the current version of the container\n# docker run -d -p 8080:8080 --name ${container_name} myapp:latest\n\n##### end"
},
{
"Condition": {
"Fn::Equals": [
"${isDockerBuild}",
false
]
},
"Value": "##### Sample Java Deploy Script \n##### for ECS on Alibaba Cloud Linux 3.2104\n\n### Build jar file.\n# set -e\n# yum install -y maven-3.5.4\n# mvn package\n\n### Stop the previous version of the application (if any) and deploy the current version.\n# PID=$(ps -ef | grep \"sample-spring-1.0-SNAPSHOT.jar\" | grep -v \"grep\" | awk '{print $2}')\n# if [ -n \"$PID\" ]; then\n# kill -9 $PID\n# fi\n# java -jar target/sample-spring-1.0-SNAPSHOT.jar &\n\n##### end"
}
]
}
}
},
"RamRole": "",
"Tasks": [
{
"Name": "GitCodeRepo",
"Action": "ACS::CICD::GitCodeRepo",
"Description": "指定代码源,生成临时授权链接",
"Properties": {
"organization": "{{ organization }}",
"platform": "{{ platform }}",
"owner": "{{ owner }}",
"repository": "{{ repository }}",
"branch": "{{ branch }}"
}
},
{
"Name": "LocalBuildAndDeploy",
"Action": "ACS::CICD::LocalBuildAndDeploy",
"Description": "拉取代码,构建并部署应用",
"Properties": {
"instanceId": "{{ instanceId }}",
"codeSource": "git",
"isDockerBuild": "{{ isDockerBuild }}",
"codeSourceUrl": "{{ GitCodeRepo.authorizedUrl }}",
"buildAndDeployScript": {
"Fn::If": [
{
"Fn::And": [
{
"Fn::Equals": [
"{{ buildOption }}",
"Automation"
]
},
{
"Fn::Equals": [
"{{ isDockerBuild }}",
true
]
}
]
},
{
"Fn::Sub": [
"repository=$(echo \"{{repository}}\" | sed 's/[^a-zA-Z0-9 ]/-/g')\ncurrent_image_version={{platform}}-{{owner}}-$repository:{{ACS::ExecutionId}}\ndocker build -f {{dockerFilePath}} -t $current_image_version ${FinalContextPath}\n\ncontainer_name={{platform}}-{{owner}}-$repository\ncontainer_id=$(docker ps -aq -f name=$container_name) \nif [ -n \"$container_id\" ]; then\n docker stop $container_id\n docker rm $container_id\nfi\n\ndocker run -d --name $container_name {{ dockerRunOptions }} $current_image_version",
{
"FinalContextPath": {
"Fn::If": [
{
"Fn::Equals": [
"{{ contextPath }}",
""
]
},
{
"Fn::If": [
{
"Fn::ContainsSubString": [
"{{ dockerFilePath }}",
"/"
]
},
{
"Fn::Join": [
"/",
{
"Fn::RangeSelect": [
0,
-1,
{
"Fn::Split": [
"/",
"{{ dockerFilePath }}"
]
}
]
}
]
},
"."
]
},
"{{ contextPath }}"
]
}
}
]
},
"{{ buildAndDeployScript }}"
]
},
"workingDir": {
"Fn::If": [
{
"Fn::Equals": [
"{{ downloadPath }}",
""
]
},
"/root/workspace/{{ACS::ExecutionId}}",
"{{ downloadPath }}"
]
}
},
"Outputs": {
"downloadCodeFromOssOutput": {
"Type": "String",
"ValueSelector": "downloadCodeFromOssOutput"
},
"downloadCodeFromGitOutput": {
"Type": "String",
"ValueSelector": "downloadCodeFromGitOutput"
},
"installDockerOutput": {
"Type": "String",
"ValueSelector": "installDockerOutput"
},
"buildAndDeployOutput": {
"Type": "String",
"ValueSelector": "buildAndDeployOutput"
}
}
}
],
"Outputs": {
"commandOutput": {
"Type": "String",
"Value": "{{ LocalBuildAndDeploy.buildAndDeployOutput }}"
}
},
"Metadata": {
"ALIYUN::OOS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"platform",
"owner",
"organization",
"repository",
"branch",
"downloadPath"
],
"Label": {
"default": {
"zh-cn": "代码源配置",
"en": "Code Source Configuration"
}
}
},
{
"Parameters": [
"isDockerBuild",
"buildOption",
"buildAndDeployScript",
"dockerFilePath",
"contextPath",
"dockerRunOptions"
],
"Label": {
"default": {
"zh-cn": "构建部署配置",
"en": "Build and Deploy Configuration"
}
}
}
]
}
}
}