docker-template 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -6
- data/comp/list +0 -1
- data/lib/docker/template.rb +10 -0
- data/lib/docker/template/builder.rb +20 -7
- data/lib/docker/template/cache.rb +26 -18
- data/lib/docker/template/cli.rb +9 -8
- data/lib/docker/template/error.rb +12 -12
- data/lib/docker/template/metadata.rb +24 -3
- data/lib/docker/template/normal.rb +3 -3
- data/lib/docker/template/notify.rb +1 -1
- data/lib/docker/template/parser.rb +25 -6
- data/lib/docker/template/repo.rb +33 -11
- data/lib/docker/template/version.rb +1 -1
- 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: b075d40fa03bed4ef57a9a788c53c778a60cb053
|
4
|
+
data.tar.gz: b8183048b12f4547fd711e0e96ac08bc543e3cd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df02551d54168a59d5095d51f0a1f4763a07e4a16c953c40b3b4597c34941b03dc735451e043a30cd434acff0e6184e0cdcd7653b82492ad085bf31df4640f9e
|
7
|
+
data.tar.gz: 0fa1f9443e84aff442fe796df646ab06f44822ebbb1f4397d92b42988539c09b2a3ede58afa8f2bf56e2664cf993d1d51daebc285bc525aa5cc65c70b2827318
|
data/Rakefile
CHANGED
@@ -41,13 +41,13 @@ module CompList
|
|
41
41
|
def normalize_command(command)
|
42
42
|
if command.is_a?(Array)
|
43
43
|
then command.map do |key|
|
44
|
-
key.
|
45
|
-
|
44
|
+
key.tr(
|
45
|
+
"_", "-"
|
46
46
|
)
|
47
47
|
end
|
48
48
|
else
|
49
|
-
command.
|
50
|
-
|
49
|
+
command.tr(
|
50
|
+
"_", "-"
|
51
51
|
)
|
52
52
|
end
|
53
53
|
end
|
@@ -85,8 +85,7 @@ module CompList
|
|
85
85
|
)}"
|
86
86
|
end
|
87
87
|
|
88
|
-
ary
|
89
|
-
opt.aliases
|
88
|
+
ary | opt.aliases
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
data/comp/list
CHANGED
data/lib/docker/template.rb
CHANGED
@@ -83,3 +83,13 @@ module Docker
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
# ----------------------------------------------------------------------------
|
88
|
+
# Trick extras into merging array's into array's for us so users can inherit.
|
89
|
+
# ----------------------------------------------------------------------------
|
90
|
+
|
91
|
+
class Array
|
92
|
+
def deep_merge(new_)
|
93
|
+
self | new_
|
94
|
+
end
|
95
|
+
end
|
@@ -63,10 +63,13 @@ module Docker
|
|
63
63
|
# ----------------------------------------------------------------------
|
64
64
|
|
65
65
|
def aliased_img
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
if alias?
|
67
|
+
then @aliased_img ||= begin
|
68
|
+
Docker::Image.get(
|
69
|
+
aliased_repo ? aliased_repo.to_s : aliased_tag
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
70
73
|
|
71
74
|
rescue Docker::Error::NotFoundError
|
72
75
|
if alias?
|
@@ -137,10 +140,19 @@ module Docker
|
|
137
140
|
alias_setup
|
138
141
|
|
139
142
|
if @repo.buildable?
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
+
if (repo = aliased_repo)
|
144
|
+
aliased = self.class.new(repo)
|
145
|
+
unless aliased_img
|
146
|
+
aliased.build
|
147
|
+
end
|
148
|
+
|
149
|
+
elsif !aliased_img
|
150
|
+
raise(
|
151
|
+
Error::ImageNotFound, aliased_tag
|
152
|
+
)
|
153
|
+
end
|
143
154
|
|
155
|
+
Notify.alias(self)
|
144
156
|
aliased_img.tag(
|
145
157
|
@repo.to_tag_h
|
146
158
|
)
|
@@ -294,6 +306,7 @@ module Docker
|
|
294
306
|
|
295
307
|
# ----------------------------------------------------------------------
|
296
308
|
|
309
|
+
rb_delegate :aliased_tag, :to => "repo.metadata"
|
297
310
|
rb_delegate :aliased_repo, {
|
298
311
|
:to => :repo, :alias_of => :aliased
|
299
312
|
}
|
@@ -14,22 +14,25 @@ module Docker
|
|
14
14
|
# ----------------------------------------------------------------------
|
15
15
|
|
16
16
|
def context(builder, context)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
builder.repo.cache_dir.rm_rf
|
18
|
+
$stderr.puts Simple::Ansi.yellow(format("Copying context for %s", builder.repo))
|
19
|
+
cache_dir = builder.repo.cache_dir
|
20
|
+
cache_dir.parent.mkdir_p
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
readme(builder)
|
23
|
+
context.cp_r(cache_dir.tap(
|
24
|
+
&:rm_rf
|
25
|
+
))
|
26
|
+
end
|
27
|
+
|
28
|
+
# ----------------------------------------------------------------------
|
29
|
+
# rubocop:disable Metrics/LineLength
|
30
|
+
# ----------------------------------------------------------------------
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def aliased_context(builder)
|
33
|
+
if builder.aliased_repo.cache_dir.exist?
|
34
|
+
$stderr.puts Simple::Ansi.yellow(format("Copying %s context to %s", builder.aliased_repo, builder.repo))
|
35
|
+
builder.aliased_repo.cache_dir.cp_r(builder.repo.cache_dir.tap(
|
33
36
|
&:rm_rf
|
34
37
|
))
|
35
38
|
end
|
@@ -38,13 +41,18 @@ module Docker
|
|
38
41
|
# ----------------------------------------------------------------------
|
39
42
|
# Cleanup the context caches, removing the caches we no longer need.
|
40
43
|
# ----------------------------------------------------------------------
|
44
|
+
# rubocop:enable Metrics/LineLength
|
45
|
+
# ----------------------------------------------------------------------
|
41
46
|
|
42
47
|
def cleanup(repo)
|
43
|
-
repo.cache_dir.parent
|
44
|
-
|
45
|
-
|
48
|
+
cache_dir = repo.cache_dir.parent
|
49
|
+
|
50
|
+
if repo.cacheable? && cache_dir.exist?
|
51
|
+
then cache_dir.children.each do |file|
|
52
|
+
next unless repo.metadata.tags.include?(file.basename)
|
53
|
+
$stdout.puts Simple::Ansi.yellow(format("Removing %s.",
|
46
54
|
file.relative_path_from(Template.root)
|
47
|
-
|
55
|
+
))
|
48
56
|
|
49
57
|
file.rm_rf
|
50
58
|
end
|
data/lib/docker/template/cli.rb
CHANGED
@@ -28,9 +28,9 @@ module Docker
|
|
28
28
|
# ----------------------------------------------------------------------
|
29
29
|
|
30
30
|
def build(*args)
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
with_profiling do
|
32
|
+
Parser.new(args, options).parse.tap { |o| o.map(&:build) } \
|
33
|
+
.uniq(&:name).map(&:clean)
|
34
34
|
end
|
35
35
|
|
36
36
|
rescue Docker::Template::Error::StandardError => e
|
@@ -46,11 +46,13 @@ module Docker
|
|
46
46
|
option :grep, :type => :boolean, :desc => "Make --only a Regexp search."
|
47
47
|
option :only, :type => :string, :desc => "Only a specific repo."
|
48
48
|
|
49
|
+
# ----------------------------------------------------------------------
|
50
|
+
# rubocop:disable Metrics/AbcSize
|
49
51
|
# ----------------------------------------------------------------------
|
50
52
|
|
51
53
|
def list
|
52
54
|
Parser.new([], {}).parse.each do |repo|
|
53
|
-
repo_s =
|
55
|
+
repo_s = repo.to_s.gsub(/^[^\/]+\//, "")
|
54
56
|
next unless (only.is_a?(Regexp) && repo_s =~ only) \
|
55
57
|
|| (only && repo_s == only) || !only
|
56
58
|
|
@@ -58,12 +60,10 @@ module Docker
|
|
58
60
|
$stderr.print " -> ", repo.aliased.to_s, "\n" if repo.alias?
|
59
61
|
$stderr.puts unless repo.alias?
|
60
62
|
end
|
61
|
-
rescue Docker::Template::Error::StandardError => e
|
62
|
-
$stderr.puts Simple::Ansi.red(e.message)
|
63
|
-
exit e.respond_to?(:status) \
|
64
|
-
? e.status : 1
|
65
63
|
end
|
66
64
|
|
65
|
+
# ----------------------------------------------------------------------
|
66
|
+
# rubocop:enable Metrics/AbcSize
|
67
67
|
# ----------------------------------------------------------------------
|
68
68
|
|
69
69
|
no_tasks do
|
@@ -94,6 +94,7 @@ module Docker
|
|
94
94
|
MemoryProfiler.report(:top => 10_240) { yield }.pretty_print({\
|
95
95
|
:to_file => "mem.txt"
|
96
96
|
})
|
97
|
+
|
97
98
|
rescue LoadError
|
98
99
|
$stderr.puts "The gem 'memory_profiler' wasn't found."
|
99
100
|
$stderr.puts "You can install it with `gem install memory_profiler'"
|
@@ -15,8 +15,8 @@ module Docker
|
|
15
15
|
|
16
16
|
class PlaceHolderError < StandardError
|
17
17
|
def initialize(error)
|
18
|
-
super
|
19
|
-
error
|
18
|
+
super format(
|
19
|
+
"PLACEHOLDER ERROR: %s", error
|
20
20
|
)
|
21
21
|
end
|
22
22
|
end
|
@@ -74,16 +74,6 @@ module Docker
|
|
74
74
|
|
75
75
|
# ----------------------------------------------------------------------
|
76
76
|
|
77
|
-
class NoHookExists < StandardError
|
78
|
-
def initialize(base, point)
|
79
|
-
super "Unknown hook base '#{base}' or hook point '#{
|
80
|
-
point
|
81
|
-
}'"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# ----------------------------------------------------------------------
|
86
|
-
|
87
77
|
class NoRootMetadata < StandardError
|
88
78
|
def initialize
|
89
79
|
super "Metadata without the root flag must provide the root_metadata."
|
@@ -124,6 +114,16 @@ module Docker
|
|
124
114
|
}"
|
125
115
|
end
|
126
116
|
end
|
117
|
+
|
118
|
+
# ----------------------------------------------------------------------
|
119
|
+
|
120
|
+
class ImageNotFound < StandardError
|
121
|
+
def initialize(image)
|
122
|
+
super "Unable to find the image #{
|
123
|
+
image
|
124
|
+
}"
|
125
|
+
end
|
126
|
+
end
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -60,6 +60,8 @@ module Docker
|
|
60
60
|
# })
|
61
61
|
# ```
|
62
62
|
# ----------------------------------------------------------------------
|
63
|
+
# rubocop:disable Metrics/AbcSize
|
64
|
+
# ----------------------------------------------------------------------
|
63
65
|
|
64
66
|
def initialize(overrides, root: nil)
|
65
67
|
if root.is_a?(self.class)
|
@@ -89,6 +91,8 @@ module Docker
|
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
94
|
+
# ----------------------------------------------------------------------
|
95
|
+
# rubocop:enable Metrics/AbcSize
|
92
96
|
# ----------------------------------------------------------------------
|
93
97
|
|
94
98
|
def _shas
|
@@ -128,12 +132,13 @@ module Docker
|
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
131
|
-
true
|
132
135
|
else
|
133
|
-
@data.include?(
|
136
|
+
return @data.include?(
|
134
137
|
val
|
135
138
|
)
|
136
139
|
end
|
140
|
+
|
141
|
+
true
|
137
142
|
end
|
138
143
|
|
139
144
|
# ----------------------------------------------------------------------
|
@@ -257,6 +262,9 @@ module Docker
|
|
257
262
|
# --------------------------------------------------------------------
|
258
263
|
# Fallback, determining which route is the best. Tag > Group > All.
|
259
264
|
# --------------------------------------------------------------------
|
265
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
266
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
267
|
+
# ----------------------------------------------------------------------
|
260
268
|
|
261
269
|
def fallback(group: current_group, tag: current_tag, query_data: @data)
|
262
270
|
if query_data.is_a?(self.class)
|
@@ -277,6 +285,9 @@ module Docker
|
|
277
285
|
end
|
278
286
|
|
279
287
|
# --------------------------------------------------------------------
|
288
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
289
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
290
|
+
# ----------------------------------------------------------------------
|
280
291
|
|
281
292
|
def for_all(query_data: @data)
|
282
293
|
if query_data.is_a?(self.class)
|
@@ -430,6 +441,9 @@ module Docker
|
|
430
441
|
end
|
431
442
|
end
|
432
443
|
|
444
|
+
# ----------------------------------------------------------------------
|
445
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
446
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
433
447
|
# ----------------------------------------------------------------------
|
434
448
|
|
435
449
|
def to_a(raw: false, shell: false)
|
@@ -450,11 +464,16 @@ module Docker
|
|
450
464
|
end
|
451
465
|
end
|
452
466
|
|
467
|
+
# ----------------------------------------------------------------------
|
468
|
+
# rubocop:eanble Metrics/CyclomaticComplexity
|
469
|
+
# rubocop:eanble Metrics/PerceivedComplexity
|
453
470
|
# ----------------------------------------------------------------------
|
454
471
|
# Convert a `Metadata' into a normal hash. If `self' is queryable then
|
455
472
|
# we go and start merging values smartly. This means that we will merge
|
456
473
|
# all the arrays into one another and we will merge hashes into hashes.
|
457
474
|
# ----------------------------------------------------------------------
|
475
|
+
# rubocop:disable Metrics/AbcSize
|
476
|
+
# ----------------------------------------------------------------------
|
458
477
|
|
459
478
|
def to_h(raw: false)
|
460
479
|
return @data.to_h if raw || !queryable? || !mergeable_hash?
|
@@ -487,6 +506,8 @@ module Docker
|
|
487
506
|
end
|
488
507
|
end
|
489
508
|
|
509
|
+
# ----------------------------------------------------------------------
|
510
|
+
# rubocop:enable Metrics/AbcSize
|
490
511
|
# ----------------------------------------------------------------------
|
491
512
|
|
492
513
|
def mergeable_hash?(key = nil)
|
@@ -564,7 +585,7 @@ module Docker
|
|
564
585
|
|
565
586
|
private
|
566
587
|
def string_wrapper(obj, shell: false)
|
567
|
-
return obj if obj == true
|
588
|
+
return obj if obj == true || obj == false || obj.nil?
|
568
589
|
return obj.to_s(:shell => shell) if obj.is_a?(self.class)
|
569
590
|
!obj.is_a?(Array) ? obj.to_s : obj.join(
|
570
591
|
"\s"
|
@@ -32,6 +32,8 @@ module Docker
|
|
32
32
|
then raise Error::RepoNotFound
|
33
33
|
end
|
34
34
|
|
35
|
+
# ----------------------------------------------------------------------
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
35
37
|
# ----------------------------------------------------------------------
|
36
38
|
|
37
39
|
def parse
|
@@ -42,14 +44,21 @@ module Docker
|
|
42
44
|
}
|
43
45
|
|
44
46
|
all.each do |v|
|
45
|
-
hash = to_repo_hash(
|
47
|
+
hash = self.class.to_repo_hash(
|
48
|
+
v
|
49
|
+
)
|
50
|
+
|
46
51
|
if hash.empty?
|
47
|
-
raise
|
52
|
+
raise(Docker::Template::Error::BadRepoName,
|
53
|
+
v
|
54
|
+
)
|
48
55
|
|
49
56
|
else
|
50
57
|
Repo.new(hash, @argv).to_repos.each do |r|
|
51
|
-
r.alias?? repos[:aliases] << r :
|
52
|
-
|
58
|
+
r.alias?? repos[:aliases] << r : \
|
59
|
+
if r.builder.scratch?
|
60
|
+
repos[:scratch] << r else repos[:simple] << r
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|
@@ -59,10 +68,11 @@ module Docker
|
|
59
68
|
)
|
60
69
|
end
|
61
70
|
|
71
|
+
# ----------------------------------------------------------------------
|
72
|
+
# rubocop:enable Metrics/AbcSize
|
62
73
|
# ----------------------------------------------------------------------
|
63
74
|
|
64
|
-
|
65
|
-
def to_repo_hash(val)
|
75
|
+
def self.to_repo_hash(val)
|
66
76
|
data = val.split(SPLIT_REGEXP)
|
67
77
|
|
68
78
|
return "name" => data[0] if data.one?
|
@@ -72,6 +82,15 @@ module Docker
|
|
72
82
|
|
73
83
|
{}
|
74
84
|
end
|
85
|
+
|
86
|
+
# ----------------------------------------------------------------------
|
87
|
+
|
88
|
+
def self.full_name?(val)
|
89
|
+
parsed = to_repo_hash(val)
|
90
|
+
parsed.key?("name") && (parsed.key?("user") || parsed.key?(
|
91
|
+
"tag"
|
92
|
+
))
|
93
|
+
end
|
75
94
|
end
|
76
95
|
end
|
77
96
|
end
|
data/lib/docker/template/repo.rb
CHANGED
@@ -13,7 +13,12 @@ module Docker
|
|
13
13
|
|
14
14
|
def initialize(*hashes)
|
15
15
|
@base_meta = hashes.compact.reduce(:deep_merge).freeze
|
16
|
-
|
16
|
+
|
17
|
+
unless root.exist?
|
18
|
+
raise(
|
19
|
+
Error::RepoNotFound, name
|
20
|
+
)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
# ----------------------------------------------------------------------
|
@@ -21,9 +26,10 @@ module Docker
|
|
21
26
|
# ----------------------------------------------------------------------
|
22
27
|
|
23
28
|
def pushable?
|
24
|
-
(metadata["push"] || metadata["push_only"]) &&
|
25
|
-
"cache_only"
|
26
|
-
|
29
|
+
(metadata["push"] || metadata["push_only"]) &&
|
30
|
+
!metadata["cache_only"] && !metadata[
|
31
|
+
"clean_only"
|
32
|
+
]
|
27
33
|
end
|
28
34
|
|
29
35
|
# ----------------------------------------------------------------------
|
@@ -31,9 +37,10 @@ module Docker
|
|
31
37
|
# ----------------------------------------------------------------------
|
32
38
|
|
33
39
|
def cacheable?
|
34
|
-
(metadata["cache"] || metadata["cache_only"]) &&
|
35
|
-
|
36
|
-
|
40
|
+
(metadata["cache"] || metadata["cache_only"]) &&
|
41
|
+
!metadata[
|
42
|
+
"push_only"
|
43
|
+
]
|
37
44
|
end
|
38
45
|
|
39
46
|
# ----------------------------------------------------------------------
|
@@ -41,9 +48,10 @@ module Docker
|
|
41
48
|
# ----------------------------------------------------------------------
|
42
49
|
|
43
50
|
def buildable?
|
44
|
-
!metadata["push_only"] && !metadata["cache_only"] &&
|
45
|
-
|
46
|
-
|
51
|
+
!metadata["push_only"] && !metadata["cache_only"] &&
|
52
|
+
!metadata[
|
53
|
+
"clean_only"
|
54
|
+
]
|
47
55
|
end
|
48
56
|
|
49
57
|
# ----------------------------------------------------------------------
|
@@ -52,11 +60,25 @@ module Docker
|
|
52
60
|
# ----------------------------------------------------------------------
|
53
61
|
|
54
62
|
def aliased
|
55
|
-
|
63
|
+
full = Parser.full_name?(
|
64
|
+
metadata.aliased_tag
|
65
|
+
)
|
66
|
+
|
67
|
+
if alias? && full
|
68
|
+
self.class.new(to_h.merge(Parser.to_repo_hash(
|
69
|
+
metadata.aliased_tag
|
70
|
+
)))
|
71
|
+
|
72
|
+
elsif alias?
|
56
73
|
self.class.new(to_h.merge({
|
57
74
|
"tag" => metadata.aliased_tag
|
58
75
|
}))
|
59
76
|
end
|
77
|
+
|
78
|
+
rescue Error::RepoNotFound => e
|
79
|
+
unless full
|
80
|
+
raise e
|
81
|
+
end
|
60
82
|
end
|
61
83
|
|
62
84
|
# ----------------------------------------------------------------------
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|