linecook-gem 0.3.0 → 0.3.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/linecook/cli.rb +10 -4
- data/lib/linecook/packager/ebs.rb +81 -7
- data/lib/linecook/packager/manager.rb +2 -2
- data/lib/linecook/util/config.rb +3 -1
- data/lib/linecook/version.rb +1 -1
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1abf2321c6f050ebebaff2cd97736d181c3438d3
|
4
|
+
data.tar.gz: e8482496017204409f513273352ac69b50d41295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310b56ecc9861ab86f2ed209fe8d77b64571e3b9d664747f2f785754388595be636ca1d3fcabaaf620b5c62fc2bdd3c877e11a40dee8d4ea09af4d7fe03d47f0
|
7
|
+
data.tar.gz: b8a143904d6c6924cff355ebac678bae6abca2e0cac2de2ffd32698bfc58243c63b2fc73161b20d6601117ddfe977d9fd154cbb5ca5f9dc2ff2a8ff89f0e59aa
|
data/lib/linecook/cli.rb
CHANGED
@@ -63,10 +63,16 @@ class Image < Thor
|
|
63
63
|
puts Linecook::ImageManager.url(image, **opts)
|
64
64
|
end
|
65
65
|
|
66
|
-
desc 'package
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
desc 'package', 'Package image'
|
67
|
+
method_option :name, type: :string, required: false, banner: 'NAME', desc: 'Name of the image to snapshot. Specify this, or --latest with a type', aliases: '-n'
|
68
|
+
method_option :latest, type: :boolean, default: false, desc: 'Use the latest build for type', aliases: '-l'
|
69
|
+
method_option :ami, type: :boolean, default: true, desc: 'Create an ami', aliases: '-a'
|
70
|
+
method_option :type, type: :string, required: false, banner: 'ID', desc: 'Type of image to snapshot', aliases: '-t'
|
71
|
+
def package
|
72
|
+
fail 'Must specify image name or use latest' unless options[:name] || options[:latest]
|
73
|
+
fail 'Must specify type if specifying latest' if options[:latest] && !options[:type]
|
74
|
+
name = options[:latest] ? Linecook::ImageManager.latest(options[:type]) : options[:name]
|
75
|
+
Linecook::Packager.package(name, type: options[:type], ami: options[:ami])
|
70
76
|
end
|
71
77
|
end
|
72
78
|
|
@@ -2,6 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'open-uri'
|
3
3
|
require 'timeout'
|
4
4
|
require 'tmpdir'
|
5
|
+
require 'securerandom'
|
5
6
|
|
6
7
|
require 'linecook/util/ssh'
|
7
8
|
require 'linecook/util/executor'
|
@@ -14,20 +15,24 @@ module Linecook
|
|
14
15
|
class EBS
|
15
16
|
include Executor
|
16
17
|
|
17
|
-
def initialize(hvm: true, size: 10, region:
|
18
|
+
def initialize(hvm: true, size: 10, region: nil, copy_regions: [], account_ids: [])
|
18
19
|
@hvm = hvm
|
19
20
|
@size = size
|
20
21
|
@region = region
|
22
|
+
@copy_regions = copy_regions
|
23
|
+
@account_ids = account_ids
|
21
24
|
end
|
22
25
|
|
23
|
-
def package(image, type: nil)
|
26
|
+
def package(image, type: nil, ami: nil)
|
24
27
|
@image = image
|
28
|
+
@name = "#{File.basename(image).gsub('.squashfs', '').gsub('-decrypted', '')}-#{SecureRandom.hex(4)}"
|
25
29
|
@type = type
|
26
30
|
setup_remote unless instance_id
|
27
31
|
prepare
|
28
32
|
execute("tar -C #{@mountpoint} -cpf - . | sudo tar -C #{@root} -xpf -")
|
29
33
|
finalize
|
30
34
|
snapshot
|
35
|
+
create_ami if ami
|
31
36
|
end
|
32
37
|
|
33
38
|
private
|
@@ -44,7 +49,7 @@ module Linecook
|
|
44
49
|
execute("echo \"UUID=\\\"$(blkid -o value -s UUID #{@rootdev})\\\" / ext4 defaults 1 2\" > /tmp/fstab")
|
45
50
|
execute("mv /tmp/fstab #{@root}/etc/fstab")
|
46
51
|
chroot_exec('apt-get update')
|
47
|
-
chroot_exec('apt-get
|
52
|
+
chroot_exec('apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y --force-yes --no-upgrade install grub-pc grub-legacy-ec2')
|
48
53
|
chroot_exec('update-grub')
|
49
54
|
execute("grub-install --root-directory=#{@root} $(echo #{@rootdev} | sed \"s/[0-9]*//g\")") if @hvm
|
50
55
|
end
|
@@ -83,10 +88,13 @@ module Linecook
|
|
83
88
|
@availability_zone ||= metadata('placement/availability-zone')
|
84
89
|
end
|
85
90
|
|
86
|
-
def client
|
91
|
+
def client(region: nil)
|
92
|
+
@client = nil if region
|
87
93
|
@client ||= begin
|
94
|
+
region ||= @region
|
95
|
+
puts "Using AWS region #{region} for following request"
|
88
96
|
credentials = Aws::Credentials.new(Linecook.config[:aws][:access_key], Linecook.config[:aws][:secret_key])
|
89
|
-
Aws::EC2::Client.new(region:
|
97
|
+
Aws::EC2::Client.new(region: region, credentials: credentials)
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
@@ -125,11 +133,77 @@ module Linecook
|
|
125
133
|
wait_for_state('available', 120) do
|
126
134
|
client.describe_volumes(volume_ids: [@volume_id]).volumes.first.state
|
127
135
|
end
|
128
|
-
resp = client.create_snapshot(volume_id: @volume_id, description: "Snapshot of #{
|
129
|
-
|
136
|
+
resp = client.create_snapshot(volume_id: @volume_id, description: "Snapshot of #{@name}")
|
137
|
+
@snapshot_id = resp.snapshot_id
|
138
|
+
tag(@snapshot_id, Name: 'Linecook snapshot', image: @name, hvm: @hvm.to_s)
|
130
139
|
client.delete_volume(volume_id: @volume_id)
|
131
140
|
end
|
132
141
|
|
142
|
+
def create_ami
|
143
|
+
|
144
|
+
puts "Waiting for snapshot #{@snapshot_id} to be completed"
|
145
|
+
wait_for_state('completed', 900) do
|
146
|
+
client.describe_snapshots(snapshot_ids: [@snapshot_id]).snapshots.first.state
|
147
|
+
end
|
148
|
+
|
149
|
+
puts "Registering an AMI with for #{@name}"
|
150
|
+
options = {
|
151
|
+
name: @name,
|
152
|
+
virtualization_type: @hvm ? 'hvm' : 'paravirtual',
|
153
|
+
architecture: 'x86_64', # fixme
|
154
|
+
root_device_name: '/dev/sda1', # fixme when does this need to be sda?
|
155
|
+
block_device_mappings: [{
|
156
|
+
device_name: '/dev/sda1',
|
157
|
+
ebs: {
|
158
|
+
snapshot_id: @snapshot_id,
|
159
|
+
volume_size: @size,
|
160
|
+
volume_type: @hvm ? 'gp2' : 'standard', # fixme: support iops?
|
161
|
+
delete_on_termination: true,
|
162
|
+
}
|
163
|
+
}]
|
164
|
+
}
|
165
|
+
options.merge!({sriov_net_support: 'simple'}) if @hvm
|
166
|
+
|
167
|
+
resp = client.register_image(**options)
|
168
|
+
@ami_id = resp.image_id
|
169
|
+
|
170
|
+
wait_for_state('available', 300) do
|
171
|
+
client.describe_images(image_ids: [@ami_id]).images.first.state
|
172
|
+
end
|
173
|
+
|
174
|
+
amis = {
|
175
|
+
@region => @ami_id
|
176
|
+
}
|
177
|
+
|
178
|
+
@copy_regions.each do |region|
|
179
|
+
puts "Copying #{@ami_id} to #{region}"
|
180
|
+
resp = client(region: region).copy_image({
|
181
|
+
source_region: @region,
|
182
|
+
source_image_id: @ami_id,
|
183
|
+
name: @name,
|
184
|
+
description: "Copy of #{@name}",
|
185
|
+
})
|
186
|
+
ami = resp.image_id
|
187
|
+
puts "Waiting for #{ami} to become available in #{region}"
|
188
|
+
wait_for_state('available', 1800) do
|
189
|
+
client.describe_images(image_ids: [ami]).images.first.state
|
190
|
+
end
|
191
|
+
amis[region] = ami
|
192
|
+
end
|
193
|
+
|
194
|
+
unless @account_ids.empty?
|
195
|
+
amis.each do |region, ami|
|
196
|
+
puts "Updating account permissions for #{ami} in #{region}"
|
197
|
+
client(region: region).modify_image_attribute({
|
198
|
+
operation_type: 'add',
|
199
|
+
attribute: 'launchPermission',
|
200
|
+
image_id: ami,
|
201
|
+
user_ids: @account_ids
|
202
|
+
})
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
133
207
|
def free_device
|
134
208
|
prefix = device_prefix
|
135
209
|
('f'..'zzz').to_a.each do |suffix|
|
data/lib/linecook/util/config.rb
CHANGED
data/lib/linecook/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linecook-gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
@@ -192,6 +192,34 @@ dependencies:
|
|
192
192
|
- - '='
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: 1.1.7
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rbnacl
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 3.2.0
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 3.2.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rbnacl-libsodium
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - '='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 1.0.7
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.0.7
|
195
223
|
- !ruby/object:Gem::Dependency
|
196
224
|
name: rake
|
197
225
|
requirement: !ruby/object:Gem::Requirement
|