linecook-gem 0.7.25 → 0.7.26
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-gem/cli.rb +15 -1
- data/lib/linecook-gem/image.rb +4 -0
- data/lib/linecook-gem/image/s3.rb +20 -1
- data/lib/linecook-gem/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: 192443005342695e7942ab306489e53cc8315919
|
|
4
|
+
data.tar.gz: 00df5e02a21f7a5cc67d2434c38cae9a6df2b2f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e5c348a118bb4a76ddbb925a81961c4d60daf3003cce5e3df559845af2aa9733d8c29cfc8538922ddccede1f3037de9b3f10b3fd2e221d5cf0d33541451c2fe
|
|
7
|
+
data.tar.gz: 842c7e155423a6ccc922078cd78a39f8b1d27c3a8bf89c327194fa60046499eff61834f6d6fa81b39179eff2a4135346cbc27eef3ac337e9176d910eee49459c
|
data/lib/linecook-gem/cli.rb
CHANGED
|
@@ -10,8 +10,22 @@ class Image < Thor
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
desc 'list', 'List images'
|
|
13
|
+
method_option :name, type: :string, required: false, banner: 'NAME', desc: 'Name of the image to fetch.', aliases: '-n'
|
|
14
|
+
method_option :group, type: :string, required: false, banner: 'ID', desc: 'Group of image to list', aliases: '-g'
|
|
13
15
|
def list
|
|
14
|
-
|
|
16
|
+
opts = options.symbolize_keys
|
|
17
|
+
image = Linecook::Image.new(opts[:name], opts[:group], nil)
|
|
18
|
+
puts image.list
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc 'clean', 'Cleanup old images'
|
|
22
|
+
method_option :name, type: :string, required: true, banner: 'NAME', desc: 'Name of the image to fetch.', aliases: '-n'
|
|
23
|
+
method_option :group, type: :string, required: true, banner: 'ID', desc: 'Group of image to list', aliases: '-g'
|
|
24
|
+
method_option :retention, type: :numeric, required: false, banner: 'RETENTION', desc: 'Images to keep', aliases: '-k', default: 5
|
|
25
|
+
def clean
|
|
26
|
+
opts = options.symbolize_keys
|
|
27
|
+
image = Linecook::Image.new(opts[:name], opts[:group], nil)
|
|
28
|
+
puts "Cleaned up #{image.clean(opts[:retention]).length} images"
|
|
15
29
|
end
|
|
16
30
|
|
|
17
31
|
desc 'fetch', 'Fetch and decrypt an image'
|
data/lib/linecook-gem/image.rb
CHANGED
|
@@ -18,6 +18,17 @@ module Linecook
|
|
|
18
18
|
list_objects(group: group).map{ |x| x.key if x.key =~ /\.tar\.xz/ }.compact
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def clean(retention, group)
|
|
22
|
+
full_set = list(group: group)
|
|
23
|
+
keep = full_set.reverse.take(retention)
|
|
24
|
+
destroy = full_set - keep
|
|
25
|
+
destroy.each_slice(1000).each do |garbage|
|
|
26
|
+
to_destroy = garbage.map { |x| { key: x } }
|
|
27
|
+
client.delete_objects(bucket: Linecook.config[:aws][:s3][:bucket], delete: { objects: to_destroy} )
|
|
28
|
+
end
|
|
29
|
+
return destroy
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
def latest(group)
|
|
22
33
|
objects = list_objects(group: group).sort! { |a,b| a.last_modified <=> b.last_modified }
|
|
23
34
|
key = objects.last ? objects.last.key : nil
|
|
@@ -48,7 +59,15 @@ module Linecook
|
|
|
48
59
|
private
|
|
49
60
|
|
|
50
61
|
def list_objects(group: nil)
|
|
51
|
-
|
|
62
|
+
contents = []
|
|
63
|
+
marker = nil
|
|
64
|
+
loop do
|
|
65
|
+
resp = client.list_objects(bucket: Linecook.config[:aws][:s3][:bucket], prefix: File.join([PREFIX, group].compact), marker: marker)
|
|
66
|
+
break unless resp.contents.last
|
|
67
|
+
marker = resp.contents.last.key
|
|
68
|
+
contents += resp.contents
|
|
69
|
+
end
|
|
70
|
+
contents.sort { |a,b| a.last_modified <=> b.last_modified }
|
|
52
71
|
end
|
|
53
72
|
|
|
54
73
|
def client
|
data/lib/linecook-gem/version.rb
CHANGED