dslh 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dslh.rb +59 -54
- data/lib/dslh/version.rb +1 -1
- data/spec/Drupal_Single_Instance.template +270 -0
- data/spec/dslh_spec.rb +370 -3
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d2dfc05d04e7e6e193b066d2ecb8c7cff66c543
|
4
|
+
data.tar.gz: 33496a369aa2d80a63a5cf4aeceb3bf2f9141a10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89010f761b726a054d10815815c5971e3dd20937410cd1b533272edbd6cd4b133e18f16021f67c1e7eec125d98ca9c2cf322ae66eadbeda2df8f19a088996ef5
|
7
|
+
data.tar.gz: ce5a58b6eff9972b0621e3a62ec2ec42f36a9e677990dfa7028ef2ffef7f4db1128b743cc2c167cbd976fc65db49fb7dcc7339b8c1b60d67c8e5703a963ac7f4
|
data/lib/dslh.rb
CHANGED
@@ -75,70 +75,20 @@ class Dslh
|
|
75
75
|
|
76
76
|
def deval0(hash, depth, buf)
|
77
77
|
indent = (INDENT_SPACES * depth)
|
78
|
-
next_indent = (INDENT_SPACES * (depth + 1))
|
79
78
|
key_conv = @options[:key_conv]
|
80
79
|
value_conv = @options[:value_conv]
|
81
|
-
nested = false
|
82
80
|
|
83
|
-
if
|
81
|
+
if exclude_keys?(hash.keys)
|
84
82
|
buf.puts('(' + ("\n" + hash.pretty_inspect.strip).gsub("\n", "\n" + indent) + ')')
|
85
83
|
return
|
86
84
|
end
|
87
85
|
|
88
86
|
hash.each do |key, value|
|
89
|
-
value_proc = proc do |value_buf|
|
90
|
-
case value
|
91
|
-
when Hash
|
92
|
-
if exclude_key?(value.keys)
|
93
|
-
value_buf.puts('(' + ("\n" + value.pretty_inspect.strip).gsub("\n", "\n" + next_indent) + ')')
|
94
|
-
else
|
95
|
-
nested = true
|
96
|
-
value_buf.puts(' do')
|
97
|
-
deval0(value, depth + 1, value_buf)
|
98
|
-
value_buf.puts(indent + 'end')
|
99
|
-
end
|
100
|
-
when Array
|
101
|
-
if value.any? {|v| [Array, Hash].any? {|c| v.kind_of?(c) }}
|
102
|
-
nested = true
|
103
|
-
value_buf.puts(' [')
|
104
|
-
|
105
|
-
value.each_with_index do |v, i|
|
106
|
-
if v.kind_of?(Hash)
|
107
|
-
value_buf.puts(next_indent + '_{')
|
108
|
-
deval0(v, depth + 2, value_buf)
|
109
|
-
value_buf.print(next_indent + '}')
|
110
|
-
else
|
111
|
-
value_buf.print(next_indent + v.pretty_inspect.strip.gsub("\n", "\n" + next_indent))
|
112
|
-
end
|
113
|
-
|
114
|
-
value_buf.puts(i < (value.length - 1) ? ',' : '')
|
115
|
-
end
|
116
|
-
|
117
|
-
value_buf.puts(indent + ']')
|
118
|
-
elsif value.length == 1
|
119
|
-
value_buf.puts(' ' + value.inspect)
|
120
|
-
else
|
121
|
-
value_buf.puts(' ' + value.map {|v|
|
122
|
-
v = value_conv.call(v) if value_conv
|
123
|
-
|
124
|
-
if v.kind_of?(Hash)
|
125
|
-
'(' + v.inspect + ')'
|
126
|
-
else
|
127
|
-
v.inspect
|
128
|
-
end
|
129
|
-
}.join(', '))
|
130
|
-
end
|
131
|
-
else
|
132
|
-
value = value_conv.call(value) if value_conv
|
133
|
-
value_buf.puts(' ' + value.inspect)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
87
|
key = key_conv.call(key) if key_conv
|
138
88
|
|
139
89
|
if key.kind_of?(Proc)
|
140
90
|
tmp_buf = StringIO.new
|
141
|
-
value_proc
|
91
|
+
nested = value_proc(value, depth, tmp_buf)
|
142
92
|
|
143
93
|
key_value = case key.arity
|
144
94
|
when 0
|
@@ -152,12 +102,67 @@ class Dslh
|
|
152
102
|
buf.puts(indent + key_value)
|
153
103
|
else
|
154
104
|
buf.print(indent + key)
|
155
|
-
value_proc
|
105
|
+
value_proc(value, depth, buf)
|
156
106
|
end
|
157
107
|
end
|
158
108
|
end
|
159
109
|
|
160
|
-
def
|
110
|
+
def value_proc(value, depth, value_buf)
|
111
|
+
indent = (INDENT_SPACES * depth)
|
112
|
+
next_indent = (INDENT_SPACES * (depth + 1))
|
113
|
+
value_conv = @options[:value_conv]
|
114
|
+
nested = false
|
115
|
+
|
116
|
+
case value
|
117
|
+
when Hash
|
118
|
+
if exclude_keys?(value.keys)
|
119
|
+
value_buf.puts('(' + ("\n" + value.pretty_inspect.strip).gsub("\n", "\n" + next_indent) + ')')
|
120
|
+
else
|
121
|
+
nested = true
|
122
|
+
value_buf.puts(' do')
|
123
|
+
deval0(value, depth + 1, value_buf)
|
124
|
+
value_buf.puts(indent + 'end')
|
125
|
+
end
|
126
|
+
when Array
|
127
|
+
if value.any? {|v| [Array, Hash].any? {|c| v.kind_of?(c) }}
|
128
|
+
nested = true
|
129
|
+
value_buf.puts(' [')
|
130
|
+
|
131
|
+
value.each_with_index do |v, i|
|
132
|
+
if v.kind_of?(Hash)
|
133
|
+
value_buf.puts(next_indent + '_{')
|
134
|
+
deval0(v, depth + 2, value_buf)
|
135
|
+
value_buf.print(next_indent + '}')
|
136
|
+
else
|
137
|
+
value_buf.print(next_indent + v.pretty_inspect.strip.gsub("\n", "\n" + next_indent))
|
138
|
+
end
|
139
|
+
|
140
|
+
value_buf.puts(i < (value.length - 1) ? ',' : '')
|
141
|
+
end
|
142
|
+
|
143
|
+
value_buf.puts(indent + ']')
|
144
|
+
elsif value.length == 1
|
145
|
+
value_buf.puts(' ' + value.inspect)
|
146
|
+
else
|
147
|
+
value_buf.puts(' ' + value.map {|v|
|
148
|
+
v = value_conv.call(v) if value_conv
|
149
|
+
|
150
|
+
if v.kind_of?(Hash)
|
151
|
+
'(' + v.inspect + ')'
|
152
|
+
else
|
153
|
+
v.inspect
|
154
|
+
end
|
155
|
+
}.join(', '))
|
156
|
+
end
|
157
|
+
else
|
158
|
+
value = value_conv.call(value) if value_conv
|
159
|
+
value_buf.puts(' ' + value.inspect)
|
160
|
+
end
|
161
|
+
|
162
|
+
return nested
|
163
|
+
end
|
164
|
+
|
165
|
+
def exclude_keys?(keys)
|
161
166
|
key_conv = @options[:key_conv]
|
162
167
|
|
163
168
|
exclude_key = @options[:exclude_key] || proc {|k|
|
data/lib/dslh/version.rb
CHANGED
@@ -0,0 +1,270 @@
|
|
1
|
+
{
|
2
|
+
"AWSTemplateFormatVersion" : "2010-09-09",
|
3
|
+
|
4
|
+
"Description" : "AWS CloudFormation Sample Template Drupal_Single_Instance. Drupal is an open source content management platform powering millions of websites and applications. This template installs a singe instance deployment with a local MySQL database for storage. It uses the AWS CloudFormation bootstrap scripts to install packages and files at instance launch time. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",
|
5
|
+
|
6
|
+
"Parameters" : {
|
7
|
+
|
8
|
+
"KeyName": {
|
9
|
+
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
|
10
|
+
"Type": "String",
|
11
|
+
"MinLength": "1",
|
12
|
+
"MaxLength": "255",
|
13
|
+
"AllowedPattern" : "[\\x20-\\x7E]*",
|
14
|
+
"ConstraintDescription" : "can contain only ASCII characters."
|
15
|
+
},
|
16
|
+
|
17
|
+
"InstanceType" : {
|
18
|
+
"Description" : "WebServer EC2 instance type",
|
19
|
+
"Type" : "String",
|
20
|
+
"Default" : "m1.small",
|
21
|
+
"AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","m3.xlarge","m3.2xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"],
|
22
|
+
"ConstraintDescription" : "must be a valid EC2 instance type."
|
23
|
+
},
|
24
|
+
|
25
|
+
"SiteName": {
|
26
|
+
"Default": "My Site",
|
27
|
+
"Description" : "The name of the Drupal Site",
|
28
|
+
"Type": "String"
|
29
|
+
},
|
30
|
+
|
31
|
+
"SiteEMail": {
|
32
|
+
"Description" : "EMail for site adminitrator",
|
33
|
+
"Type": "String"
|
34
|
+
},
|
35
|
+
|
36
|
+
"SiteAdmin": {
|
37
|
+
"Description" : "The Drupal site admin account username",
|
38
|
+
"Type": "String",
|
39
|
+
"MinLength": "1",
|
40
|
+
"MaxLength": "16",
|
41
|
+
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
|
42
|
+
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
|
43
|
+
},
|
44
|
+
|
45
|
+
"SitePassword": {
|
46
|
+
"NoEcho": "true",
|
47
|
+
"Description" : "The Drupal site admin account password",
|
48
|
+
"Type": "String",
|
49
|
+
"MinLength": "1",
|
50
|
+
"MaxLength": "41",
|
51
|
+
"AllowedPattern" : "[a-zA-Z0-9]*",
|
52
|
+
"ConstraintDescription" : "must contain only alphanumeric characters."
|
53
|
+
},
|
54
|
+
|
55
|
+
"DBName": {
|
56
|
+
"Default": "drupaldb",
|
57
|
+
"Description" : "The Drupal database name",
|
58
|
+
"Type": "String",
|
59
|
+
"MinLength": "1",
|
60
|
+
"MaxLength": "64",
|
61
|
+
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
|
62
|
+
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
|
63
|
+
},
|
64
|
+
|
65
|
+
"DBUsername": {
|
66
|
+
"Default": "admin",
|
67
|
+
"NoEcho": "true",
|
68
|
+
"Description" : "The Drupal database admin account username",
|
69
|
+
"Type": "String",
|
70
|
+
"MinLength": "1",
|
71
|
+
"MaxLength": "16",
|
72
|
+
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
|
73
|
+
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
|
74
|
+
},
|
75
|
+
|
76
|
+
"DBPassword": {
|
77
|
+
"Default": "admin",
|
78
|
+
"NoEcho": "true",
|
79
|
+
"Description" : "The Drupal database admin account password",
|
80
|
+
"Type": "String",
|
81
|
+
"MinLength": "1",
|
82
|
+
"MaxLength": "41",
|
83
|
+
"AllowedPattern" : "[a-zA-Z0-9]*",
|
84
|
+
"ConstraintDescription" : "must contain only alphanumeric characters."
|
85
|
+
},
|
86
|
+
|
87
|
+
"DBRootPassword": {
|
88
|
+
"NoEcho": "true",
|
89
|
+
"Description" : "Root password for MySQL",
|
90
|
+
"Type": "String",
|
91
|
+
"MinLength": "1",
|
92
|
+
"MaxLength": "41",
|
93
|
+
"AllowedPattern" : "[a-zA-Z0-9]*",
|
94
|
+
"ConstraintDescription" : "must contain only alphanumeric characters."
|
95
|
+
},
|
96
|
+
"SSHLocation" : {
|
97
|
+
"Description" : "The IP address range that can be used to SSH to the EC2 instances",
|
98
|
+
"Type": "String",
|
99
|
+
"MinLength": "9",
|
100
|
+
"MaxLength": "18",
|
101
|
+
"Default": "0.0.0.0/0",
|
102
|
+
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
|
103
|
+
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
|
104
|
+
}
|
105
|
+
},
|
106
|
+
|
107
|
+
"Mappings" : {
|
108
|
+
"AWSInstanceType2Arch" : {
|
109
|
+
"t1.micro" : { "Arch" : "64" },
|
110
|
+
"m1.small" : { "Arch" : "64" },
|
111
|
+
"m1.medium" : { "Arch" : "64" },
|
112
|
+
"m1.large" : { "Arch" : "64" },
|
113
|
+
"m1.xlarge" : { "Arch" : "64" },
|
114
|
+
"m2.xlarge" : { "Arch" : "64" },
|
115
|
+
"m2.2xlarge" : { "Arch" : "64" },
|
116
|
+
"m2.4xlarge" : { "Arch" : "64" },
|
117
|
+
"m3.xlarge" : { "Arch" : "64" },
|
118
|
+
"m3.2xlarge" : { "Arch" : "64" },
|
119
|
+
"c1.medium" : { "Arch" : "64" },
|
120
|
+
"c1.xlarge" : { "Arch" : "64" },
|
121
|
+
"cc1.4xlarge" : { "Arch" : "64HVM" },
|
122
|
+
"cc2.8xlarge" : { "Arch" : "64HVM" },
|
123
|
+
"cg1.4xlarge" : { "Arch" : "64HVM" }
|
124
|
+
},
|
125
|
+
|
126
|
+
"AWSRegionArch2AMI" : {
|
127
|
+
"us-east-1" : { "32" : "ami-a0cd60c9", "64" : "ami-aecd60c7", "64HVM" : "ami-a8cd60c1" },
|
128
|
+
"us-west-2" : { "32" : "ami-46da5576", "64" : "ami-48da5578", "64HVM" : "NOT_YET_SUPPORTED" },
|
129
|
+
"us-west-1" : { "32" : "ami-7d4c6938", "64" : "ami-734c6936", "64HVM" : "NOT_YET_SUPPORTED" },
|
130
|
+
"eu-west-1" : { "32" : "ami-61555115", "64" : "ami-6d555119", "64HVM" : "ami-67555113" },
|
131
|
+
"ap-southeast-1" : { "32" : "ami-220b4a70", "64" : "ami-3c0b4a6e", "64HVM" : "NOT_YET_SUPPORTED" },
|
132
|
+
"ap-southeast-2" : { "32" : "ami-b3990e89", "64" : "ami-bd990e87", "64HVM" : "NOT_YET_SUPPORTED" },
|
133
|
+
"ap-northeast-1" : { "32" : "ami-2a19aa2b", "64" : "ami-2819aa29", "64HVM" : "NOT_YET_SUPPORTED" },
|
134
|
+
"sa-east-1" : { "32" : "ami-f836e8e5", "64" : "ami-fe36e8e3", "64HVM" : "NOT_YET_SUPPORTED" }
|
135
|
+
}
|
136
|
+
},
|
137
|
+
|
138
|
+
"Resources" : {
|
139
|
+
|
140
|
+
"WebServer": {
|
141
|
+
"Type": "AWS::EC2::Instance",
|
142
|
+
"Metadata" : {
|
143
|
+
"AWS::CloudFormation::Init" : {
|
144
|
+
"config" : {
|
145
|
+
"packages" : {
|
146
|
+
"yum" : {
|
147
|
+
"httpd" : [],
|
148
|
+
"php" : [],
|
149
|
+
"php-mysql" : [],
|
150
|
+
"php-gd" : [],
|
151
|
+
"php-xml" : [],
|
152
|
+
"php-mbstring" : [],
|
153
|
+
"mysql" : [],
|
154
|
+
"mysql-server" : [],
|
155
|
+
"mysql-devel" : [],
|
156
|
+
"mysql-libs" : []
|
157
|
+
|
158
|
+
}
|
159
|
+
},
|
160
|
+
|
161
|
+
"sources" : {
|
162
|
+
"/var/www/html" : "http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz",
|
163
|
+
"/home/ec2-user" : "http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz"
|
164
|
+
},
|
165
|
+
|
166
|
+
"files" : {
|
167
|
+
"/tmp/setup.mysql" : {
|
168
|
+
"content" : { "Fn::Join" : ["", [
|
169
|
+
"CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
|
170
|
+
"CREATE USER '", { "Ref" : "DBUsername" }, "'@'localhost' IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
|
171
|
+
"GRANT ALL ON ", { "Ref" : "DBName" }, ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost';\n",
|
172
|
+
"FLUSH PRIVILEGES;\n"
|
173
|
+
]]},
|
174
|
+
"mode" : "000644",
|
175
|
+
"owner" : "root",
|
176
|
+
"group" : "root"
|
177
|
+
}
|
178
|
+
},
|
179
|
+
|
180
|
+
"services" : {
|
181
|
+
"sysvinit" : {
|
182
|
+
"httpd" : { "enabled" : "true", "ensureRunning" : "true" },
|
183
|
+
"mysqld" : { "enabled" : "true", "ensureRunning" : "true" },
|
184
|
+
"sendmail" : { "enabled" : "false", "ensureRunning" : "false" }
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
},
|
190
|
+
"Properties": {
|
191
|
+
"ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
|
192
|
+
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
|
193
|
+
"InstanceType" : { "Ref" : "InstanceType" },
|
194
|
+
"SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],
|
195
|
+
"KeyName" : { "Ref" : "KeyName" },
|
196
|
+
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
|
197
|
+
"#!/bin/bash -v\n",
|
198
|
+
"yum update -y aws-cfn-bootstrap\n",
|
199
|
+
|
200
|
+
|
201
|
+
"# Helper function\n",
|
202
|
+
"function error_exit\n",
|
203
|
+
"{\n",
|
204
|
+
" /opt/aws/bin/cfn-signal -e 0 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
|
205
|
+
" exit 1\n",
|
206
|
+
"}\n",
|
207
|
+
|
208
|
+
"# Install Apache Web Server, MySQL, PHP and Drupal\n",
|
209
|
+
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackId" }, " -r WebServer ",
|
210
|
+
" --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
|
211
|
+
|
212
|
+
"# Setup MySQL root password and create a user\n",
|
213
|
+
"mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "' || error_exit 'Failed to initialize root password'\n",
|
214
|
+
"mysql -u root --password='", { "Ref" : "DBRootPassword" }, "' < /tmp/setup.mysql || error_exit 'Failed to create database user'\n",
|
215
|
+
|
216
|
+
"# Make changes to Apache Web Server configuration\n",
|
217
|
+
"mv /var/www/html/drupal-7.8/* /var/www/html\n",
|
218
|
+
"mv /var/www/html/drupal-7.8/.* /var/www/html\n",
|
219
|
+
"rmdir /var/www/html/drupal-7.8\n",
|
220
|
+
"sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf\n",
|
221
|
+
"service httpd restart\n",
|
222
|
+
|
223
|
+
"# Create the site in Drupal\n",
|
224
|
+
"cd /var/www/html\n",
|
225
|
+
"~ec2-user/drush/drush site-install standard --yes",
|
226
|
+
" --site-name='", { "Ref" : "SiteName" }, "' --site-mail=", { "Ref" : "SiteEMail" },
|
227
|
+
" --account-name=", { "Ref" : "SiteAdmin" }, " --account-pass=", { "Ref" : "SitePassword" },
|
228
|
+
" --db-url=mysql://", { "Ref" : "DBUsername" }, ":", { "Ref" : "DBPassword" }, "@localhost/", { "Ref" : "DBName" },
|
229
|
+
" --db-prefix=drupal_\n",
|
230
|
+
"chown apache:apache sites/default/files\n",
|
231
|
+
|
232
|
+
"# All is well so signal success\n",
|
233
|
+
"/opt/aws/bin/cfn-signal -e 0 -r \"Drupal setup complete\" '", { "Ref" : "WaitHandle" }, "'\n"
|
234
|
+
|
235
|
+
]]}}
|
236
|
+
}
|
237
|
+
},
|
238
|
+
|
239
|
+
"WaitHandle" : {
|
240
|
+
"Type" : "AWS::CloudFormation::WaitConditionHandle"
|
241
|
+
},
|
242
|
+
|
243
|
+
"WaitCondition" : {
|
244
|
+
"Type" : "AWS::CloudFormation::WaitCondition",
|
245
|
+
"DependsOn" : "WebServer",
|
246
|
+
"Properties" : {
|
247
|
+
"Handle" : {"Ref" : "WaitHandle"},
|
248
|
+
"Timeout" : "300"
|
249
|
+
}
|
250
|
+
},
|
251
|
+
|
252
|
+
"WebServerSecurityGroup" : {
|
253
|
+
"Type" : "AWS::EC2::SecurityGroup",
|
254
|
+
"Properties" : {
|
255
|
+
"GroupDescription" : "Enable HTTP access via port 80 and SSH access",
|
256
|
+
"SecurityGroupIngress" : [
|
257
|
+
{"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"},
|
258
|
+
{"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}}
|
259
|
+
]
|
260
|
+
}
|
261
|
+
}
|
262
|
+
},
|
263
|
+
|
264
|
+
"Outputs" : {
|
265
|
+
"WebsiteURL" : {
|
266
|
+
"Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicDnsName" ]}]] },
|
267
|
+
"Description" : "Drupal Website"
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
data/spec/dslh_spec.rb
CHANGED
@@ -3,6 +3,10 @@ describe Dslh do
|
|
3
3
|
open(File.expand_path('../Drupal_Multi_AZ.template', __FILE__)) {|f| f.read }
|
4
4
|
end
|
5
5
|
|
6
|
+
let(:drupal_single_instance_template) do
|
7
|
+
open(File.expand_path('../Drupal_Single_Instance.template', __FILE__)) {|f| f.read }
|
8
|
+
end
|
9
|
+
|
6
10
|
it 'should be empty hash' do
|
7
11
|
h = Dslh.eval {}
|
8
12
|
expect(h).to eq({})
|
@@ -1092,13 +1096,13 @@ end
|
|
1092
1096
|
|
1093
1097
|
exclude_key = proc do |k|
|
1094
1098
|
k = k.to_s.gsub('::', '__')
|
1095
|
-
k !~ /\A[_a-z]\w+\Z/i and k !~ %r|
|
1099
|
+
k !~ /\A[_a-z]\w+\Z/i and k !~ %r|\A/\S*\Z|
|
1096
1100
|
end
|
1097
1101
|
|
1098
1102
|
key_conv = proc do |k|
|
1099
1103
|
k = k.to_s
|
1100
1104
|
|
1101
|
-
if k =~ %r|
|
1105
|
+
if k =~ %r|\A/\S*\Z|
|
1102
1106
|
proc do |v, nested|
|
1103
1107
|
if nested
|
1104
1108
|
"_path(#{k.inspect}) #{v}"
|
@@ -1685,6 +1689,369 @@ Outputs do
|
|
1685
1689
|
Description "Drupal Website"
|
1686
1690
|
end
|
1687
1691
|
end
|
1688
|
-
EOS
|
1692
|
+
EOS
|
1693
|
+
end
|
1694
|
+
|
1695
|
+
it 'should convert json to dsl with key_conf (use drupal_single_instance_template)' do
|
1696
|
+
template = JSON.parse(drupal_single_instance_template)
|
1697
|
+
|
1698
|
+
exclude_key = proc do |k|
|
1699
|
+
k = k.to_s.gsub('::', '__')
|
1700
|
+
k !~ /\A[_a-z]\w+\Z/i and k !~ %r|\A/\S*\Z|
|
1701
|
+
end
|
1702
|
+
|
1703
|
+
key_conv = proc do |k|
|
1704
|
+
k = k.to_s
|
1705
|
+
|
1706
|
+
if k =~ %r|\A/\S*\Z|
|
1707
|
+
proc do |v, nested|
|
1708
|
+
if nested
|
1709
|
+
"_path(#{k.inspect}) #{v}"
|
1710
|
+
else
|
1711
|
+
"_path #{k.inspect}, #{v}"
|
1712
|
+
end
|
1713
|
+
end
|
1714
|
+
else
|
1715
|
+
k.gsub('::', '__')
|
1716
|
+
end
|
1717
|
+
end
|
1718
|
+
|
1719
|
+
dsl = Dslh.deval(template, :key_conv => key_conv, :exclude_key => exclude_key)
|
1720
|
+
|
1721
|
+
expect(dsl).to eq(<<-'EOS')
|
1722
|
+
AWSTemplateFormatVersion "2010-09-09"
|
1723
|
+
Description "AWS CloudFormation Sample Template Drupal_Single_Instance. Drupal is an open source content management platform powering millions of websites and applications. This template installs a singe instance deployment with a local MySQL database for storage. It uses the AWS CloudFormation bootstrap scripts to install packages and files at instance launch time. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template."
|
1724
|
+
Parameters do
|
1725
|
+
KeyName do
|
1726
|
+
Description "Name of an existing EC2 KeyPair to enable SSH access to the instances"
|
1727
|
+
Type "String"
|
1728
|
+
MinLength "1"
|
1729
|
+
MaxLength "255"
|
1730
|
+
AllowedPattern "[\\x20-\\x7E]*"
|
1731
|
+
ConstraintDescription "can contain only ASCII characters."
|
1732
|
+
end
|
1733
|
+
InstanceType do
|
1734
|
+
Description "WebServer EC2 instance type"
|
1735
|
+
Type "String"
|
1736
|
+
Default "m1.small"
|
1737
|
+
AllowedValues "t1.micro", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.xlarge", "m3.2xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge", "cg1.4xlarge"
|
1738
|
+
ConstraintDescription "must be a valid EC2 instance type."
|
1739
|
+
end
|
1740
|
+
SiteName do
|
1741
|
+
Default "My Site"
|
1742
|
+
Description "The name of the Drupal Site"
|
1743
|
+
Type "String"
|
1744
|
+
end
|
1745
|
+
SiteEMail do
|
1746
|
+
Description "EMail for site adminitrator"
|
1747
|
+
Type "String"
|
1748
|
+
end
|
1749
|
+
SiteAdmin do
|
1750
|
+
Description "The Drupal site admin account username"
|
1751
|
+
Type "String"
|
1752
|
+
MinLength "1"
|
1753
|
+
MaxLength "16"
|
1754
|
+
AllowedPattern "[a-zA-Z][a-zA-Z0-9]*"
|
1755
|
+
ConstraintDescription "must begin with a letter and contain only alphanumeric characters."
|
1756
|
+
end
|
1757
|
+
SitePassword do
|
1758
|
+
NoEcho "true"
|
1759
|
+
Description "The Drupal site admin account password"
|
1760
|
+
Type "String"
|
1761
|
+
MinLength "1"
|
1762
|
+
MaxLength "41"
|
1763
|
+
AllowedPattern "[a-zA-Z0-9]*"
|
1764
|
+
ConstraintDescription "must contain only alphanumeric characters."
|
1765
|
+
end
|
1766
|
+
DBName do
|
1767
|
+
Default "drupaldb"
|
1768
|
+
Description "The Drupal database name"
|
1769
|
+
Type "String"
|
1770
|
+
MinLength "1"
|
1771
|
+
MaxLength "64"
|
1772
|
+
AllowedPattern "[a-zA-Z][a-zA-Z0-9]*"
|
1773
|
+
ConstraintDescription "must begin with a letter and contain only alphanumeric characters."
|
1774
|
+
end
|
1775
|
+
DBUsername do
|
1776
|
+
Default "admin"
|
1777
|
+
NoEcho "true"
|
1778
|
+
Description "The Drupal database admin account username"
|
1779
|
+
Type "String"
|
1780
|
+
MinLength "1"
|
1781
|
+
MaxLength "16"
|
1782
|
+
AllowedPattern "[a-zA-Z][a-zA-Z0-9]*"
|
1783
|
+
ConstraintDescription "must begin with a letter and contain only alphanumeric characters."
|
1784
|
+
end
|
1785
|
+
DBPassword do
|
1786
|
+
Default "admin"
|
1787
|
+
NoEcho "true"
|
1788
|
+
Description "The Drupal database admin account password"
|
1789
|
+
Type "String"
|
1790
|
+
MinLength "1"
|
1791
|
+
MaxLength "41"
|
1792
|
+
AllowedPattern "[a-zA-Z0-9]*"
|
1793
|
+
ConstraintDescription "must contain only alphanumeric characters."
|
1794
|
+
end
|
1795
|
+
DBRootPassword do
|
1796
|
+
NoEcho "true"
|
1797
|
+
Description "Root password for MySQL"
|
1798
|
+
Type "String"
|
1799
|
+
MinLength "1"
|
1800
|
+
MaxLength "41"
|
1801
|
+
AllowedPattern "[a-zA-Z0-9]*"
|
1802
|
+
ConstraintDescription "must contain only alphanumeric characters."
|
1803
|
+
end
|
1804
|
+
SSHLocation do
|
1805
|
+
Description "The IP address range that can be used to SSH to the EC2 instances"
|
1806
|
+
Type "String"
|
1807
|
+
MinLength "9"
|
1808
|
+
MaxLength "18"
|
1809
|
+
Default "0.0.0.0/0"
|
1810
|
+
AllowedPattern "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
|
1811
|
+
ConstraintDescription "must be a valid IP CIDR range of the form x.x.x.x/x."
|
1812
|
+
end
|
1813
|
+
end
|
1814
|
+
Mappings do
|
1815
|
+
AWSInstanceType2Arch(
|
1816
|
+
{"t1.micro"=>{"Arch"=>"64"},
|
1817
|
+
"m1.small"=>{"Arch"=>"64"},
|
1818
|
+
"m1.medium"=>{"Arch"=>"64"},
|
1819
|
+
"m1.large"=>{"Arch"=>"64"},
|
1820
|
+
"m1.xlarge"=>{"Arch"=>"64"},
|
1821
|
+
"m2.xlarge"=>{"Arch"=>"64"},
|
1822
|
+
"m2.2xlarge"=>{"Arch"=>"64"},
|
1823
|
+
"m2.4xlarge"=>{"Arch"=>"64"},
|
1824
|
+
"m3.xlarge"=>{"Arch"=>"64"},
|
1825
|
+
"m3.2xlarge"=>{"Arch"=>"64"},
|
1826
|
+
"c1.medium"=>{"Arch"=>"64"},
|
1827
|
+
"c1.xlarge"=>{"Arch"=>"64"},
|
1828
|
+
"cc1.4xlarge"=>{"Arch"=>"64HVM"},
|
1829
|
+
"cc2.8xlarge"=>{"Arch"=>"64HVM"},
|
1830
|
+
"cg1.4xlarge"=>{"Arch"=>"64HVM"}})
|
1831
|
+
AWSRegionArch2AMI(
|
1832
|
+
{"us-east-1"=>
|
1833
|
+
{"32"=>"ami-a0cd60c9", "64"=>"ami-aecd60c7", "64HVM"=>"ami-a8cd60c1"},
|
1834
|
+
"us-west-2"=>
|
1835
|
+
{"32"=>"ami-46da5576", "64"=>"ami-48da5578", "64HVM"=>"NOT_YET_SUPPORTED"},
|
1836
|
+
"us-west-1"=>
|
1837
|
+
{"32"=>"ami-7d4c6938", "64"=>"ami-734c6936", "64HVM"=>"NOT_YET_SUPPORTED"},
|
1838
|
+
"eu-west-1"=>
|
1839
|
+
{"32"=>"ami-61555115", "64"=>"ami-6d555119", "64HVM"=>"ami-67555113"},
|
1840
|
+
"ap-southeast-1"=>
|
1841
|
+
{"32"=>"ami-220b4a70", "64"=>"ami-3c0b4a6e", "64HVM"=>"NOT_YET_SUPPORTED"},
|
1842
|
+
"ap-southeast-2"=>
|
1843
|
+
{"32"=>"ami-b3990e89", "64"=>"ami-bd990e87", "64HVM"=>"NOT_YET_SUPPORTED"},
|
1844
|
+
"ap-northeast-1"=>
|
1845
|
+
{"32"=>"ami-2a19aa2b", "64"=>"ami-2819aa29", "64HVM"=>"NOT_YET_SUPPORTED"},
|
1846
|
+
"sa-east-1"=>
|
1847
|
+
{"32"=>"ami-f836e8e5", "64"=>"ami-fe36e8e3", "64HVM"=>"NOT_YET_SUPPORTED"}})
|
1848
|
+
end
|
1849
|
+
Resources do
|
1850
|
+
WebServer do
|
1851
|
+
Type "AWS::EC2::Instance"
|
1852
|
+
Metadata do
|
1853
|
+
AWS__CloudFormation__Init do
|
1854
|
+
config do
|
1855
|
+
packages do
|
1856
|
+
yum(
|
1857
|
+
{"httpd"=>[],
|
1858
|
+
"php"=>[],
|
1859
|
+
"php-mysql"=>[],
|
1860
|
+
"php-gd"=>[],
|
1861
|
+
"php-xml"=>[],
|
1862
|
+
"php-mbstring"=>[],
|
1863
|
+
"mysql"=>[],
|
1864
|
+
"mysql-server"=>[],
|
1865
|
+
"mysql-devel"=>[],
|
1866
|
+
"mysql-libs"=>[]})
|
1867
|
+
end
|
1868
|
+
sources do
|
1869
|
+
_path "/var/www/html", "http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz"
|
1870
|
+
_path "/home/ec2-user", "http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz"
|
1871
|
+
end
|
1872
|
+
files do
|
1873
|
+
_path("/tmp/setup.mysql") do
|
1874
|
+
content do
|
1875
|
+
Fn__Join [
|
1876
|
+
"",
|
1877
|
+
["CREATE DATABASE ",
|
1878
|
+
{"Ref"=>"DBName"},
|
1879
|
+
";\n",
|
1880
|
+
"CREATE USER '",
|
1881
|
+
{"Ref"=>"DBUsername"},
|
1882
|
+
"'@'localhost' IDENTIFIED BY '",
|
1883
|
+
{"Ref"=>"DBPassword"},
|
1884
|
+
"';\n",
|
1885
|
+
"GRANT ALL ON ",
|
1886
|
+
{"Ref"=>"DBName"},
|
1887
|
+
".* TO '",
|
1888
|
+
{"Ref"=>"DBUsername"},
|
1889
|
+
"'@'localhost';\n",
|
1890
|
+
"FLUSH PRIVILEGES;\n"]
|
1891
|
+
]
|
1892
|
+
end
|
1893
|
+
mode "000644"
|
1894
|
+
owner "root"
|
1895
|
+
group "root"
|
1896
|
+
end
|
1897
|
+
end
|
1898
|
+
services do
|
1899
|
+
sysvinit do
|
1900
|
+
httpd do
|
1901
|
+
enabled "true"
|
1902
|
+
ensureRunning "true"
|
1903
|
+
end
|
1904
|
+
mysqld do
|
1905
|
+
enabled "true"
|
1906
|
+
ensureRunning "true"
|
1907
|
+
end
|
1908
|
+
sendmail do
|
1909
|
+
enabled "false"
|
1910
|
+
ensureRunning "false"
|
1911
|
+
end
|
1912
|
+
end
|
1913
|
+
end
|
1914
|
+
end
|
1915
|
+
end
|
1916
|
+
end
|
1917
|
+
Properties do
|
1918
|
+
ImageId do
|
1919
|
+
Fn__FindInMap [
|
1920
|
+
"AWSRegionArch2AMI",
|
1921
|
+
_{
|
1922
|
+
Ref "AWS::Region"
|
1923
|
+
},
|
1924
|
+
_{
|
1925
|
+
Fn__FindInMap [
|
1926
|
+
"AWSInstanceType2Arch",
|
1927
|
+
_{
|
1928
|
+
Ref "InstanceType"
|
1929
|
+
},
|
1930
|
+
"Arch"
|
1931
|
+
]
|
1932
|
+
}
|
1933
|
+
]
|
1934
|
+
end
|
1935
|
+
InstanceType do
|
1936
|
+
Ref "InstanceType"
|
1937
|
+
end
|
1938
|
+
SecurityGroups [
|
1939
|
+
_{
|
1940
|
+
Ref "WebServerSecurityGroup"
|
1941
|
+
}
|
1942
|
+
]
|
1943
|
+
KeyName do
|
1944
|
+
Ref "KeyName"
|
1945
|
+
end
|
1946
|
+
UserData do
|
1947
|
+
Fn__Base64 do
|
1948
|
+
Fn__Join [
|
1949
|
+
"",
|
1950
|
+
["#!/bin/bash -v\n",
|
1951
|
+
"yum update -y aws-cfn-bootstrap\n",
|
1952
|
+
"# Helper function\n",
|
1953
|
+
"function error_exit\n",
|
1954
|
+
"{\n",
|
1955
|
+
" /opt/aws/bin/cfn-signal -e 0 -r \"$1\" '",
|
1956
|
+
{"Ref"=>"WaitHandle"},
|
1957
|
+
"'\n",
|
1958
|
+
" exit 1\n",
|
1959
|
+
"}\n",
|
1960
|
+
"# Install Apache Web Server, MySQL, PHP and Drupal\n",
|
1961
|
+
"/opt/aws/bin/cfn-init -s ",
|
1962
|
+
{"Ref"=>"AWS::StackId"},
|
1963
|
+
" -r WebServer ",
|
1964
|
+
" --region ",
|
1965
|
+
{"Ref"=>"AWS::Region"},
|
1966
|
+
" || error_exit 'Failed to run cfn-init'\n",
|
1967
|
+
"# Setup MySQL root password and create a user\n",
|
1968
|
+
"mysqladmin -u root password '",
|
1969
|
+
{"Ref"=>"DBRootPassword"},
|
1970
|
+
"' || error_exit 'Failed to initialize root password'\n",
|
1971
|
+
"mysql -u root --password='",
|
1972
|
+
{"Ref"=>"DBRootPassword"},
|
1973
|
+
"' < /tmp/setup.mysql || error_exit 'Failed to create database user'\n",
|
1974
|
+
"# Make changes to Apache Web Server configuration\n",
|
1975
|
+
"mv /var/www/html/drupal-7.8/* /var/www/html\n",
|
1976
|
+
"mv /var/www/html/drupal-7.8/.* /var/www/html\n",
|
1977
|
+
"rmdir /var/www/html/drupal-7.8\n",
|
1978
|
+
"sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf\n",
|
1979
|
+
"service httpd restart\n",
|
1980
|
+
"# Create the site in Drupal\n",
|
1981
|
+
"cd /var/www/html\n",
|
1982
|
+
"~ec2-user/drush/drush site-install standard --yes",
|
1983
|
+
" --site-name='",
|
1984
|
+
{"Ref"=>"SiteName"},
|
1985
|
+
"' --site-mail=",
|
1986
|
+
{"Ref"=>"SiteEMail"},
|
1987
|
+
" --account-name=",
|
1988
|
+
{"Ref"=>"SiteAdmin"},
|
1989
|
+
" --account-pass=",
|
1990
|
+
{"Ref"=>"SitePassword"},
|
1991
|
+
" --db-url=mysql://",
|
1992
|
+
{"Ref"=>"DBUsername"},
|
1993
|
+
":",
|
1994
|
+
{"Ref"=>"DBPassword"},
|
1995
|
+
"@localhost/",
|
1996
|
+
{"Ref"=>"DBName"},
|
1997
|
+
" --db-prefix=drupal_\n",
|
1998
|
+
"chown apache:apache sites/default/files\n",
|
1999
|
+
"# All is well so signal success\n",
|
2000
|
+
"/opt/aws/bin/cfn-signal -e 0 -r \"Drupal setup complete\" '",
|
2001
|
+
{"Ref"=>"WaitHandle"},
|
2002
|
+
"'\n"]
|
2003
|
+
]
|
2004
|
+
end
|
2005
|
+
end
|
2006
|
+
end
|
2007
|
+
end
|
2008
|
+
WaitHandle do
|
2009
|
+
Type "AWS::CloudFormation::WaitConditionHandle"
|
2010
|
+
end
|
2011
|
+
WaitCondition do
|
2012
|
+
Type "AWS::CloudFormation::WaitCondition"
|
2013
|
+
DependsOn "WebServer"
|
2014
|
+
Properties do
|
2015
|
+
Handle do
|
2016
|
+
Ref "WaitHandle"
|
2017
|
+
end
|
2018
|
+
Timeout "300"
|
2019
|
+
end
|
2020
|
+
end
|
2021
|
+
WebServerSecurityGroup do
|
2022
|
+
Type "AWS::EC2::SecurityGroup"
|
2023
|
+
Properties do
|
2024
|
+
GroupDescription "Enable HTTP access via port 80 and SSH access"
|
2025
|
+
SecurityGroupIngress [
|
2026
|
+
_{
|
2027
|
+
IpProtocol "tcp"
|
2028
|
+
FromPort "80"
|
2029
|
+
ToPort "80"
|
2030
|
+
CidrIp "0.0.0.0/0"
|
2031
|
+
},
|
2032
|
+
_{
|
2033
|
+
IpProtocol "tcp"
|
2034
|
+
FromPort "22"
|
2035
|
+
ToPort "22"
|
2036
|
+
CidrIp do
|
2037
|
+
Ref "SSHLocation"
|
2038
|
+
end
|
2039
|
+
}
|
2040
|
+
]
|
2041
|
+
end
|
2042
|
+
end
|
2043
|
+
end
|
2044
|
+
Outputs do
|
2045
|
+
WebsiteURL do
|
2046
|
+
Value do
|
2047
|
+
Fn__Join [
|
2048
|
+
"",
|
2049
|
+
["http://", {"Fn::GetAtt"=>["WebServer", "PublicDnsName"]}]
|
2050
|
+
]
|
2051
|
+
end
|
2052
|
+
Description "Drupal Website"
|
2053
|
+
end
|
2054
|
+
end
|
2055
|
+
EOS
|
1689
2056
|
end
|
1690
2057
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dslh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/dslh.rb
|
70
70
|
- lib/dslh/version.rb
|
71
71
|
- spec/Drupal_Multi_AZ.template
|
72
|
+
- spec/Drupal_Single_Instance.template
|
72
73
|
- spec/dslh_spec.rb
|
73
74
|
- spec/spec_helper.rb
|
74
75
|
homepage: https://github.com/winebarrel/dslh
|
@@ -97,6 +98,7 @@ specification_version: 4
|
|
97
98
|
summary: It define Hash as a DSL.
|
98
99
|
test_files:
|
99
100
|
- spec/Drupal_Multi_AZ.template
|
101
|
+
- spec/Drupal_Single_Instance.template
|
100
102
|
- spec/dslh_spec.rb
|
101
103
|
- spec/spec_helper.rb
|
102
104
|
has_rdoc:
|