linecook-gem 0.7.13 → 0.7.14
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/baker/docker.rb +14 -5
- data/lib/linecook-gem/packager/packer.rb +2 -24
- data/lib/linecook-gem/util/locking.rb +29 -0
- data/lib/linecook-gem/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdfda88b02f59d7207a72bb5cf478f5211471ffa
|
|
4
|
+
data.tar.gz: b62d50d1caeaed2126437781ac9591cf2a61db72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a09c5d0e13281c5154210a3dffc1f8e7592418afb3b9be478873b0236a0d01a28100005fc3e340cdfef6d5eb184f933680200a521a240e2c2a6d610389492577
|
|
7
|
+
data.tar.gz: d28b99d10e116e387cc6ff69dec1513eb3ab0cf464d3249801eeb43393df125d27eb5acacbc84e39f1623dfb70c22210cc92b3a554b32ffcf7939c0869f2dc79
|
|
@@ -4,6 +4,7 @@ require 'fileutils'
|
|
|
4
4
|
require 'docker'
|
|
5
5
|
|
|
6
6
|
require 'linecook-gem/image'
|
|
7
|
+
require 'linecook-gem/util/locking'
|
|
7
8
|
|
|
8
9
|
# Until https://github.com/swipely/docker-api/pull/413 gets merged
|
|
9
10
|
class Excon::Errors::InternalServerError < Excon::Errors::InternalServerErrorError; end
|
|
@@ -12,6 +13,7 @@ module Linecook
|
|
|
12
13
|
module Baker
|
|
13
14
|
# FIXME - refactor into a base class with an interface
|
|
14
15
|
class Docker
|
|
16
|
+
include Locking
|
|
15
17
|
|
|
16
18
|
RETAIN_IMAGES = 3 # number of latest images to retain
|
|
17
19
|
|
|
@@ -99,13 +101,20 @@ module Linecook
|
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
def import(image)
|
|
102
|
-
|
|
103
|
-
image
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
lock("import_#{image.id}")
|
|
105
|
+
if image_exists?(image)
|
|
106
|
+
puts "Image #{image.id} has already been imported"
|
|
107
|
+
else
|
|
108
|
+
puts "Importing #{image.id}..."
|
|
109
|
+
image.fetch
|
|
110
|
+
open(image.path) do |io|
|
|
111
|
+
::Docker::Image.import_stream(repo: image.group, tag: image.tag, changes: ['CMD ["/sbin/init"]']) do
|
|
112
|
+
io.read(Excon.defaults[:chunk_size] * 10 ) || ""
|
|
113
|
+
end
|
|
107
114
|
end
|
|
108
115
|
end
|
|
116
|
+
ensure
|
|
117
|
+
unlock("import_#{image.id}")
|
|
109
118
|
end
|
|
110
119
|
|
|
111
120
|
|
|
@@ -8,12 +8,14 @@ require 'pty'
|
|
|
8
8
|
|
|
9
9
|
require 'linecook-gem/image'
|
|
10
10
|
require 'linecook-gem/util/downloader'
|
|
11
|
+
require 'linecook-gem/util/locking'
|
|
11
12
|
require 'linecook-gem/packager/route53'
|
|
12
13
|
|
|
13
14
|
module Linecook
|
|
14
15
|
class AmiPacker
|
|
15
16
|
|
|
16
17
|
include Downloader
|
|
18
|
+
include Locking
|
|
17
19
|
|
|
18
20
|
SOURCE_URL = 'https://releases.hashicorp.com/packer/'
|
|
19
21
|
PACKER_VERSION = '0.8.6'
|
|
@@ -186,30 +188,6 @@ module Linecook
|
|
|
186
188
|
!File.exists?("/dev/#{device}") && !File.exists?(lock_path(device))
|
|
187
189
|
end
|
|
188
190
|
|
|
189
|
-
def lock(name)
|
|
190
|
-
lockfile(name).flock(File::LOCK_EX)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def unlock(name)
|
|
194
|
-
lockfile(name).flock(File::LOCK_UN)
|
|
195
|
-
lockfile(name).close
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def clear_lock(name)
|
|
199
|
-
unlock(name)
|
|
200
|
-
FileUtils.rm_f(lockfile(name))
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
def lockfile(suffix)
|
|
204
|
-
@locks ||= {}
|
|
205
|
-
path = lock_path(suffix)
|
|
206
|
-
@locks[path] = @locks[path] || File.open(path, File::RDWR|File::CREAT, 0644)
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
def lock_path(suffix)
|
|
210
|
-
"/tmp/free_device_lock_#{suffix.gsub('/','_')}"
|
|
211
|
-
end
|
|
212
|
-
|
|
213
191
|
def device_prefix
|
|
214
192
|
prefixes = ['xvd', 'sd']
|
|
215
193
|
`sudo ls -1 /sys/block`.lines.each do |dev| # FIXME
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
module Linecook
|
|
4
|
+
module Locking
|
|
5
|
+
def lock(name)
|
|
6
|
+
lockfile(name).flock(File::LOCK_EX)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def unlock(name)
|
|
10
|
+
lockfile(name).flock(File::LOCK_UN)
|
|
11
|
+
lockfile(name).close
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def clear_lock(name)
|
|
15
|
+
unlock(name)
|
|
16
|
+
FileUtils.rm_f(lockfile(name))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def lockfile(suffix)
|
|
20
|
+
@locks ||= {}
|
|
21
|
+
path = lock_path(suffix)
|
|
22
|
+
@locks[path] = @locks[path] || File.open(path, File::RDWR|File::CREAT, 0644)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def lock_path(suffix)
|
|
26
|
+
"/tmp/lock_#{suffix.gsub('/','_')}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/linecook-gem/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.7.
|
|
4
|
+
version: 0.7.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dale Hamel
|
|
@@ -280,6 +280,7 @@ files:
|
|
|
280
280
|
- lib/linecook-gem/packager/route53.rb
|
|
281
281
|
- lib/linecook-gem/packager/squashfs.rb
|
|
282
282
|
- lib/linecook-gem/util/downloader.rb
|
|
283
|
+
- lib/linecook-gem/util/locking.rb
|
|
283
284
|
- lib/linecook-gem/util/secrets.rb
|
|
284
285
|
- lib/linecook-gem/version.rb
|
|
285
286
|
- man/LINECOOK.1
|