biosphere 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/bin/biosphere +5 -1
- data/lib/biosphere/deployment.rb +38 -1
- data/lib/biosphere/kube.rb +48 -52
- data/lib/biosphere/suite.rb +0 -1
- data/lib/biosphere/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc686dce74249976a49fd057c0afe79a7fe09912
|
4
|
+
data.tar.gz: aa2aa286f7d61f3c9f0c8693f5368597303c1b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97e05ad763e9c9869e73b234cd6542f7b0c4451c170f1381b8ae88ed6365763de5653847b97e7bb3a3689cbb36939e389d57ee18e0d84c75f4026c8140c8b67b
|
7
|
+
data.tar.gz: 95c255c267f676aba43ff08b63cc3045a3c9cf7bcde66e6c2bea9c2c0a9dd0b6e19b4c94c8cc34aa30beaa6809a3f9da5657b383fa237e57795676ad22118491
|
data/bin/biosphere
CHANGED
@@ -180,8 +180,12 @@ elsif ARGV[0] == "commit" && options.src
|
|
180
180
|
puts "\nOk, will not proceed with commit"
|
181
181
|
elsif answer == "y"
|
182
182
|
puts "\nApplying the changes (this may take several minutes)"
|
183
|
-
|
183
|
+
state_file = "#{options.build_dir}/#{deployment}.tfstate"
|
184
|
+
tf_apply = %x( terraform apply -state=#{state_file} #{options.build_dir})
|
184
185
|
puts "\n" + tf_apply
|
186
|
+
puts "Loading outputs from #{state_file}"
|
187
|
+
suite.deployments[deployment].load_outputs(state_file)
|
188
|
+
state.save()
|
185
189
|
s3.save("#{options.build_dir}/#{deployment}.tfstate")
|
186
190
|
s3.save("#{options.build_dir}/state.node")
|
187
191
|
end
|
data/lib/biosphere/deployment.rb
CHANGED
@@ -58,6 +58,7 @@ class Biosphere
|
|
58
58
|
@resources = []
|
59
59
|
@actions = {}
|
60
60
|
@deployments = []
|
61
|
+
@outputs = []
|
61
62
|
|
62
63
|
self.setup(settings)
|
63
64
|
|
@@ -124,10 +125,46 @@ class Biosphere
|
|
124
125
|
|
125
126
|
end
|
126
127
|
|
127
|
-
def output(name, value)
|
128
|
+
def output(name, value, &block)
|
128
129
|
@export["output"][name] = {
|
129
130
|
"value" => value
|
130
131
|
}
|
132
|
+
|
133
|
+
if block_given?
|
134
|
+
output = {
|
135
|
+
:name => name,
|
136
|
+
:block => block
|
137
|
+
}
|
138
|
+
|
139
|
+
@outputs << output
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def evaluate_outputs(outputs)
|
144
|
+
|
145
|
+
# Call first sub-deployments
|
146
|
+
@deployments.each do |deployment|
|
147
|
+
deployment.evaluate_outputs(outputs)
|
148
|
+
end
|
149
|
+
|
150
|
+
@outputs.each do |output|
|
151
|
+
value = outputs[output[:name]]
|
152
|
+
instance_exec(value["value"], value, &output[:block])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def load_outputs(tfstate_filename)
|
157
|
+
|
158
|
+
begin
|
159
|
+
tf_state = JSON.parse(File.read(tfstate_filename))
|
160
|
+
rescue SystemCallError
|
161
|
+
puts "Couldn't read Terraform statefile, can't continue"
|
162
|
+
exit
|
163
|
+
end
|
164
|
+
|
165
|
+
outputs = tf_state["modules"].first["outputs"]
|
166
|
+
|
167
|
+
evaluate_outputs(outputs)
|
131
168
|
end
|
132
169
|
|
133
170
|
def evaluate_resources()
|
data/lib/biosphere/kube.rb
CHANGED
@@ -2,6 +2,7 @@ require 'yaml'
|
|
2
2
|
require 'kubeclient'
|
3
3
|
require 'erb'
|
4
4
|
require 'hashdiff'
|
5
|
+
require 'ostruct'
|
5
6
|
|
6
7
|
class String
|
7
8
|
# Converts "CamelCase"" into "camel_case"
|
@@ -114,6 +115,46 @@ class Biosphere
|
|
114
115
|
|
115
116
|
end
|
116
117
|
|
118
|
+
def apply_resource(resource)
|
119
|
+
name = resource[:metadata][:name]
|
120
|
+
responses = []
|
121
|
+
not_found = false
|
122
|
+
begin
|
123
|
+
response = get(resource)
|
124
|
+
rescue RestClient::NotFound => e
|
125
|
+
not_found = true
|
126
|
+
end
|
127
|
+
|
128
|
+
if not_found
|
129
|
+
begin
|
130
|
+
response = post(resource)
|
131
|
+
puts "Created resource #{response[:resource]}"
|
132
|
+
responses << response
|
133
|
+
rescue RestClient::UnprocessableEntity => e
|
134
|
+
pp e
|
135
|
+
pp JSON.parse(e.response.body)
|
136
|
+
end
|
137
|
+
else
|
138
|
+
puts "Updating resource #{response[:resource]}"
|
139
|
+
|
140
|
+
# Get the current full resource from apiserver
|
141
|
+
current_resource = response[:body]
|
142
|
+
|
143
|
+
update_resource = Kube.kube_merge_resource_for_put!(current_resource, resource)
|
144
|
+
|
145
|
+
begin
|
146
|
+
responses << put(update_resource)
|
147
|
+
rescue RestClient::Exception => e
|
148
|
+
puts "Error updating resource: #{e} #{e.class}"
|
149
|
+
pp JSON.parse(e.response)
|
150
|
+
rescue RestClient::Exception => e
|
151
|
+
puts "Misc exception: #{e}, #{e.class}, #{e.response}"
|
152
|
+
end
|
153
|
+
|
154
|
+
return responses
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
117
158
|
end # end of class Client
|
118
159
|
|
119
160
|
def kube_test(str)
|
@@ -124,25 +165,18 @@ class Biosphere
|
|
124
165
|
return Client.new(hostname, ssl_options)
|
125
166
|
end
|
126
167
|
|
127
|
-
def
|
128
|
-
files =
|
129
|
-
|
130
|
-
files.each do |file|
|
131
|
-
resources += kube_load_manifest_file(file)
|
132
|
-
end
|
133
|
-
|
134
|
-
files = Dir[dir + "/**/*.yaml"]
|
135
|
-
files.each do |file|
|
136
|
-
resources += kube_load_manifest_file(file)
|
137
|
-
end
|
168
|
+
def self.find_manifest_files(dir)
|
169
|
+
files = []
|
170
|
+
files += Dir[dir + "/**/*.erb"]
|
138
171
|
|
139
|
-
|
172
|
+
files += Dir[dir + "/**/*.yaml"]
|
173
|
+
files
|
140
174
|
end
|
141
175
|
|
142
|
-
def
|
176
|
+
def self.load_resources(file, context={})
|
143
177
|
resources = []
|
144
178
|
puts "Loading file #{file}"
|
145
|
-
str = ERB.new(IO.read(file)).result(binding)
|
179
|
+
str = ERB.new(IO.read(file)).result(OpenStruct.new(context).instance_eval { binding })
|
146
180
|
begin
|
147
181
|
Psych.load_stream(str) do |document|
|
148
182
|
kind = document["kind"]
|
@@ -206,44 +240,6 @@ class Biosphere
|
|
206
240
|
return new_version
|
207
241
|
end
|
208
242
|
|
209
|
-
def kube_apply_resource(client, resource)
|
210
|
-
name = resource[:metadata][:name]
|
211
|
-
responses = []
|
212
|
-
not_found = false
|
213
|
-
begin
|
214
|
-
response = client.get(resource)
|
215
|
-
rescue RestClient::NotFound => e
|
216
|
-
not_found = true
|
217
|
-
end
|
218
|
-
|
219
|
-
if not_found
|
220
|
-
begin
|
221
|
-
response = client.post(resource)
|
222
|
-
puts "Created resource #{response[:resource]}"
|
223
|
-
responses << response
|
224
|
-
rescue RestClient::UnprocessableEntity => e
|
225
|
-
pp e
|
226
|
-
pp JSON.parse(e.response.body)
|
227
|
-
end
|
228
|
-
else
|
229
|
-
puts "Updating resource #{response[:resource]}"
|
230
|
-
|
231
|
-
# Get the current full resource from apiserver
|
232
|
-
current_resource = response[:body]
|
233
|
-
|
234
|
-
update_resource = Kube.kube_merge_resource_for_put!(current_resource, resource)
|
235
243
|
|
236
|
-
begin
|
237
|
-
responses << client.put(update_resource)
|
238
|
-
rescue RestClient::Exception => e
|
239
|
-
puts "Error updating resource: #{e} #{e.class}"
|
240
|
-
pp JSON.parse(e.response)
|
241
|
-
rescue RestClient::Exception => e
|
242
|
-
puts "Misc exception: #{e}, #{e.class}, #{e.response}"
|
243
|
-
end
|
244
|
-
|
245
|
-
return responses
|
246
|
-
end
|
247
|
-
end
|
248
244
|
end
|
249
245
|
end
|
data/lib/biosphere/suite.rb
CHANGED
data/lib/biosphere/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biosphere
|
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
|
- Juho Mäkinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|