forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecs-with-nodejs-enviroment.yml
230 lines (228 loc) · 6.79 KB
/
ecs-with-nodejs-enviroment.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create an ECS instance, install Node.js environment and test. *** WARNING ***
This template only supports CentOS.
zh-cn: 创建一个ECS实例,安装Node.js环境并测试。 ***警告*** 此模板仅支持 CentOS。
Parameters:
IoOptimized:
Type: String
Label: Io Optimized
Description: The 'optimized' instance can provide better IO performance. Support
'none' and 'optimized' only, default is 'optimized'.
Default: optimized
AllowedValues:
- none
- optimized
ImageId:
Type: String
Label: ECS Image Id
Description: Image Id, represents the image resource to startup one ECS instance,
<a href='#/product/cn-beijing/list/imageList' target='_blank'>View image resources</a>
Default: centos_7
VpcName:
Type: String
Label: Vpc Name
Description: Name of VPC
ConstraintDescription: '[2, 128] English or Chinese characters'
MinLength: 2
MaxLength: 128
VpcCidrBlock:
Type: String
Label: Vpc Cidr Block
Description: |-
The IP address range of the VPC in the CIDR block form. You can use the following IP address ranges and their subnets:
10.0.0.0/8
172.16.0.0/12 (Default)
192.168.0.0/16
Default: 192.168.0.0/16
AllowedValues:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
InstancePassword:
Type: String
Label: ECS Instance Password
Description: The root password of ECS instance. The password is a string of 8
to 41 characters and must contain uppercase/lowercase letters, numbers.
ConstraintDescription: Consist of 8 to 30 alphanumeric.
AllowedPattern: '[a-zA-Z0-9]*'
MinLength: '8'
MaxLength: '30'
NoEcho: true
Confirm: true
ZoneId:
Type: String
Label: ECS Zone Id
Description: Ecs Available Zone Id, <a href='#/product/cn-beijing/list/zoneList'
target='_blank'>View zoneid info</a>
SystemDiskCategory:
Type: String
Label: Instance System Disk Category
Description: 'System disk category: average cloud disk(cloud), efficient cloud
disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)'
Default: cloud_ssd
AllowedValues:
- cloud
- cloud_efficiency
- cloud_ssd
NodejsUrl:
Type: String
Label: Node js Url
Description: The official download path of .tar.gz
Default: https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz
InstanceName:
Type: String
Label: ECS Instance Name
Description: The name of ECS instance
Default: ecsinstance
VSwitchCidrBlock:
Type: String
Label: VSwitch Cidr Block
Description: Cidr Block of created VSwitch
Default: 192.168.1.0/24
InstanceType:
Type: String
Label: ECS Instance Type
Description: The ECS instance type, <a href='#/product/cn-beijing/list/typeList'
target='_blank'>View instance types</a>
Default: ecs.c5.large
AllowedValues:
- ecs.c5.large
- ecs.g5.large
- ecs.c5.xlarge
- ecs.g5.xlarge
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: VpcName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
CidrBlock:
Ref: VSwitchCidrBlock
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- SourceCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: internet
PortRange: -1/-1
Priority: 1
SecurityGroupEgress:
- IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
PortRange: -1/-1
Priority: 1
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId:
Ref: ImageId
IoOptimized:
Ref: IoOptimized
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."}''
'
InstanceName:
Ref: InstanceName
InstanceType:
Ref: InstanceType
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WebServerGroupWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Handle:
Ref: WebServerConditionHandle
Timeout: 3600
Count: 1
DependsOn: WebServer
Outputs:
WebsiteURL:
Description: URL for newly created testing Node.js program.
Value:
Fn::Join:
- ''
- - http://
- Fn::GetAtt:
- WebServer
- PublicIp
- :3000