-
Notifications
You must be signed in to change notification settings - Fork 35
/
ruby-on-rails-single-instance.yml
490 lines (483 loc) · 16.7 KB
/
ruby-on-rails-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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建单ECS实例配MySQL,运行Ruby on Rails应用,支持CentOS-7,含警告提示。
en: Provision a single ECS instance equipped with MySQL, deployed to run Ruby on
Rails applications, compatible with CentOS-7, inclusive of warning notifications.
Parameters:
VpcName:
Type: String
Label:
en: VPC Name
zh-cn: 虚拟专有网络名称
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: MyVPC
MinLength: 2
MaxLength: 128
VpcCidrBlock:
Type: String
Label:
en: VPC CIDR Block
zh-cn: VPC网段
Description:
en: 'The VPC CIDR Block; <br>You can use the following IP address ranges and
their subnets: <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网段;<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: 10.0.0.0/8
AllowedValues:
- 192.168.0.0/16
- 172.16.0.0/12
- 10.0.0.0/8
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: 10.0.10.0/24
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区ID
Description:
en: ECS Available Zone ID,<br><b>note: <font color='blue'>Before selecting,
please confirm that the Availability Zone supports the specification of creating
ECS resources</font></b>
zh-cn: ECS可用区ID,<br><b>注: <font color='blue'>选择可用区前请确认该可用区是否支持创建ECS资源的规格</font></b>
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
InstanceName:
Type: String
Label:
en: Instance Name
zh-cn: 实例名称
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: DefaultECSInstance
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例规格
Description:
en: <font color='blue'><b>1.Before selecting the model please confirm that the
current available zone under the model is in stock, some models need to be
reported in advance</b></font><br><font color='blue'><b>2.List of optional
models</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU 4GiB Intranet
bandwidth1Gbps In-grid sending and receiving packages30MillionPPS</font>]<br></b>[ecs.c5.xlarge
<font color='green'>4vCPU 8GiB Intranet bandwidth1.5Gbps In-grid sending and
receiving packages50MillionPPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU
16GiB Intranet bandwidth2.5Gbps In-grid sending and receiving packages80MillionPPS</font>]
zh-cn: <font color='blue'><b>1.选择机型前请先确认当前可用区下该机型是否有货,部分机型需要提前报备</b></font><br><font
color='blue'><b>2.可选机型列表</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU
4GiB 内网带宽1Gbps 内网收发包30万PPS</font>]<br></b>[ecs.c5.xlarge <font color='green'>4vCPU
8GiB 内网带宽1.5Gbps 内网收发包50万PPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU
16GiB 内网带宽2.5Gbps 内网收发包80万PPS</font>]
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${InstanceType}
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
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: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: '8'
MaxLength: '30'
NoEcho: true
DBName:
Type: String
Label:
en: DB Name
zh-cn: 数据库名称
Description:
en: MySQL database name, Must begin with a letter and consists of the uppercase,
lowercase letter and number,Not longer than 16 characters.
zh-cn: MySQL 数据库名,由小写字母、数字、下划线(_)组成,以字母开头。长度不超过16个字符。
ConstraintDescription:
en: Must begin with a letter and contain only alphanumeric characters.
zh-cn: 必须以字母开头并且只包含字母数字字符。
Default: MyDatabase
MinLength: 1
MaxLength: 64
DBPassword:
Type: String
Label:
en: DB Password
zh-cn: 数据库用户访问密码
Description:
en: The MySQL password, consisting of letters, numbers, and underline(_), 8
to 32 characters in length
zh-cn: MySQL密码,数据库访问大小写字母、数字和下划线(_),8-32个字符
ConstraintDescription:
en: Consisting of letters, numbers, and underline(_), 8 to 32 characters in
length
zh-cn: 由字母、数字和下划线(_)组成,长度为8到32个字符
MinLength: 8
MaxLength: 32
NoEcho: true
DBUser:
Type: String
Label:
en: DB User
zh-cn: 访问用户名
Description:
en: Username for MySQL database access, consists of the uppercase, lowercase
letter and number,Not longer than 16 characters.
zh-cn: MySQL数据库访问用户名, 由小写字母、数字、下划线(_)组成,以字母开头。长度不超过16个字符。
ConstraintDescription:
en: Must begin with a letter and contain only alphanumeric characters.
zh-cn: 必须以字母开头并且只包含字母数字字符。
Default: DBUser
MinLength: 1
MaxLength: 16
DBRootPassword:
Type: String
Label:
en: DB Root Password
zh-cn: 数据库Root密码
Description:
en: Root password for MySQL, consisting of letters, numbers, and underline(_),
8 to 32 characters in length
zh-cn: MySQL的root密码, 由字母、数字、下划线(_)组成,长度为8~32个字符
ConstraintDescription:
en: Consisting of letters, numbers, and underline(_), 8 to 32 characters in
length
zh-cn: 由字母、数字和下划线(_)组成,长度为8到32个字符
MinLength: 8
MaxLength: 32
NoEcho: true
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: VpcName
Metadata:
ALIYUN::ROS::Designer:
id: 33ec8514-1b03-425f-862a-35c70b2f462c
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
CidrBlock:
Ref: VSwitchCidrBlock
Metadata:
ALIYUN::ROS::Designer:
id: bdcc07fd-7a3b-4758-90a3-c931e25445b5
WebServerSecurityGroup:
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: 2a0aaeba-b844-4d44-a879-3bd35ca85c9f
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: WebServerSecurityGroup
ImageId: centos_7
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
'
- dbname=
- Ref: DBName
- '
'
- dbuser=
- Ref: DBUser
- '
'
- dbpassword=
- Ref: DBPassword
- '
'
- dbrootpassword=
- Ref: DBRootPassword
- " \n"
- 'export HOME=/root
'
- 'export PATH=$PATH:/usr/local/bin
'
- "curl -sSL https://get.rvm.io | bash \n"
- "source /etc/profile.d/rvm.sh \n"
- "rvm install 2.3.1 \n"
- "source /etc/profile.d/rvm.sh \n"
- "rvm --default use 2.3.1 \n"
- "gem update --system \n"
- "gem install rails \n"
- " \n"
- "# install mysql in centos-7 \n"
- "yum -y install mysql mysql-server mysql-devel mysql-libs \n"
- "yum -y install mariadb-server mariadb-client \n"
- "systemctl start mariadb.service \n"
- "systemctl enable mariadb.service \n"
- " \n"
- "# set mysql root password \n"
- "mysqladmin -u root password \"$dbrootpassword\" \n"
- "$(mysql $dbname -u root --password=\"$dbrootpassword\" >/dev/null 2>&1\
\ </dev/null); (( $? != 0 )) \n"
- " \n"
- "# create database \n"
- "touch /tmp/setup.mysql \n"
- "echo CREATE USER \"$dbuser\"@\"localhost\" IDENTIFIED BY \"'$dbpassword'\"\
\\; >> /tmp/setup.mysql \n"
- "echo GRANT ALL ON $dbname.* TO \"$dbuser\"@\"localhost\"\\; >> /tmp/setup.mysql\
\ \n"
- "echo FLUSH PRIVILEGES\\; >> /tmp/setup.mysql \n"
- "chmod 400 /tmp/setup.mysql \n"
- " \n"
- "mysql -u root --password=\"$dbrootpassword\" < /tmp/setup.mysql \n"
- "$(mysql $dbname -u root --password=\"$dbrootpassword\" >/dev/null 2>&1\
\ </dev/null); (( $? != 0 )) \n"
- " \n"
- "# install application \n"
- "touch /tmp/database.yml \n"
- "echo development: >> /tmp/database.yml \n"
- "echo \" adapter: mysql2\" >> /tmp/database.yml \n"
- "echo \" encoding: utf8\" >> /tmp/database.yml \n"
- "echo \" reconnect: false\" >> /tmp/database.yml \n"
- "echo \" pool: 5\" >> /tmp/database.yml \n"
- "echo \" database: $dbname\" >> /tmp/database.yml \n"
- "echo \" username: $dbuser\" >> /tmp/database.yml \n"
- "echo \" password: $dbpassword\" >> /tmp/database.yml \n"
- "echo \" socket: /var/lib/mysql/mysql.sock\" >> /tmp/database.yml\
\ \n"
- "chmod 400 /tmp/database.yml \n"
- " \n"
- "source /etc/profile.d/rvm.sh \n"
- "rvm use 2.3.1 \n"
- "/usr/local/rvm/scripts/rvm use 2.3.1 \n"
- "cd /root \n"
- " \n"
- "# Kill the rails server if it is running to allow update \n"
- "if pgrep ruby &> /dev/null ; then pkill -TERM ruby ; fi \n"
- " \n"
- "# Create a new application, with therubyracer javascript library \n"
- "rails new sample -d mysql --skip-spring --skip-bundle --force \n"
- "cd /root/sample \n"
- "sed -i 's/^# \\(.*therubyracer.*$\\)/\\1/' Gemfile \n"
- "bundle install \n"
- " \n"
- "yum -y install nodejs \n"
- "rails generate scaffold Note title:string body:text --force \n"
- " \n"
- "cd config \n"
- "mv database.yml database.yml.bak \n"
- "cd .. \n"
- "mv /tmp/database.yml config \n"
- "rake db:create db:migrate \n"
- " \n"
- "# Startup the application \n"
- "source /etc/profile.d/rvm.sh \n"
- "rvm use 2.3.1 \n"
- "/usr/local/rvm/scripts/rvm use 2.3.1 \n"
- " \n"
- "cd /root/sample \n"
- " \n"
- "rails server --binding 0.0.0.0 -p 80 -d \n"
- " \n"
- "# cleanup \n"
- "# rm -f /tmp/setup.mysql \n"
- 'ros-notify -d ''{"data" : "Install Ruby on rails."}''
'
Metadata:
ALIYUN::ROS::Designer:
id: 9abc8b0f-108a-4186-9517-7576554acc1f
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
Metadata:
ALIYUN::ROS::Designer:
id: 68e9da8c-1f83-4651-9c85-8cd766cddda1
WebServerGroupWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WebServerConditionHandle
Timeout: 3600
DependsOn: WebServer
Metadata:
ALIYUN::ROS::Designer:
id: a5f44003-e470-4fca-beb6-ef5ea65368b0
Outputs:
WebsiteURL:
Description:
en: URL for newly created Ruby on Rails application
zh-cn: 新创建的Ruby on Rails应用程序的URL
Value:
Fn::Join:
- ''
- - http://
- Fn::GetAtt:
- WebServer
- PublicIp
- /notes
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- VpcName
- VpcCidrBlock
- VSwitchCidrBlock
Label:
default:
en: VPC
zh-cn: 专有网络
- Parameters:
- ZoneId
- InstanceName
- InstanceType
- SystemDiskCategory
- InstancePassword
Label:
default:
en: ECS
zh-cn: 云服务器
- Parameters:
- DBName
- DBPassword
- DBUser
- DBRootPassword
Label:
default:
en: DB
zh-cn: 数据库
TemplateTags:
- acs:example:网站:创建一个ECSInstance和本地MySQL部署RubyOnRails
ALIYUN::ROS::Designer:
2a0aaeba-b844-4d44-a879-3bd35ca85c9f:
position:
x: 341
y: 255
size:
height: 60
width: 60
z: 1
33ec8514-1b03-425f-862a-35c70b2f462c:
embeds:
- bdcc07fd-7a3b-4758-90a3-c931e25445b5
- 2a0aaeba-b844-4d44-a879-3bd35ca85c9f
position:
x: 268
y: 79
size:
height: 257
width: 198.3134765625
z: 0
44ad3021-0347-413a-80f9-fabbcaf14f86:
source:
id: a5f44003-e470-4fca-beb6-ef5ea65368b0
target:
id: 68e9da8c-1f83-4651-9c85-8cd766cddda1
z: 1
68e9da8c-1f83-4651-9c85-8cd766cddda1:
position:
x: 547
y: 106
size:
height: 60
width: 60
z: 0
9abc8b0f-108a-4186-9517-7576554acc1f:
position:
x: 341
y: 149
size:
height: 60
width: 60
z: 2
a5f44003-e470-4fca-beb6-ef5ea65368b0:
position:
x: 547
y: 243
size:
height: 60
width: 60
z: 0
bdcc07fd-7a3b-4758-90a3-c931e25445b5:
embeds:
- 9abc8b0f-108a-4186-9517-7576554acc1f
position:
x: 293
y: 102
size:
height: 138
width: 149
z: 1
fd6b1c7c-19b3-4c5e-a20e-1b1c080ec92c:
source:
id: 9abc8b0f-108a-4186-9517-7576554acc1f
target:
id: 2a0aaeba-b844-4d44-a879-3bd35ca85c9f
z: 1