sumomo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -2
- data/data/sumomo/custom_resource_utils.js +151 -0
- data/data/sumomo/custom_resources/AMILookup.js +106 -0
- data/data/sumomo/custom_resources/AvailabilityZones.js +89 -0
- data/data/sumomo/custom_resources/CloudflareCNAME.js +231 -0
- data/data/sumomo/custom_resources/DeployTime.js +15 -0
- data/data/sumomo/custom_resources/SelectSpot.js +294 -0
- data/data/sumomo/sources/spot-watcher-poller.sh +22 -0
- data/data/sumomo/sources/spot-watcher.sh +45 -0
- data/lib/sumomo.rb +193 -1
- data/lib/sumomo/ec2.rb +414 -0
- data/lib/sumomo/momo_extensions/resource.rb +10 -0
- data/lib/sumomo/momo_extensions/stack.rb +6 -0
- data/lib/sumomo/network.rb +70 -0
- data/lib/sumomo/stack.rb +152 -0
- data/lib/sumomo/version.rb +1 -1
- data/sumomo.gemspec +2 -0
- metadata +44 -3
data/lib/sumomo/stack.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
|
2
|
+
module Sumomo
|
3
|
+
module Stack
|
4
|
+
|
5
|
+
def hidden_value(value)
|
6
|
+
name = make_default_resource_name("HiddenValue")
|
7
|
+
if !@hidden_values
|
8
|
+
@hidden_values = []
|
9
|
+
end
|
10
|
+
|
11
|
+
@hidden_values << {
|
12
|
+
parameter_key: name,
|
13
|
+
parameter_value: value
|
14
|
+
}
|
15
|
+
|
16
|
+
param name, type: :string
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload_file(name,content)
|
20
|
+
@store.set_raw("uploads/#{name}", content)
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_lambda(name: nil, files:[{name:"index.js", code:""}],
|
24
|
+
description: "Lambda Function in #{@bucket_name}",
|
25
|
+
function_key: "cloudformation/lambda/function_#{name}",
|
26
|
+
handler: "index.handler",
|
27
|
+
runtime: "nodejs4.3",
|
28
|
+
memory_size: 128,
|
29
|
+
timeout: 30,
|
30
|
+
role: nil)
|
31
|
+
|
32
|
+
name ||= make_default_resource_name("Lambda")
|
33
|
+
|
34
|
+
stringio = Zip::OutputStream.write_buffer do |zio|
|
35
|
+
files.each do |file|
|
36
|
+
zio.put_next_entry(file[:name])
|
37
|
+
if file[:code]
|
38
|
+
zio.write file[:code]
|
39
|
+
elsif file[:path]
|
40
|
+
zio.write File.read(file[:path])
|
41
|
+
else
|
42
|
+
raise "Files needs to be an array of objects with :name and :code or :path members"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
@store.set_raw(function_key, stringio.string)
|
48
|
+
|
49
|
+
code_location = {"S3Bucket": @bucket_name, "S3Key": function_key}
|
50
|
+
fun = make "AWS::Lambda::Function", name: name do
|
51
|
+
Code code_location
|
52
|
+
Description description
|
53
|
+
MemorySize memory_size
|
54
|
+
Handler handler
|
55
|
+
Runtime runtime
|
56
|
+
Timeout timeout
|
57
|
+
Role role || exec_role.Arn
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_custom_resource(name: nil,code:)
|
62
|
+
|
63
|
+
name ||= make_default_resource_name("CustomResource")
|
64
|
+
|
65
|
+
func = make_lambda(
|
66
|
+
name: name,
|
67
|
+
files:[
|
68
|
+
{
|
69
|
+
name: "index.js",
|
70
|
+
code: File.read( File.join(Gem.datadir("sumomo"), "custom_resource_utils.js") ).sub("{{ CODE }}", code)
|
71
|
+
}
|
72
|
+
],
|
73
|
+
description: "CF Resource Custom::#{name}",
|
74
|
+
function_key: "cloudformation/custom_resources/function_#{name}")
|
75
|
+
|
76
|
+
@custom_resources["Custom::#{name}"] = func
|
77
|
+
end
|
78
|
+
|
79
|
+
def make_custom(custom_resource, options = {}, &block)
|
80
|
+
bucket_name = @bucket_name
|
81
|
+
stack_make "Custom::#{custom_resource.name}", options do
|
82
|
+
ServiceToken custom_resource.Arn
|
83
|
+
Region ref("AWS::Region")
|
84
|
+
Bucket bucket_name
|
85
|
+
instance_eval(&block) if block
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def make(type, options = {}, &block)
|
90
|
+
match = /^Custom\:\:(?<name>[a-z0-9]+)/i.match(type)
|
91
|
+
if match
|
92
|
+
if !@custom_resources[type]
|
93
|
+
|
94
|
+
resource_function_source = File.join(Gem.datadir("sumomo"), "custom_resources", "#{match[:name]}.js")
|
95
|
+
|
96
|
+
if File.exists? resource_function_source
|
97
|
+
define_custom_resource(name: match[:name], code: File.read(resource_function_source))
|
98
|
+
else
|
99
|
+
throw "#{resource_function_source} does not exist"
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
make_custom(@custom_resources[type], options, &block)
|
104
|
+
else
|
105
|
+
stack_make(type, options, &block)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def make_exec_role
|
110
|
+
if @exec_role == nil
|
111
|
+
role_policy_doc = {
|
112
|
+
"Version" => "2012-10-17",
|
113
|
+
"Statement" => [{
|
114
|
+
"Effect" => "Allow",
|
115
|
+
"Principal" => {"Service" => ["lambda.amazonaws.com"]},
|
116
|
+
"Action" => ["sts:AssumeRole"]
|
117
|
+
}]
|
118
|
+
}
|
119
|
+
bucket_name = @bucket_name
|
120
|
+
@exec_role = make "AWS::IAM::Role", name: "LambdaFunctionExecutionRole" do
|
121
|
+
AssumeRolePolicyDocument role_policy_doc
|
122
|
+
Path "/"
|
123
|
+
Policies [
|
124
|
+
{
|
125
|
+
"PolicyName" => "lambdapolicy",
|
126
|
+
"PolicyDocument" => {
|
127
|
+
"Version" => "2012-10-17",
|
128
|
+
"Statement" => [{
|
129
|
+
"Effect" => "Allow",
|
130
|
+
"Action" => ["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],
|
131
|
+
"Resource" => "arn:aws:logs:*:*:*"
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"Effect" => "Allow",
|
135
|
+
"Action" => ["cloudformation:DescribeStacks", "ec2:Describe*", ],
|
136
|
+
"Resource" => "*"
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"Effect" => "Allow",
|
140
|
+
"Action" => ["s3:DeleteObject", "s3:GetObject", "s3:PutObject"],
|
141
|
+
"Resource" => "arn:aws:s3:::#{bucket_name}/*"
|
142
|
+
}]
|
143
|
+
}
|
144
|
+
}
|
145
|
+
]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
@exec_role
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
data/lib/sumomo/version.rb
CHANGED
data/sumomo.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Siaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: hashie
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Sumomo
|
112
140
|
email:
|
113
141
|
- davidsiaw@gmail.com
|
@@ -123,7 +151,20 @@ files:
|
|
123
151
|
- Rakefile
|
124
152
|
- bin/console
|
125
153
|
- bin/setup
|
154
|
+
- data/sumomo/custom_resource_utils.js
|
155
|
+
- data/sumomo/custom_resources/AMILookup.js
|
156
|
+
- data/sumomo/custom_resources/AvailabilityZones.js
|
157
|
+
- data/sumomo/custom_resources/CloudflareCNAME.js
|
158
|
+
- data/sumomo/custom_resources/DeployTime.js
|
159
|
+
- data/sumomo/custom_resources/SelectSpot.js
|
160
|
+
- data/sumomo/sources/spot-watcher-poller.sh
|
161
|
+
- data/sumomo/sources/spot-watcher.sh
|
126
162
|
- lib/sumomo.rb
|
163
|
+
- lib/sumomo/ec2.rb
|
164
|
+
- lib/sumomo/momo_extensions/resource.rb
|
165
|
+
- lib/sumomo/momo_extensions/stack.rb
|
166
|
+
- lib/sumomo/network.rb
|
167
|
+
- lib/sumomo/stack.rb
|
127
168
|
- lib/sumomo/version.rb
|
128
169
|
- sumomo.gemspec
|
129
170
|
homepage: https://github.com/davidsiaw/sumomo
|
@@ -146,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
187
|
version: '0'
|
147
188
|
requirements: []
|
148
189
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.4.
|
190
|
+
rubygems_version: 2.4.8
|
150
191
|
signing_key:
|
151
192
|
specification_version: 4
|
152
193
|
summary: An advanced infrastructure description language for AWS
|