docker-template 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +18 -20
- data/bin/docker-template +7 -10
- data/comp/list +7 -10
- data/comp/list.pak +0 -0
- data/lib/docker/template.rb +33 -30
- data/lib/docker/template/auth.rb +72 -0
- data/lib/docker/template/builder.rb +169 -81
- data/lib/docker/template/builder/normal.rb +58 -0
- data/lib/docker/template/builder/rootfs.rb +111 -0
- data/lib/docker/template/builder/scratch.rb +165 -0
- data/lib/docker/template/cache.rb +15 -20
- data/lib/docker/template/cli.rb +77 -20
- data/lib/docker/template/cli/build.rb +23 -8
- data/lib/docker/template/cli/list.rb +10 -10
- data/lib/docker/template/error.rb +12 -43
- data/lib/docker/template/logger.rb +99 -38
- data/lib/docker/template/{metadata.rb → meta.rb} +209 -114
- data/lib/docker/template/notify.rb +55 -12
- data/lib/docker/template/parser.rb +44 -35
- data/lib/docker/template/repo.rb +85 -81
- data/lib/docker/template/version.rb +1 -3
- data/lib/erb/context.rb +5 -8
- data/templates/rootfs/alpine.erb +65 -66
- data/templates/rootfs/ubuntu.erb +71 -42
- metadata +32 -12
- data/lib/docker/template/normal.rb +0 -46
- data/lib/docker/template/rootfs.rb +0 -85
- data/lib/docker/template/scratch.rb +0 -166
- data/shas.yml +0 -11
@@ -1,17 +1,15 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
module Docker
|
8
6
|
module Template
|
9
7
|
module Notify
|
10
8
|
module_function
|
11
9
|
|
12
|
-
#
|
10
|
+
# --
|
13
11
|
# Notify the user of a push that is happening.
|
14
|
-
#
|
12
|
+
# --
|
15
13
|
|
16
14
|
def push(builder)
|
17
15
|
$stderr.puts Simple::Ansi.green(
|
@@ -19,9 +17,9 @@ module Docker
|
|
19
17
|
)
|
20
18
|
end
|
21
19
|
|
22
|
-
#
|
20
|
+
# --
|
23
21
|
# Notify the user that we are tag aliasing.
|
24
|
-
#
|
22
|
+
# --
|
25
23
|
|
26
24
|
def alias(builder)
|
27
25
|
repo = builder.repo
|
@@ -30,14 +28,59 @@ module Docker
|
|
30
28
|
$stderr.puts msg
|
31
29
|
end
|
32
30
|
|
33
|
-
#
|
31
|
+
# --
|
32
|
+
|
33
|
+
def build(repo, rootfs: false)
|
34
|
+
build_start(repo, {
|
35
|
+
:rootfs => rootfs
|
36
|
+
})
|
37
|
+
|
38
|
+
if block_given?
|
39
|
+
yield
|
40
|
+
build_end(repo, {
|
41
|
+
:rootfs => rootfs
|
42
|
+
})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# --
|
34
47
|
# Notify the user that we are building their repository.
|
35
|
-
#
|
48
|
+
# --
|
36
49
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
50
|
+
def build_start(repo, rootfs: false)
|
51
|
+
if ENV["TRAVIS"] && !ENV.key?("RSPEC_RUNNING")
|
52
|
+
STDOUT.puts(format("travis_fold:end:%s",
|
53
|
+
repo.to_s(:rootfs => rootfs).tr("^A-Za-z0-9", "-").gsub(
|
54
|
+
/\-$/, ""
|
55
|
+
)
|
56
|
+
))
|
57
|
+
end
|
58
|
+
|
59
|
+
$stderr.puts Simple::Ansi.green(format(
|
60
|
+
"Building: %s", repo.to_s({
|
61
|
+
:rootfs => rootfs
|
62
|
+
})
|
63
|
+
))
|
64
|
+
end
|
65
|
+
|
66
|
+
# --
|
67
|
+
# Notify the user that building their repository has ended.
|
68
|
+
# --
|
69
|
+
|
70
|
+
def build_end(repo, rootfs: false)
|
71
|
+
if ENV["TRAVIS"] && !ENV.key?("RSPEC_RUNNING")
|
72
|
+
STDOUT.puts(format("travis_fold:end:%s",
|
73
|
+
repo.to_s(:rootfs => rootfs).tr("^A-Za-z0-9", "-").gsub(
|
74
|
+
/\-$/, ""
|
75
|
+
)
|
76
|
+
))
|
77
|
+
end
|
78
|
+
|
79
|
+
$stderr.puts Simple::Ansi.green(format(
|
80
|
+
"Done Building: %s", repo.to_s({
|
81
|
+
:rootfs => rootfs
|
82
|
+
})
|
83
|
+
))
|
41
84
|
end
|
42
85
|
end
|
43
86
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
module Docker
|
8
6
|
module Template
|
@@ -16,62 +14,60 @@ module Docker
|
|
16
14
|
@argv = argv
|
17
15
|
end
|
18
16
|
|
19
|
-
#
|
17
|
+
# --
|
20
18
|
# Return `raw_repos` if you send us a list of repos you wish to build,
|
21
19
|
# otherwise we get the children of the repo folder and ship that off so
|
22
20
|
# you can build *every* repo, I don't know if you want that.
|
23
|
-
#
|
24
|
-
|
21
|
+
# --
|
25
22
|
def all
|
26
23
|
return @raw_repos unless @raw_repos.empty?
|
27
|
-
Template.root.
|
24
|
+
return [Template.root.basename.to_s] if Template.project?
|
25
|
+
Template.root.join(Meta.new({}).repos_dir).children.map do |path|
|
28
26
|
path.basename.to_s
|
29
27
|
end
|
30
28
|
|
31
29
|
rescue Errno::ENOENT
|
32
|
-
then raise
|
30
|
+
then raise(
|
31
|
+
Error::RepoNotFound
|
32
|
+
)
|
33
33
|
end
|
34
34
|
|
35
|
-
#
|
35
|
+
# --
|
36
36
|
# rubocop:disable Metrics/AbcSize
|
37
|
-
#
|
38
|
-
|
37
|
+
# --
|
39
38
|
def parse
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
:aliases => []
|
44
|
-
}
|
39
|
+
scratch = []
|
40
|
+
simple = []
|
41
|
+
aliases = []
|
45
42
|
|
46
43
|
all.each do |v|
|
47
|
-
hash = self.class.to_repo_hash(
|
48
|
-
|
49
|
-
)
|
44
|
+
hash = self.class.to_repo_hash(v)
|
45
|
+
raise Error::BadRepoName, v if hash.empty?
|
46
|
+
Repo.new(hash, @argv).to_repos.each do |r|
|
47
|
+
scratch << r if r.builder.scratch? && !r.alias?
|
48
|
+
simple << r unless r.alias? || r.builder.scratch?
|
49
|
+
aliases << r if r.alias?
|
50
|
+
end
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
out = aliases.each_with_object(scratch | simple) do |alias_, repos|
|
54
|
+
index = repos.rindex { |v| v.name == alias_.name }
|
55
|
+
if index
|
56
|
+
repos.insert(index + 1,
|
57
|
+
alias_
|
54
58
|
)
|
55
59
|
|
56
60
|
else
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
repos[:scratch] << r else repos[:simple] << r
|
61
|
-
end
|
62
|
-
end
|
61
|
+
repos.push(
|
62
|
+
alias_
|
63
|
+
)
|
63
64
|
end
|
64
65
|
end
|
65
|
-
|
66
|
-
repos.values.reduce(
|
67
|
-
:|
|
68
|
-
)
|
69
66
|
end
|
70
67
|
|
71
|
-
#
|
68
|
+
# --
|
72
69
|
# rubocop:enable Metrics/AbcSize
|
73
|
-
#
|
74
|
-
|
70
|
+
# --
|
75
71
|
def self.to_repo_hash(val)
|
76
72
|
data = val.to_s.split(SPLIT_REGEXP)
|
77
73
|
|
@@ -83,7 +79,20 @@ module Docker
|
|
83
79
|
{}
|
84
80
|
end
|
85
81
|
|
86
|
-
#
|
82
|
+
# --
|
83
|
+
|
84
|
+
def self.from_tag_to_repo_hash(val)
|
85
|
+
data = val.to_s.split(SPLIT_REGEXP)
|
86
|
+
|
87
|
+
return "tag" => data[0] if data.one?
|
88
|
+
return "name" => data[0], "tag" => data[1] if val =~ COLON_REGEXP && data.size == 2
|
89
|
+
return "user" => data[0], "name" => data[1] if val =~ SLASH_REGEXP && data.size == 2
|
90
|
+
return "user" => data[0], "name" => data[1], "tag" => data[2] if data.size == 3
|
91
|
+
|
92
|
+
{}
|
93
|
+
end
|
94
|
+
|
95
|
+
# --
|
87
96
|
|
88
97
|
def self.full_name?(val)
|
89
98
|
parsed = to_repo_hash(val)
|
data/lib/docker/template/repo.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
module Docker
|
8
6
|
module Template
|
9
7
|
class Repo
|
10
8
|
extend Forwardable::Extended
|
11
9
|
|
12
|
-
#
|
10
|
+
# --
|
13
11
|
|
14
12
|
def initialize(*hashes)
|
15
|
-
@base_meta = hashes.compact
|
13
|
+
@base_meta = hashes.compact
|
14
|
+
@base_meta = @base_meta.reduce(:deep_merge)
|
15
|
+
@base_meta.freeze
|
16
16
|
|
17
17
|
unless root.exist?
|
18
18
|
raise(
|
@@ -21,57 +21,56 @@ module Docker
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
25
|
-
# Determines whether or not we should (or you should) push the repo.
|
26
|
-
# ----------------------------------------------------------------------
|
24
|
+
# --
|
27
25
|
|
28
26
|
def pushable?
|
29
|
-
(
|
30
|
-
!
|
27
|
+
(meta["push"] || meta["push_only"]) &&
|
28
|
+
!meta["cache_only"] && !meta[
|
31
29
|
"clean_only"
|
32
30
|
]
|
33
31
|
end
|
34
32
|
|
35
|
-
#
|
36
|
-
# Determines whether or not we should (or you should) cache the repo.
|
37
|
-
# ----------------------------------------------------------------------
|
33
|
+
# --
|
38
34
|
|
39
35
|
def cacheable?
|
40
|
-
(
|
41
|
-
!
|
36
|
+
(meta["cache"] || meta["cache_only"]) &&
|
37
|
+
!meta[
|
42
38
|
"push_only"
|
43
39
|
]
|
44
40
|
end
|
45
41
|
|
46
|
-
#
|
47
|
-
|
48
|
-
|
42
|
+
# --
|
43
|
+
|
44
|
+
def clean_cache?
|
45
|
+
(meta["clean"] || meta["clean_only"])
|
46
|
+
end
|
47
|
+
|
48
|
+
# --
|
49
49
|
|
50
50
|
def buildable?
|
51
|
-
!
|
52
|
-
!
|
51
|
+
meta.build? && !meta["push_only"] && !meta["cache_only"] &&
|
52
|
+
!meta[
|
53
53
|
"clean_only"
|
54
54
|
]
|
55
55
|
end
|
56
56
|
|
57
|
-
#
|
57
|
+
# --
|
58
58
|
# Pulls out the repo this repo is aliasing it, this happens when you
|
59
59
|
# when you set the tag in the "alias" section of your `opts.yml`.
|
60
|
-
#
|
61
|
-
|
60
|
+
# --
|
62
61
|
def aliased
|
63
62
|
full = Parser.full_name?(
|
64
|
-
|
63
|
+
meta.aliased_tag
|
65
64
|
)
|
66
65
|
|
67
66
|
if alias? && full
|
68
67
|
self.class.new(to_h.merge(Parser.to_repo_hash(
|
69
|
-
|
68
|
+
meta.aliased_tag
|
70
69
|
)))
|
71
70
|
|
72
71
|
elsif alias?
|
73
72
|
self.class.new(to_h.merge({
|
74
|
-
"tag" =>
|
73
|
+
"tag" => meta.aliased_tag
|
75
74
|
}))
|
76
75
|
end
|
77
76
|
|
@@ -81,51 +80,47 @@ module Docker
|
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
84
|
-
#
|
83
|
+
# --
|
85
84
|
# Initializes and returns the builder so that you can build the repo.
|
86
|
-
#
|
87
|
-
|
85
|
+
# --
|
88
86
|
def builder
|
89
87
|
return @builder ||= begin
|
90
|
-
Template.const_get(type.capitalize).new(
|
88
|
+
Template::Builder.const_get(type.capitalize).new(
|
91
89
|
self
|
92
90
|
)
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
96
|
-
#
|
94
|
+
# --
|
97
95
|
# Convert the repo into it's final image name, however if you tell, us
|
98
96
|
# this is a rootfs build we will convert it into the rootfs name.
|
99
|
-
#
|
100
|
-
|
97
|
+
# --
|
101
98
|
def to_s(rootfs: false)
|
102
|
-
prefix =
|
99
|
+
prefix = meta["local_prefix"]
|
103
100
|
return "#{user}/#{name}:#{tag}" unless rootfs
|
104
101
|
"#{prefix}/rootfs:#{name}"
|
105
102
|
end
|
106
103
|
|
107
|
-
#
|
104
|
+
# --
|
108
105
|
# The directory you wish to cache to (like `cache/`) or other.
|
109
|
-
#
|
110
|
-
|
106
|
+
# --
|
111
107
|
def cache_dir
|
112
108
|
return root.join(
|
113
|
-
|
109
|
+
meta["cache_dir"], tag
|
114
110
|
)
|
115
111
|
end
|
116
112
|
|
117
|
-
#
|
113
|
+
# --
|
118
114
|
# The directory you store your image data in (by default `copy/`.)
|
119
|
-
#
|
120
|
-
|
115
|
+
# --
|
121
116
|
def copy_dir(*path)
|
122
|
-
dir =
|
123
|
-
root.join(
|
124
|
-
*path
|
117
|
+
dir = meta["copy_dir"]
|
118
|
+
root.join(
|
119
|
+
dir, *path
|
125
120
|
)
|
126
121
|
end
|
127
122
|
|
128
|
-
#
|
123
|
+
# --
|
129
124
|
|
130
125
|
def to_tag_h
|
131
126
|
{
|
@@ -135,91 +130,100 @@ module Docker
|
|
135
130
|
}
|
136
131
|
end
|
137
132
|
|
138
|
-
#
|
133
|
+
# --
|
139
134
|
|
140
135
|
def to_rootfs_h
|
141
136
|
{
|
142
137
|
"tag" => name,
|
143
|
-
"repo" => "#{
|
138
|
+
"repo" => "#{meta["local_prefix"]}/rootfs",
|
144
139
|
"force" => true
|
145
140
|
}
|
146
141
|
end
|
147
142
|
|
148
|
-
#
|
143
|
+
# --
|
149
144
|
|
150
145
|
def tmpdir(*args, root: nil)
|
151
146
|
args.unshift(user, name, tag)
|
152
|
-
Pathutil.tmpdir(
|
153
|
-
nil, root
|
147
|
+
Pathutil.tmpdir(
|
148
|
+
args, nil, root
|
154
149
|
)
|
155
150
|
end
|
156
151
|
|
157
|
-
#
|
152
|
+
# --
|
158
153
|
|
159
154
|
def tmpfile(*args, root: nil)
|
160
155
|
args.unshift(user, name, tag)
|
161
|
-
Pathutil.tmpfile(
|
162
|
-
nil, root
|
156
|
+
Pathutil.tmpfile(
|
157
|
+
args, nil, root
|
163
158
|
)
|
164
159
|
end
|
165
160
|
|
166
|
-
#
|
161
|
+
# --
|
167
162
|
# If a tag was given then it returns [self] and if a tag was not sent
|
168
163
|
# it then goes on to detect the type and split itself accordingly
|
169
164
|
# returning multiple, AKA all repos that should be built.
|
170
|
-
#
|
171
|
-
|
165
|
+
# --
|
172
166
|
def to_repos
|
173
|
-
|
174
|
-
|
175
|
-
|
167
|
+
if Template.project?
|
168
|
+
then Set.new([
|
169
|
+
self
|
170
|
+
])
|
171
|
+
|
176
172
|
else
|
177
|
-
|
178
|
-
|
179
|
-
set << self
|
180
|
-
|
181
|
-
|
173
|
+
set = Set.new
|
174
|
+
if @base_meta.key?("tag")
|
175
|
+
set << self
|
176
|
+
else
|
177
|
+
tags.each do |tag|
|
178
|
+
hash = Parser.from_tag_to_repo_hash(tag)
|
179
|
+
hash = to_h.merge(hash)
|
180
|
+
set << self.class.new(
|
181
|
+
hash, @cli_opts
|
182
|
+
)
|
183
|
+
end
|
182
184
|
end
|
185
|
+
|
186
|
+
set
|
183
187
|
end
|
184
|
-
set
|
185
188
|
end
|
186
189
|
|
187
|
-
#
|
190
|
+
# --
|
188
191
|
|
189
|
-
def
|
190
|
-
return @
|
191
|
-
|
192
|
+
def meta
|
193
|
+
return @meta ||= begin
|
194
|
+
Meta.new(
|
192
195
|
@base_meta
|
193
196
|
)
|
194
197
|
end
|
195
198
|
end
|
196
199
|
|
197
|
-
#
|
200
|
+
# --
|
198
201
|
|
199
202
|
def to_env(tar_gz: nil, copy_dir: nil)
|
200
|
-
hash =
|
201
|
-
|
203
|
+
hash = meta["env"] || { "all" => {}}
|
204
|
+
Meta.new(hash, :root => meta).merge({
|
202
205
|
"REPO" => name,
|
203
206
|
"TAR_GZ" => tar_gz,
|
204
|
-
"GROUP" =>
|
207
|
+
"GROUP" => meta.group,
|
208
|
+
"DEBUG" => meta.debug?? "true" : "",
|
205
209
|
"COPY_DIR" => copy_dir,
|
206
210
|
"BUILD_TYPE" => type,
|
207
211
|
"TAG" => tag
|
208
212
|
})
|
209
213
|
end
|
210
214
|
|
211
|
-
#
|
215
|
+
# --
|
212
216
|
|
213
217
|
rb_delegate :build, :to => :builder
|
214
|
-
rb_delegate :alias?, :to => :
|
215
|
-
rb_delegate :complex_alias?, :to => :
|
216
|
-
rb_delegate :type, :to => :
|
217
|
-
rb_delegate :user, :to => :
|
218
|
-
rb_delegate :name, :to => :
|
219
|
-
rb_delegate :tag, :to => :
|
218
|
+
rb_delegate :alias?, :to => :meta
|
219
|
+
rb_delegate :complex_alias?, :to => :meta
|
220
|
+
rb_delegate :type, :to => :meta, :type => :hash
|
221
|
+
rb_delegate :user, :to => :meta, :type => :hash
|
222
|
+
rb_delegate :name, :to => :meta, :type => :hash
|
223
|
+
rb_delegate :tag, :to => :meta, :type => :hash
|
220
224
|
rb_delegate :to_h, :to => :@base_meta
|
221
|
-
rb_delegate :root, :to => :
|
222
|
-
rb_delegate :tags, :to => :
|
225
|
+
rb_delegate :root, :to => :meta
|
226
|
+
rb_delegate :tags, :to => :meta
|
223
227
|
rb_delegate :clean, {
|
224
228
|
:to => Cache, :alias_of => :cleanup, :args => %w(
|
225
229
|
self
|