linecook-gem 0.3.1 → 0.3.2
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/linecook/image/manager.rb +2 -3
- data/lib/linecook/packager/ebs.rb +31 -8
- data/lib/linecook/provisioner/chef-zero.rb +9 -2
- data/lib/linecook/util/config.rb +5 -5
- data/lib/linecook/version.rb +1 -1
- data/lib/linecook.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c4d3f814360279e6d37e60a436f6597ff6ac4b1
|
4
|
+
data.tar.gz: fefeaef64eff88fcb7c6610dcd26871aa322f5b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5705ef81dd3175c91ae2706974568ef0a3b771a175359aa35f7b35e103b6d15d0b5a8f2f4c65491b249bd4b46e01adbbf5989bb3cd365ee80502b695e43cf0a
|
7
|
+
data.tar.gz: 70214b40fd54f10a9046949a83f2726b9abf93c1462d70f77e2b962bababc56040ac62dcc7e0bd3a094ca6823e65cfae18f0b21a59a2859502088072d1c84a33
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
|
-
require 'linecook/image/crypt'
|
4
|
-
require 'linecook/image/github'
|
5
3
|
require 'linecook/image/s3'
|
6
|
-
require 'linecook/
|
4
|
+
require 'linecook/image/github'
|
5
|
+
require 'linecook/image/crypt'
|
7
6
|
|
8
7
|
module Linecook
|
9
8
|
module ImageManager
|
@@ -25,13 +25,15 @@ module Linecook
|
|
25
25
|
|
26
26
|
def package(image, type: nil, ami: nil)
|
27
27
|
@image = image
|
28
|
-
@
|
28
|
+
@source = File.basename(@image)
|
29
|
+
@name = "#{@source}-#{SecureRandom.hex(4)}"
|
29
30
|
@type = type
|
30
|
-
|
31
|
+
setup_image
|
31
32
|
prepare
|
32
33
|
execute("tar -C #{@mountpoint} -cpf - . | sudo tar -C #{@root} -xpf -")
|
33
34
|
finalize
|
34
35
|
snapshot
|
36
|
+
cleanup
|
35
37
|
create_ami if ami
|
36
38
|
end
|
37
39
|
|
@@ -54,6 +56,11 @@ module Linecook
|
|
54
56
|
execute("grub-install --root-directory=#{@root} $(echo #{@rootdev} | sed \"s/[0-9]*//g\")") if @hvm
|
55
57
|
end
|
56
58
|
|
59
|
+
def cleanup
|
60
|
+
execute("umount #{@image}")
|
61
|
+
execute("rm -f #{@image}")
|
62
|
+
execute("rmdir #{@mountpoint}")
|
63
|
+
end
|
57
64
|
|
58
65
|
def chroot_exec(command)
|
59
66
|
execute("mount -o bind /dev #{@root}/dev")
|
@@ -135,7 +142,7 @@ module Linecook
|
|
135
142
|
end
|
136
143
|
resp = client.create_snapshot(volume_id: @volume_id, description: "Snapshot of #{@name}")
|
137
144
|
@snapshot_id = resp.snapshot_id
|
138
|
-
tag(@snapshot_id, Name:
|
145
|
+
tag(@snapshot_id, Name: "Linecook snapshot for #{@source}", type: @type, image: @name, hvm: @hvm.to_s)
|
139
146
|
client.delete_volume(volume_id: @volume_id)
|
140
147
|
end
|
141
148
|
|
@@ -202,6 +209,11 @@ module Linecook
|
|
202
209
|
})
|
203
210
|
end
|
204
211
|
end
|
212
|
+
|
213
|
+
amis.each do |region, ami|
|
214
|
+
tag(ami, region: region, source: @source, name: @name, type: @type, hvm: @hvm.to_s)
|
215
|
+
end
|
216
|
+
amis
|
205
217
|
end
|
206
218
|
|
207
219
|
def free_device
|
@@ -238,11 +250,21 @@ module Linecook
|
|
238
250
|
return nil
|
239
251
|
end
|
240
252
|
|
241
|
-
def
|
242
|
-
start_node
|
253
|
+
def setup_image
|
243
254
|
path = "/tmp/#{File.basename(@image)}"
|
244
|
-
|
245
|
-
|
255
|
+
if instance_id
|
256
|
+
return if File.exists?(@image)
|
257
|
+
Linecook::Downloader.download(image_url, path)
|
258
|
+
@image = path
|
259
|
+
else
|
260
|
+
start_node
|
261
|
+
@remote.run("wget '#{image_url}' -nv -O #{path}")
|
262
|
+
@image = Linecook::Crypto.new(remote: @remote).decrypt_file(path)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def image_url
|
267
|
+
@url ||= Linecook::ImageManager.url(File.basename(@image), type: @type)
|
246
268
|
end
|
247
269
|
|
248
270
|
def start_node
|
@@ -306,7 +328,8 @@ module Linecook
|
|
306
328
|
end
|
307
329
|
|
308
330
|
def tag(id, **kwargs)
|
309
|
-
|
331
|
+
puts "Will tag #{id} with #{kwargs}"
|
332
|
+
resp = client(region: kwargs[:region]).create_tags(resources: [id], tags: kwargs.map{ |k,v| {key: k.to_s, value: v.to_s } })
|
310
333
|
end
|
311
334
|
|
312
335
|
def key_pair
|
@@ -79,8 +79,15 @@ module Linecook
|
|
79
79
|
def build
|
80
80
|
if stale
|
81
81
|
puts 'Regenerating cookbook cache'
|
82
|
-
|
83
|
-
|
82
|
+
begin
|
83
|
+
Chefdepartie.run(background: true, config: Linecook.config[:chef], cache: CACHE_PATH)
|
84
|
+
rescue
|
85
|
+
puts 'Cache tainted, rebuilding completely'
|
86
|
+
FileUtils.rm_rf(CACHE_PATH)
|
87
|
+
Chefdepartie.run(background: true, config: Linecook.config[:chef], cache: CACHE_PATH)
|
88
|
+
ensure
|
89
|
+
Chefdepartie.stop
|
90
|
+
end
|
84
91
|
write_stamp
|
85
92
|
unlock
|
86
93
|
end
|
data/lib/linecook/util/config.rb
CHANGED
@@ -69,9 +69,10 @@ module Linecook
|
|
69
69
|
|
70
70
|
def secrets
|
71
71
|
@secrets ||= begin
|
72
|
-
|
72
|
+
secrets_path = ENV['LINECOOK_SECRETS_PATH'] || SECRETS_PATH
|
73
|
+
if File.exists?(secrets_path)
|
73
74
|
ejson_path = File.join(Gem::Specification.find_by_name('ejson').gem_dir, 'build', "#{Linecook::Config.platform}-amd64", 'ejson' )
|
74
|
-
command = "#{ejson_path} decrypt #{
|
75
|
+
command = "#{ejson_path} decrypt #{secrets_path}"
|
75
76
|
secrets = JSON.load(`sudo #{command}`)
|
76
77
|
secrets.deep_symbolize_keys
|
77
78
|
else
|
@@ -100,10 +101,9 @@ module Linecook
|
|
100
101
|
|
101
102
|
def load_config
|
102
103
|
@config ||= begin
|
104
|
+
config_path = ENV['LINECOOK_CONFIG_PATH'] || CONFIG_PATH
|
103
105
|
config = YAML.load(File.read(DEFAULT_CONFIG_PATH)) if File.exist?(DEFAULT_CONFIG_PATH)
|
104
|
-
config.deep_merge!(YAML.load(File.read(
|
105
|
-
# fail "Cookbook path not provided or doesn't exist" unless (config[:chef][:cookbook_path] && Dir.exists?(config[:chef][:cookbook_path]))
|
106
|
-
# fail "Databag secret not provided or doesn't exist" unless (config[:chef][:encrypted_data_bag_secret] && File.exists?(config[:chef][:encrypted_data_bag_secret]))
|
106
|
+
config.deep_merge!(YAML.load(File.read(config_path))) if File.exist?(config_path)
|
107
107
|
(config || {}).deep_symbolize_keys!
|
108
108
|
config.deep_merge!(secrets)
|
109
109
|
end
|
data/lib/linecook/version.rb
CHANGED
data/lib/linecook.rb
CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
|
3
3
|
require 'active_support/all'
|
4
4
|
require 'linecook/version'
|
5
5
|
require 'linecook/util/config'
|
6
|
+
require 'linecook/util/downloader'
|
6
7
|
require 'linecook/image/manager'
|
7
8
|
require 'linecook/builder/manager'
|
8
9
|
require 'linecook/provisioner/manager'
|