linecook-gem 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/linecook/builder/build.rb +4 -2
- data/lib/linecook/cli.rb +15 -3
- data/lib/linecook/image/crypt.rb +11 -2
- data/lib/linecook/image/manager.rb +14 -4
- data/lib/linecook/image/s3.rb +19 -4
- data/lib/linecook/packager/ebs.rb +3 -2
- data/lib/linecook/packager/manager.rb +2 -2
- data/lib/linecook/provisioner/manager.rb +4 -4
- data/lib/linecook/version.rb +1 -1
- 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: 3c2ebac88ea5856749e3c19115a06aee40f9c258
|
4
|
+
data.tar.gz: 21c9e7a2166694a3793813c82d0131963e3f7b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73f4b086e94dcea9fe1bb9106becf8dcb6bee7293c16b07ed467301335dd3409996808e86fe2bd8abf0cbadfc0e0aa9330bd24e1abba274ea0e4da00c3429631
|
7
|
+
data.tar.gz: 88b2c87c88f17445e74da4ad4c57ea6bd92b2ae3f41cd2e9989ffacebaee9f45172fa121f43ca72ca98d87ba49fc987139068675cb5784f176a984070658a621
|
@@ -6,10 +6,12 @@ module Linecook
|
|
6
6
|
extend Forwardable
|
7
7
|
|
8
8
|
def_instance_delegators :@container, :stop, :start, :ip, :info
|
9
|
+
attr_reader :type
|
9
10
|
|
10
|
-
def initialize(name, tag: nil, image: nil)
|
11
|
+
def initialize(name, tag: nil, image: nil, id: nil)
|
11
12
|
Linecook::Builder.start
|
12
|
-
@
|
13
|
+
@type = tag ? "#{name}-#{tag}" : name
|
14
|
+
@id = id ? "#{@type}-#{id}" : @type
|
13
15
|
@image = image || Linecook.config[:provisioner][:default_image]
|
14
16
|
@container = Linecook::Lxc::Container.new(name: @id, image: @image, remote: Linecook::Builder.ssh)
|
15
17
|
end
|
data/lib/linecook/cli.rb
CHANGED
@@ -23,7 +23,18 @@ class Image < Thor
|
|
23
23
|
subcommand 'crypto', Crypto
|
24
24
|
|
25
25
|
desc 'list', 'List images' # add remote flag
|
26
|
+
method_option :type, type: :string, required: false, banner: 'ID', desc: 'Type of image to list', aliases: '-t'
|
27
|
+
method_option :profile, type: :string, default: 'private', banner: 'PROFILE', desc: 'Profile (public/private) of image to list', enum: %w(public private), aliases: '-p'
|
26
28
|
def list
|
29
|
+
opts = options.symbolize_keys
|
30
|
+
puts Linecook::ImageManager.list(**opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'latest ID', 'Get the latest image by id' # add remote flag
|
34
|
+
method_option :profile, type: :string, default: 'private', banner: 'PROFILE', desc: 'Profile (public/private) of image to list', enum: %w(public private), aliases: '-p'
|
35
|
+
def latest(id)
|
36
|
+
opts = options.symbolize_keys
|
37
|
+
puts Linecook::ImageManager.latest(id, **opts)
|
27
38
|
end
|
28
39
|
|
29
40
|
desc 'fetch IMAGE_NAME', 'Fetch an image by name'
|
@@ -39,9 +50,10 @@ class Image < Thor
|
|
39
50
|
end
|
40
51
|
|
41
52
|
desc 'url IMAGE', 'Get URL for image'
|
42
|
-
|
53
|
+
method_option :type, type: :string, required: false, banner: 'ID', desc: 'Type of image to list', aliases: '-t'
|
43
54
|
def url(image)
|
44
|
-
|
55
|
+
opts = options.symbolize_keys
|
56
|
+
puts Linecook::ImageManager.url(image, **opts)
|
45
57
|
end
|
46
58
|
|
47
59
|
desc 'package IMAGE', 'Package image'
|
@@ -109,7 +121,7 @@ class Linecook::CLI < Thor
|
|
109
121
|
desc 'bake', 'Bake a new image.'
|
110
122
|
method_option :name, type: :string, required: true, banner: 'ROLE_NAME', desc: 'Name of the role to build', aliases: '-n'
|
111
123
|
method_option :tag, type: :string, required: false, banner: 'TAG', desc: 'Optional tag for a build', aliases: '-t'
|
112
|
-
method_option :
|
124
|
+
method_option :id, type: :string, required: false, banner: 'ID', desc: 'Optional id for a build', aliases: '-i'
|
113
125
|
method_option :keep, type: :boolean, default: true, desc: 'Keep the build running when done', aliases: '-k'
|
114
126
|
method_option :clean, type: :boolean, default: false, desc: 'Clean up all build artifacts', aliases: '-c'
|
115
127
|
method_option :build, type: :boolean, default: true, desc: 'Build the image', aliases: '-b'
|
data/lib/linecook/image/crypt.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'encryptor'
|
3
|
+
require 'tempfile'
|
3
4
|
|
4
5
|
require 'linecook/image/manager'
|
5
6
|
require 'linecook/util/executor'
|
@@ -24,13 +25,21 @@ module Linecook
|
|
24
25
|
|
25
26
|
def encrypt_file(source, dest: nil, keypath: nil)
|
26
27
|
dest ||= "/tmp/#{File.basename(source)}"
|
27
|
-
|
28
|
+
Tempfile.open('key') do |key|
|
29
|
+
key.write(@secret_key)
|
30
|
+
key.flush
|
31
|
+
capture("openssl enc -#{CIPHER} -out #{dest} -in #{source} -kfile #{key.path}", sudo: false)
|
32
|
+
end
|
28
33
|
dest
|
29
34
|
end
|
30
35
|
|
31
36
|
def decrypt_file(source, dest: nil, keypath: nil)
|
32
37
|
dest ||= "/tmp/#{File.basename(source)}-decrypted"
|
33
|
-
|
38
|
+
Tempfile.open('key') do |key|
|
39
|
+
@remote.upload(@secret_key, key.path) if @remote
|
40
|
+
capture("openssl enc -#{CIPHER} -out #{dest} -in #{source} -kfile #{key.path} -d", sudo: false)
|
41
|
+
@remote.run("rm #{key.path}") if @remote
|
42
|
+
end
|
34
43
|
dest
|
35
44
|
end
|
36
45
|
|
@@ -18,16 +18,26 @@ module Linecook
|
|
18
18
|
path
|
19
19
|
end
|
20
20
|
|
21
|
-
def upload(image, profile: :private)
|
21
|
+
def upload(image, profile: :private, type: nil)
|
22
22
|
path = File.join(IMAGE_PATH, File.basename(image))
|
23
23
|
puts "Encrypting and uploading image #{path}"
|
24
24
|
encrypted = Linecook::Crypto.new.encrypt_file(path)
|
25
|
-
provider(profile).upload(encrypted)
|
25
|
+
provider(profile).upload(encrypted, type: type)
|
26
26
|
FileUtils.rm_f(encrypted)
|
27
27
|
end
|
28
28
|
|
29
|
-
def url(image, profile: :private)
|
30
|
-
provider(profile).url(
|
29
|
+
def url(image, profile: :private, type: nil)
|
30
|
+
provider(profile).url(image, type: type)
|
31
|
+
end
|
32
|
+
|
33
|
+
def list(type: nil, profile: :private)
|
34
|
+
profile = profile.to_sym
|
35
|
+
provider(profile).list(type: type)
|
36
|
+
end
|
37
|
+
|
38
|
+
def latest(type, profile: :private)
|
39
|
+
profile = profile.to_sym
|
40
|
+
provider(profile).latest(type)
|
31
41
|
end
|
32
42
|
|
33
43
|
private
|
data/lib/linecook/image/s3.rb
CHANGED
@@ -5,19 +5,29 @@ module Linecook
|
|
5
5
|
module S3Manager
|
6
6
|
extend self
|
7
7
|
EXPIRY = 20
|
8
|
+
PREFIX = 'builds'
|
8
9
|
|
9
|
-
def url(name)
|
10
|
+
def url(name, type: nil)
|
10
11
|
client
|
11
12
|
s3 = Aws::S3::Resource.new
|
12
|
-
obj = s3.bucket(Linecook.config[:aws][:s3][:bucket]).object(name)
|
13
|
+
obj = s3.bucket(Linecook.config[:aws][:s3][:bucket]).object(File.join([PREFIX, type, name].compact))
|
13
14
|
obj.presigned_url(:get, expires_in: EXPIRY * 60)
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def list(type: nil)
|
18
|
+
list_objects(type: type).map{ |x| x.key if x.key =~ /squashfs$/ }.compact
|
19
|
+
end
|
20
|
+
|
21
|
+
def latest(type)
|
22
|
+
objects = list_objects(type: type).sort! { |a,b| a.last_modified <=> b.last_modified }
|
23
|
+
key = objects.last ? objects.last.key : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def upload(path, type: nil)
|
17
27
|
File.open(path, 'rb') do |file|
|
18
28
|
fname = File.basename(path)
|
19
29
|
pbar = ProgressBar.create(title: fname, total: file.size)
|
20
|
-
common_opts = { bucket: Linecook.config[:aws][:s3][:bucket], key: File.join(
|
30
|
+
common_opts = { bucket: Linecook.config[:aws][:s3][:bucket], key: File.join([PREFIX, type, fname].compact) }
|
21
31
|
resp = client.create_multipart_upload(storage_class: 'REDUCED_REDUNDANCY', server_side_encryption: 'AES256', **common_opts)
|
22
32
|
id = resp.upload_id
|
23
33
|
part = 0
|
@@ -36,6 +46,11 @@ module Linecook
|
|
36
46
|
end
|
37
47
|
|
38
48
|
private
|
49
|
+
|
50
|
+
def list_objects(type: nil)
|
51
|
+
client.list_objects(bucket: Linecook.config[:aws][:s3][:bucket], prefix: File.join([PREFIX, type].compact)).contents
|
52
|
+
end
|
53
|
+
|
39
54
|
def client
|
40
55
|
@client ||= begin
|
41
56
|
Aws.config[:credentials] = Aws::Credentials.new(Linecook.config[:aws][:access_key], Linecook.config[:aws][:secret_key])
|
@@ -20,8 +20,9 @@ module Linecook
|
|
20
20
|
@region = region
|
21
21
|
end
|
22
22
|
|
23
|
-
def package(image)
|
23
|
+
def package(image, type: nil)
|
24
24
|
@image = image
|
25
|
+
@type = type
|
25
26
|
setup_remote unless instance_id
|
26
27
|
prepare
|
27
28
|
execute("tar -C #{@mountpoint} -cpf - . | sudo tar -C #{@root} -xpf -")
|
@@ -166,7 +167,7 @@ module Linecook
|
|
166
167
|
def setup_remote
|
167
168
|
start_node
|
168
169
|
path = "/tmp/#{File.basename(@image)}"
|
169
|
-
@remote.run("wget '#{Linecook::ImageManager.url(File.basename(@image))}' -nv -O #{path}")
|
170
|
+
@remote.run("wget '#{Linecook::ImageManager.url(File.basename(@image), type: @type)}' -nv -O #{path}")
|
170
171
|
@image = Linecook::Crypto.new(remote: @remote).decrypt_file(path)
|
171
172
|
end
|
172
173
|
|
@@ -9,12 +9,12 @@ module Linecook
|
|
9
9
|
module Baker
|
10
10
|
extend self
|
11
11
|
|
12
|
-
def bake(name: nil, tag: nil,
|
13
|
-
build_agent = Linecook::Build.new(name, tag: tag,
|
12
|
+
def bake(name: nil, tag: nil, id: nil, snapshot: nil, upload: nil, package: nil, build: nil, keep: nil, clean: nil)
|
13
|
+
build_agent = Linecook::Build.new(name, tag: tag, id: id)
|
14
14
|
provider(name).provision(build_agent, name) if build
|
15
15
|
snapshot = build_agent.snapshot(save: true) if snapshot || upload || package
|
16
|
-
Linecook::ImageManager.upload(snapshot) if upload || package
|
17
|
-
Linecook::Packager.package(snapshot) if package
|
16
|
+
Linecook::ImageManager.upload(snapshot, type: build_agent.type) if upload || package
|
17
|
+
Linecook::Packager.package(snapshot, type: build_agent.type) if package
|
18
18
|
ensure
|
19
19
|
build_agent.stop unless keep
|
20
20
|
FileUtils.rm_f(snapshot) if clean
|
data/lib/linecook/version.rb
CHANGED