-
Notifications
You must be signed in to change notification settings - Fork 35
/
docker-alibaba-cloud-linux-2.yml
301 lines (297 loc) · 9.05 KB
/
docker-alibaba-cloud-linux-2.yml
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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 在Alibaba Cloud Linux 2.1903 LTS 64位ECS上自动部署Docker,含VPC、安全组配置与端口开放,支持新创实例或指定现有实例。
en: Automatically deploy Docker on Alibaba Cloud Linux 2.1903 LTS 64-bit ECS, including
configuration of VPC, security groups, and port opening, with support for both
newly created instances and specified existing instances.
Conditions:
CreateInstance:
Fn::Equals:
- Ref: SelectInstance
- false
Parameters:
SelectInstance:
Type: Boolean
Label:
en: Whether to select an existing instance
zh-cn: 是否选择已有实例
Default: true
InstanceId:
Type: String
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- true
Default:
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区ID
Description:
en: The available zone ID, you should confirm the zone support ECS、VPC、VSwitch
or not.
zh-cn: 可用区ID,需确认所选可用区下是否支持ECS、VPC、VSwitch等资源。
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- false
Default:
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- false
Default: ecs.g6.large
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${InstanceType}
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- false
Default:
Password:
Type: String
Label:
en: Login Password
zh-cn: 实例密码
Description:
en: |-
The password must be 8 to 32 characters in length. <br>
It must consist three of the the following character types: uppercase letters, lowercase letters, digits, and special characters. <br>
Special characters include <span style="background:#E7E9EB;"><b>()`~!@#$%^&*_-+=|{}[]:;'<>,.?/</b></span>.<br>
zh-cn: 长度为8-30位,需包含大写字母、小写字母、特殊符号和数字中的三个,允许的特殊字符包括<span style="background:#E7E9EB;"><b>()`~!@#$%^&*_-+=|{}[]:;'<>,.?/</b></span>。
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- false
Default:
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Condition: CreateInstance
Properties:
CidrBlock: 192.168.0.0/16
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Condition: CreateInstance
Properties:
VpcId:
Ref: Vpc
VSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateInstance
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
InstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Condition: CreateInstance
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_2_1903_x64_20G_alibase_20230522.vhd
InstanceType:
Ref: InstanceType
SystemDiskCategory:
Ref: SystemDiskCategory
Password:
Ref: Password
IoOptimized: optimized
MaxAmount: 1
DS_Instances:
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
Fn::If:
- CreateInstance
- Fn::GetAtt:
- InstanceGroup
- InstanceIds
- [Ref: InstanceId]
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Handle:
Ref: WaitConditionHandle
Timeout: 3720
Count: 1
SecurityGroupIngress_22:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 80/80
SecurityGroupIngress_443:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 443/443
InstallDocker:
Type: ALIYUN::ECS::RunCommand
DependsOn:
- SecurityGroupIngress_22
- SecurityGroupIngress_443
- SecurityGroupIngress_80
Properties:
InstanceIds:
Fn::If:
- CreateInstance
- Fn::GetAtt:
- InstanceGroup
- InstanceIds
- [Ref: InstanceId]
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
if [ ! -f .ros.provision ]; then
echo "Name: 部署docker(Alibaba Cloud Linux 2)" > .ros.provision
fi
name=$(grep "^Name:" .ros.provision | awk -F':' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$name" != "部署docker(Alibaba Cloud Linux 2)" ]]; then
echo "当前实例已使用过\"$name\"教程的一键配置,不能再使用本教程的一键配置"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance has already applied the configuration of the \\\"$name\\\" tutorial, and the configuration of this tutorial can no longer be applied.\"}"
exit 0
fi
echo "#########################"
echo "# Check Network"
echo "#########################"
ping -c 2 -W 2 aliyun.com > /dev/null
if [[ $? -ne 0 ]]; then
echo "当前实例无法访问公网"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance cannot access the public network.\"}"
exit 0
fi
if ! grep -q "^Step1: Prepare Environment$" .ros.provision; then
echo "#########################"
echo "# Prepare Environment"
echo "#########################"
systemctl status firewalld
systemctl stop firewalld
echo "Step1: Prepare Environment" >> .ros.provision
else
echo "#########################"
echo "# Environment has been ready"
echo "#########################"
fi
if ! grep -q "^Step2: Install Docker$" .ros.provision; then
echo "#########################"
echo "# Install Docker"
echo "#########################"
yum -y install docker
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install yum-plugin-releasever-adapter --disablerepo=* --enablerepo=plus
yum -y install docker-ce
systemctl start docker
echo "Step2: Install Docker" >> .ros.provision
else
echo "#########################"
echo "# Docker has been installed"
echo "#########################"
fi
${WaitConditionHandle.CurlCli} --data-binary '{"status": "SUCCESS"}'
Outputs:
ECSPublicIP:
Description:
en: Public Ip of ECS.
zh-cn: ECS公网IP。
Value:
Fn::Sub:
- http://${IP}
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress
end
- Fn::GetAtt:
- DS_Instances
- Instances
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- SelectInstance
- InstanceId
- ZoneId
- InstanceType
- SystemDiskCategory
- Password
Label:
default: ECS
TemplateTags:
- acs:document-help:ecs:部署并使用Docker(Alibaba Cloud Linux 2)