dockit 1.5.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/dockit.rb +20 -0
- data/lib/dockit/cli.rb +37 -9
- data/lib/dockit/container.rb +8 -1
- data/lib/dockit/image.rb +17 -10
- data/lib/dockit/service.rb +3 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef7365a09071c0358f23ed17ed670b15bd9f3f91
|
4
|
+
data.tar.gz: 062246eb13c406ba75125f815d95b45b0bc17268
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d71b2c9f2af87dd739037fe54dee9de742b4de441f47f5f83c7e21381a6ce14b60a39f046e855794a825445dc64ddb2e84d134e28eb84a836c84c71ef513578e
|
7
|
+
data.tar.gz: 71fdb7a5879d9ec895bfe9f60315d7720d020b11ba76e27d761e9b94738be8624e621152303c0ba52d8adb164f2632ef5abac8a02a28cb752f3eb716b0e2c746
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.0
|
data/lib/dockit.rb
CHANGED
@@ -16,6 +16,26 @@ module Dockit
|
|
16
16
|
def debug(msg)
|
17
17
|
$stderr.puts "DEBUG: " + msg.join(' ')
|
18
18
|
end
|
19
|
+
|
20
|
+
def self.print_chunk(chunk)
|
21
|
+
begin
|
22
|
+
chunk = JSON.parse(chunk)
|
23
|
+
rescue Docker::Error::UnexpectedResponseError => e
|
24
|
+
$stderr.puts "Response parse error:", e.message, chunk
|
25
|
+
end
|
26
|
+
|
27
|
+
progress = chunk['progress']
|
28
|
+
id = progress ? '' : chunk['id']
|
29
|
+
$stdout.puts(
|
30
|
+
if chunk['errorDetail']
|
31
|
+
'ERROR: ' + chunk['errorDetail']['message']
|
32
|
+
elsif chunk['stream']
|
33
|
+
chunk['stream']
|
34
|
+
else
|
35
|
+
[chunk['status'], id, progress, progress ? "\r" : "\n"].join(' ')
|
36
|
+
end
|
37
|
+
)
|
38
|
+
end
|
19
39
|
end
|
20
40
|
|
21
41
|
# This class encapsulates the environment used in the Dockit cli.
|
data/lib/dockit/cli.rb
CHANGED
@@ -42,7 +42,7 @@ class Default < Thor
|
|
42
42
|
class_option :locals, type: :hash, aliases: ['l'],
|
43
43
|
banner: "key:value [key:value ...]",
|
44
44
|
desc: "variables to pass to yaml file."
|
45
|
-
class_option :timeout, type: :numeric, desc: 'Timeout for excon', default:
|
45
|
+
class_option :timeout, type: :numeric, desc: 'Timeout for excon', default: 180
|
46
46
|
|
47
47
|
def initialize(*args)
|
48
48
|
super
|
@@ -52,7 +52,7 @@ class Default < Thor
|
|
52
52
|
Docker.options[:read_timeout] = options.timeout
|
53
53
|
|
54
54
|
unless @@root_echoed
|
55
|
-
|
55
|
+
say "Project root: #{dockit.root}", :red
|
56
56
|
@@root_echoed=true
|
57
57
|
end
|
58
58
|
end
|
@@ -125,10 +125,16 @@ class Default < Thor
|
|
125
125
|
option :containers, type: :boolean, default: true , desc: "remove exited containers"
|
126
126
|
option :volumes , type: :boolean, default: true , desc: 'remove dangling volumes'
|
127
127
|
option :force , type: :boolean, default: false, desc: "stop and remove all"
|
128
|
+
option 'except-containers', type: :array, desc: "container names to leave if :force", aliases: %[C]
|
129
|
+
option 'except-images', type: :array, desc: "image tags (name:version) to leave if :force", aliases: %[I]
|
130
|
+
|
128
131
|
def cleanup
|
129
132
|
force = options[:force]
|
130
|
-
Dockit::Container.clean(
|
131
|
-
|
133
|
+
Dockit::Container.clean(
|
134
|
+
force: force, except: options['except-containers']) if options[:containers]
|
135
|
+
|
136
|
+
Dockit::Image.clean(
|
137
|
+
force: force, except: options['except-images']) if options[:images]
|
132
138
|
|
133
139
|
if options[:volumes] && Docker.version['ApiVersion'].to_f >= 1.21
|
134
140
|
Dockit::Volume.clean
|
@@ -171,10 +177,30 @@ class Default < Thor
|
|
171
177
|
desc 'git-build', 'build from git (gem) repository'
|
172
178
|
option :branch, desc: '<tree-ish> git reference', default: 'master'
|
173
179
|
option :gem, type: :boolean, desc: "update Gemfiles export"
|
180
|
+
option :package, type: :boolean, desc: "update package config export"
|
181
|
+
long_desc <<-LONGDESC
|
182
|
+
Dockit.yaml keys used:
|
183
|
+
\x5 repos_path: optional treeish path
|
184
|
+
\x5 repos: repository location
|
185
|
+
\x5 package: optional (default 'Gemfile*')
|
186
|
+
|
187
|
+
`dockit git-build` will export {branch}:repos_path from the
|
188
|
+
repository location specified in the :repos key to 'repos.tar.gz'
|
189
|
+
|
190
|
+
The '--package' option will export the files in the :package key (or
|
191
|
+
Gemfile*) in Dockit.yaml separately to 'package.tar.gz'. This is docker
|
192
|
+
best practice for building rails apps.
|
193
|
+
|
194
|
+
*Note* The default (Gemfile*) will be removed in version 2.0.
|
195
|
+
|
196
|
+
The deprecated '--gem' option is will export the packages to
|
197
|
+
'gemfile.tar.gz'.
|
198
|
+
LONGDESC
|
199
|
+
|
174
200
|
def git_build(service=nil)
|
175
201
|
exec(service) do |s|
|
176
202
|
unless repos = s.config.get(:repos)
|
177
|
-
say "'repos' not defined in config file. Exiting"
|
203
|
+
say "'repos' not defined in config file. Exiting", :red
|
178
204
|
exit 1
|
179
205
|
end
|
180
206
|
path = s.config.get(:repos_path)
|
@@ -185,10 +211,12 @@ class Default < Thor
|
|
185
211
|
end
|
186
212
|
say "Exporting in #{Dir.pwd}", :green
|
187
213
|
say "<- #{repos} #{treeish}", :green
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
214
|
+
|
215
|
+
if options.gem || options.package
|
216
|
+
packages = s.config.get(:package) || 'Gemfile*'
|
217
|
+
archive = options.gem ? 'gemfile.tar.gz' : 'package.tar.gz'
|
218
|
+
say "-> #{archive}", :green
|
219
|
+
export(repos, treeish, archive, packages)
|
192
220
|
end
|
193
221
|
|
194
222
|
say "-> repos.tar.gz", :green
|
data/lib/dockit/container.rb
CHANGED
@@ -7,13 +7,20 @@ module Dockit
|
|
7
7
|
Docker::Container.all(all: all, filters: JSON.dump(filters))
|
8
8
|
end
|
9
9
|
|
10
|
-
def clean(force: false)
|
10
|
+
def clean(force: false, except: [])
|
11
11
|
puts "Containers..."
|
12
|
+
except = (except||[]).map { |e| "/#{e}"}
|
13
|
+
|
12
14
|
list(
|
13
15
|
all: force,
|
14
16
|
filters: force ? nil : {status: [:exited]}
|
15
17
|
).each do |container|
|
18
|
+
names = container.info['Names']
|
16
19
|
puts " #{container.id}"
|
20
|
+
if (names & except).count > 0
|
21
|
+
puts " ... skipping #{names}"
|
22
|
+
next
|
23
|
+
end
|
17
24
|
container.delete(force: true, v: force)
|
18
25
|
end
|
19
26
|
end
|
data/lib/dockit/image.rb
CHANGED
@@ -14,16 +14,16 @@ module Dockit
|
|
14
14
|
end
|
15
15
|
repos = config['t']
|
16
16
|
puts "Building #{repos}"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
progress = chunk['progress']
|
21
|
-
id = progress ? '' : chunk['id']
|
22
|
-
print chunk['stream'] ? chunk['stream'] :
|
23
|
-
[chunk['status'], id, progress, progress ? "\r" : "\n"].join(' ')
|
24
|
-
rescue
|
25
|
-
puts chunk
|
17
|
+
begin
|
18
|
+
image = Docker::Image.build_from_dir('.', config) do |chunk|
|
19
|
+
Dockit::Log.print_chunk(chunk)
|
26
20
|
end
|
21
|
+
rescue Docker::Error::TimeoutError => e
|
22
|
+
$stderr.puts '* Read timeout, try again with a larger "--timeout"'
|
23
|
+
exit 1
|
24
|
+
rescue Docker::Error::UnexpectedResponseError => e
|
25
|
+
$stderr.puts 'Build error, exiting.'
|
26
|
+
exit 1
|
27
27
|
end
|
28
28
|
|
29
29
|
image
|
@@ -33,13 +33,20 @@ module Dockit
|
|
33
33
|
Docker::Image.get(name)
|
34
34
|
end
|
35
35
|
|
36
|
-
def clean(force: false)
|
36
|
+
def clean(force: false, except: [])
|
37
|
+
except ||= []
|
37
38
|
puts "Images..."
|
38
39
|
list(
|
39
40
|
all: force,
|
40
41
|
filters: force ? nil : {dangling: ['true']}
|
41
42
|
).each do |image|
|
43
|
+
names = image.info["RepoTags"]
|
42
44
|
puts " #{image.id}"
|
45
|
+
if (names & except).count > 0
|
46
|
+
puts " ... skipping #{names}"
|
47
|
+
next
|
48
|
+
end
|
49
|
+
|
43
50
|
image.remove(force: true)
|
44
51
|
end
|
45
52
|
end
|
data/lib/dockit/service.rb
CHANGED
@@ -61,14 +61,10 @@ module Dockit
|
|
61
61
|
end
|
62
62
|
|
63
63
|
name = "#{registry}/#{repo}"
|
64
|
-
image = Docker::Image.create(
|
65
|
-
|
66
|
-
chunk = JSON.parse(chunk)
|
67
|
-
progress = chunk['progress']
|
68
|
-
id = progress ? '' : chunk['id']
|
69
|
-
print chunk['stream'] ? chunk['stream'] :
|
70
|
-
[chunk['status'], id, progress, progress ? "\r" : "\n"].join(' ')
|
64
|
+
image = Docker::Image.create(fromImage: name) do |chunk|
|
65
|
+
Dockit::Log::print_chunk(chunk)
|
71
66
|
end
|
67
|
+
|
72
68
|
puts "Tagging #{name} as #{repo}:#{tag||'latest'}"
|
73
69
|
image.tag(repo: repo, tag: tag, force: force)
|
74
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Frankel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|