forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodejs-single-instance.yml
381 lines (379 loc) · 12.1 KB
/
nodejs-single-instance.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
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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 部署Node.js环境于CentOS ECS,含VPC、安全组、自动脚本安装与配置,适用于测试。
en: Deploying a Node.js environment on a CentOS Elastic Compute Service (ECS) instance,
encompassing Virtual Private Cloud (VPC) setup, Security Group configuration,
automated script installation, and customization, tailored for testing purposes.
Parameters:
VpcName:
Type: String
Label:
en: VPC Name
zh-cn: VPC名称
Description:
en: Name of VPC, [2, 128] English or Chinese characters, must start with a letter
or Chinese in size, can contain numbers, '_' or '.', '-'.
zh-cn: VPC 名称,[2,128]英文或中文字符,必须以字母或中文开头,可以包含数字、下划线或“.”、“-”。
ConstraintDescription:
en: '[2, 128] English or Chinese characters'
zh-cn: '[2, 128] 英文或中文字符'
Default: DefaultVPCTest
MinLength: 2
MaxLength: 128
VpcCidrBlock:
Type: String
Label:
en: VPC CIDR Block
zh-cn: VPC网段
Description:
en: 'The VPC IP network segment; <br>You can use the following IP network segments:
<br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font
color=''green''>[192.168.0.0/16]</font>'
zh-cn: VPC的IP网段;<br>您可以使用以下IP网段:<br><font color='green'>[10.0.0.0/8]</font><br><font
color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0/16]</font>
Default: 192.168.0.0/16
AllowedValues:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
VSwitchCidrBlock:
Type: String
Label:
en: VSwitch CIDR Block
zh-cn: 交换机网段
Description:
en: CIDR Block of created VSwitch,It must belong to itself VPC CIDR Block.
zh-cn: 创建的虚拟交换机的子网,它必须属于自己的VPC网段内
Default: 192.168.1.0/24
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区
Description:
en: ECS Available Zone ID,</font><a href='https://www.alibabacloud.com/help/doc-detail/123712.html'
target='_blank'><b> View region and zone info</b><font color='blue'></a>.
zh-cn: ECS可用区ID,</font><a href='https://help.aliyun.com/document_detail/123712.html'
target='_blank'><b> 查看可用区信息</b><font color='blue'></a>.
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
ImageId:
Type: String
Label:
en: Image ID
zh-cn: 镜像ID
Description:
en: Image ID, represents the image resource to startup one ECS instance, <font><a
href='https://www.alibabacloud.com/help/doc-detail/112977.html' target='_blank'><b>View
image resources</b></font color='blue'></a>
zh-cn: 镜像ID,ECS实例的镜像资源, <font><a href='https://help.aliyun.com/document_detail/112977.html'
target='_blank'><b>查看镜像资源</b></font color='blue'></a>
AssociationProperty: ALIYUN::ECS::Image::ImageId
AssociationPropertyMetadata:
InstanceType: ${InstanceType}
SupportedImageOwnerAlias:
- system
- self
- others
Default: centos_7_04_64_20G_alibase_201701015.vhd
InstanceName:
Type: String
Label:
en: Instance Name
zh-cn: ECS实例名称
Description:
en: The name of ECS instance, [2, 128] English or Chinese characters, must start
with a letter or Chinese in size, can contain numbers, '_' or '.', '-'.
zh-cn: ECS实例名称,[2,128]英文或中文字符,必须以字母或中文开头,可以包含数字、下划线或“.”、“-”。
Default: DefaultECSInstanceTest
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: ECS实例规格
Description:
en: The ECS instance type,go to the product console to ensure the current instance
is available, <font><a href='https://www.alibabacloud.com/help/doc-detail/25378.html'
target='_blank'><b>View instance types</b></font color='blue'></a>.
zh-cn: ECS实例类型,进入产品控制台确保当前实例可用, <font><a href='https://help.aliyun.com/document_detail/25378.html'
target='_blank'><b>查看实例类型</b></font color='blue'></a>
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
Default: ecs.c5.large
SystemDiskCategory:
Type: String
Label:
en: Instance System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
InstanceType: InstanceType
ZoneId: ZoneId
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: ECS实例密码
Description:
en: The 8-30 long login password of instance, consists of the uppercase, lowercase
letter and number. <br> special characters include()'~!@#$%^&*_-+=|{}[]:;'<>,.?/.
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()'~!@#$%^&*_-+=|{}[]:;'<>,.?/
ConstraintDescription:
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
AllowedPattern: '[a-zA-Z0-9-\(\)\`\~\!@\#\$%\^&\*-+=\|\{\}\[\]\:\;\‘\,\.\?\/]*'
MinLength: 8
MaxLength: 30
NoEcho: true
NodejsUrl:
Type: String
Label:
en: Nodejs Url
zh-cn: Nodejs地址
Description:
en: Download path.
zh-cn: 下载路径
Default: https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: VpcName
Metadata:
ALIYUN::ROS::Designer:
id: 7bb2c65d-4ffb-4d7a-a516-c3e2b2df89bd
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupEgress:
- DestCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: internet
PortRange: -1/-1
Priority: 1
SecurityGroupIngress:
- IpProtocol: all
NicType: internet
PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
Metadata:
ALIYUN::ROS::Designer:
id: e9186c23-cbfc-483e-9d3f-c09ccfbd78b7
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
CidrBlock:
Ref: VSwitchCidrBlock
Metadata:
ALIYUN::ROS::Designer:
id: afa532c5-54ab-4115-acd3-ca989d117b60
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId:
Ref: ImageId
InstanceName:
Ref: InstanceName
InstanceType:
Ref: InstanceType
IoOptimized: optimized
Password:
Ref: InstancePassword
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- WebServerConditionHandle
- CurlCli
- Fn::Join:
- ''
- - "#!/bin/bash \n"
- NodejsUrl=
- Ref: NodejsUrl
- '
'
- "cd /root \n"
- "yum -y install aria2 \n"
- "aria2c $NodejsUrl \n"
- "tar xvf node-v6.9.5-linux-x64.tar.xz \n"
- "ln -s /root/node-v6.9.5-linux-x64/bin/node /usr/local/bin/node \n"
- "ln -s /root/node-v6.9.5-linux-x64/bin/npm /usr/local/bin/npm \n"
- " \n"
- "yum -y install git \n"
- "git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git\
\ checkout `git describe --abbrev=0 --tags` \n"
- " \n"
- "echo \". ~/.nvm/nvm.sh\" >> /etc/profile \n"
- "source /etc/profile \n"
- " \n"
- "nvm list-remote \n"
- "nvm install v6.9.5 \n"
- "nvm install v7.4.0 \n"
- " \n"
- "nvm ls \n"
- "nvm use v7.4.0 \n"
- " \n"
- "cd /root \n"
- "touch example.js \n"
- "Hostname=`hostname` \n"
- "Port=3000 \n"
- "echo \"const http = require('http');\" >> example.js \n"
- "echo \"const hostname = '$Hostname';\" >> example.js \n"
- "echo \"const port = '$Port';\" >> example.js \n"
- "echo \"const server = http.createServer((req, res) => {\" >> example.js\
\ \n"
- "echo \"res.statusCode = 200;\" >> example.js \n"
- "echo \"res.setHeader('Content-Type', 'text/plain');\" >> example.js\
\ \n"
- "echo \"res.end('Hello World');\" >> example.js \n"
- "echo \"});\" >> example.js \n"
- "echo \"server.listen(port, hostname, () => {\" >> example.js \n"
- "echo \"});\" >> example.js \n"
- " \n"
- "node /root/example.js & \n"
- 'ros-notify -d ''{"data" : "Install Node.js."}''
'
Metadata:
ALIYUN::ROS::Designer:
id: 9105476e-936a-4c60-84cc-8e37c7c38ffb
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
Metadata:
ALIYUN::ROS::Designer:
id: 8f6e360b-6f3d-4236-8d7b-3ee6ef8ccb33
WebServerGroupWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WebServerConditionHandle
Timeout: 3600
DependsOn: WebServer
Metadata:
ALIYUN::ROS::Designer:
id: 54d36aab-8d28-480a-9f0b-295ddd7bc7d0
Outputs:
WebsiteURL:
Description: URL for newly created testing Node.js program.
Value:
Fn::Join:
- ''
- - http://
- Fn::GetAtt:
- WebServer
- PublicIp
- :3000
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- VpcName
- VpcCidrBlock
- VSwitchCidrBlock
Label:
default: VPC
- Parameters:
- ZoneId
- InstanceName
- InstanceType
- ImageId
- SystemDiskCategory
- InstancePassword
Label:
default: ECS
- Parameters:
- NodejsUrl
Label:
default: Nodejs
TemplateTags:
- acs:example:网站:部署Node.js开发测试环境
ALIYUN::ROS::Designer:
37e70ecc-1c3a-4dcc-9db6-7be93d810ef2:
source:
id: 54d36aab-8d28-480a-9f0b-295ddd7bc7d0
target:
id: 8f6e360b-6f3d-4236-8d7b-3ee6ef8ccb33
z: 1
54d36aab-8d28-480a-9f0b-295ddd7bc7d0:
position:
x: 498
y: 95
size:
height: 60
width: 60
z: 0
7bb2c65d-4ffb-4d7a-a516-c3e2b2df89bd:
embeds:
- afa532c5-54ab-4115-acd3-ca989d117b60
- e9186c23-cbfc-483e-9d3f-c09ccfbd78b7
position:
x: 193
y: 50
size:
height: 311
width: 237
z: 0
8f6e360b-6f3d-4236-8d7b-3ee6ef8ccb33:
position:
x: 498
y: 253
size:
height: 60
width: 60
z: 0
9105476e-936a-4c60-84cc-8e37c7c38ffb:
position:
x: 283
y: 128
size:
height: 60
width: 60
z: 2
afa532c5-54ab-4115-acd3-ca989d117b60:
embeds:
- 9105476e-936a-4c60-84cc-8e37c7c38ffb
position:
x: 245
y: 88
size:
height: 144
width: 131
z: 1
b7b870b0-9860-45c6-9cec-6b11a2a14a97:
source:
id: 9105476e-936a-4c60-84cc-8e37c7c38ffb
target:
id: e9186c23-cbfc-483e-9d3f-c09ccfbd78b7
z: 1
e9186c23-cbfc-483e-9d3f-c09ccfbd78b7:
position:
x: 283
y: 266
size:
height: 60
width: 60
z: 1