-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::CICD::LocalBuildAndDeploy.json
205 lines (205 loc) · 6.06 KB
/
ACS::CICD::LocalBuildAndDeploy.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
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::CICD::LocalBuildAndDeploy",
"name-zh-cn": "本地构建并部署",
"en": "Build and deploy the local code",
"zh-cn": "本地构建并部署"
},
"Parameters": {
"instanceId": {
"Label": {
"en": "InstanceId",
"zh-cn": "ECS实例ID"
},
"Description": {
"en": "The ID of ECS instance",
"zh-cn": "ECS实例ID"
},
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceId",
"AssociationPropertyMetadata": {
"RegionId": "{{ ACS::RegionId }}"
}
},
"codeSource": {
"Label": {
"en": "CodeResource",
"zh-cn": "代码源"
},
"Type": "String",
"AllowedValues": [
"oss",
"git"
]
},
"codeSourceUrl": {
"Label": {
"en": "CodeResourceUrl",
"zh-cn": "代码源链接"
},
"Type": "String",
"AssociationPropertyMetadata": {
"PropertyType": "ref"
}
},
"isDockerBuild": {
"Label": {
"en": "IsDockerBuild",
"zh-cn": "是否Docker构建"
},
"Description": {
"en": "If true, docker will automatically be install on your ecs.",
"zh-cn": "如果为true,会为您在ECS上自动安装Docker。"
},
"Type": "Boolean",
"Default": true
},
"workingDir": {
"Label": {
"en": "WorkingDir",
"zh-cn": "工作目录"
},
"Type": "String",
"Default": "/root/workspace/{{ACS::ExecutionId}}",
"Description": {
"en": "The code is pulled to this directory and the build deployment script is executed in this directory as a working directory.",
"zh-cn": "代码会被拉取到该目录,构建部署脚本也会以该目录作为执行的工作目录。"
}
},
"buildAndDeployScript": {
"Label": {
"en": "buildAndDeployScript",
"zh-cn": "构建部署脚本"
},
"Type": "String",
"MaxLength": 16384,
"AssociationProperty": "ALIYUN::OOS::Command::CommandContent",
"AssociationPropertyMetadata": {
"CommandType": "RunShellScript"
}
}
},
"Tasks": [
{
"Name": "downloadCodeFromOss",
"Action": "ACS::ECS::DownloadFile",
"When": {
"Fn::Equals": [
"{{ codeSource }}",
"oss"
]
},
"Description": {
"en": "Download code from OSS",
"zh-cn": "从OSS下载代码"
},
"Properties": {
"regionId": "{{ ACS::RegionId }}",
"instanceId": "{{ instanceId }}",
"sourceType": "https",
"sourcePath": "{{ codeSourceUrl }}",
"destinationDir": "{{ workingDir }}"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "commandOutput"
}
}
},
{
"Name": "downloadCodeFromGit",
"Action": "ACS::ECS::RunCommand",
"When": {
"Fn::Equals": [
"{{ codeSource }}",
"git"
]
},
"Description": {
"en": "Download code from git",
"zh-cn": "从git下载代码"
},
"Properties": {
"regionId": "{{ ACS::RegionId }}",
"instanceId": "{{ instanceId }}",
"commandType": "RunShellScript",
"commandContent": "#!/bin/bash\n# Function to install git on Ubuntu/Debian\ninstall_git_debian() {\n echo \"Installing git...\"\n sudo apt-get update\n sudo apt-get install git -y\n}\n\n# Function to install git on CentOS/Red Hat\ninstall_git_centos() {\n echo \"Installing git...\"\n sudo yum install git -y\n}\n\n# Identify the Operating System\n. /etc/os-release\n\ncase $ID in\n ubuntu|debian)\n echo \"Detected system: Ubuntu/Debian\"\n install_git_debian\n ;;\n centos|rhel|alinux)\n echo \"Detected system: CentOS/Red Hat\"\n install_git_centos\n ;;\n *)\n echo \"Unsupported Operating System: $ID\"\n exit 1\n ;;\nesac\n\necho \"Git installation script has completed.\"\nmkdir -p {{ workingDir }}\ncd {{ workingDir }}\ngit clone {{ codeSourceUrl }} ."
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "installDocker",
"When": {
"Fn::Equals": [
"{{ isDockerBuild }}",
true
]
},
"Description": {
"en": "Install environment",
"zh-cn": "安装Docker环境"
},
"Action": "ACS::ECS::ConfigureOOSPackageWithTemporaryURL",
"Properties": {
"regionId": "{{ ACS::RegionId }}",
"instanceId": "{{ instanceId }}",
"action": "install",
"packageName": "ACS-Extension-DockerCE-1853370294850618"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "commandOutput"
}
}
},
{
"Name": "buildAndDeploy",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Build and deploy",
"zh-cn": "构建并部署"
},
"Properties": {
"regionId": "{{ ACS::RegionId }}",
"instanceId": "{{ instanceId }}",
"commandType": "RunShellScript",
"workingDir": "{{ workingDir }}",
"commandContent": "{{ buildAndDeployScript }}",
"maxRetryInterval": 12,
"timeout": 3600
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
}
],
"Outputs": {
"downloadCodeFromOssOutput": {
"Type": "String",
"Value": "{{ downloadCodeFromOss.commandOutput }}"
},
"downloadCodeFromGitOutput": {
"Type": "String",
"Value": "{{ downloadCodeFromGit.commandOutput }}"
},
"installDockerOutput": {
"Type": "String",
"Value": "{{ installDocker.commandOutput }}"
},
"buildAndDeployOutput": {
"Type": "String",
"Value": "{{ buildAndDeploy.commandOutput }}"
}
}
}