docker-template 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +30 -4
- data/LICENSE +1 -1
- data/README.md +79 -14
- data/Rakefile +115 -38
- data/bin/docker-template +24 -10
- data/comp/bin +9 -0
- data/comp/list +83 -0
- data/comp/list.pak +0 -0
- data/lib/docker/template.rb +47 -61
- data/lib/docker/template/builder.rb +302 -0
- data/lib/docker/template/cache.rb +71 -0
- data/lib/docker/template/cli.rb +125 -0
- data/lib/docker/template/error.rb +120 -11
- data/lib/docker/template/logger.rb +128 -0
- data/lib/docker/template/metadata.rb +566 -103
- data/lib/docker/template/normal.rb +46 -0
- data/lib/docker/template/notify.rb +44 -0
- data/lib/docker/template/parser.rb +48 -38
- data/lib/docker/template/repo.rb +131 -97
- data/lib/docker/template/rootfs.rb +51 -41
- data/lib/docker/template/scratch.rb +96 -66
- data/lib/docker/template/version.rb +4 -2
- data/lib/erb/context.rb +29 -0
- data/shas.yml +11 -0
- data/templates/rootfs.erb +5 -0
- data/templates/rootfs/alpine.erb +71 -0
- data/templates/rootfs/ubuntu.erb +76 -0
- data/{lib/docker/template/templates → templates}/scratch.erb +0 -1
- metadata +64 -50
- data/lib/docker/template/alias.rb +0 -28
- data/lib/docker/template/ansi.rb +0 -85
- data/lib/docker/template/auth.rb +0 -25
- data/lib/docker/template/common.rb +0 -130
- data/lib/docker/template/config.rb +0 -80
- data/lib/docker/template/error/bad_exit_status.rb +0 -17
- data/lib/docker/template/error/bad_repo_name.rb +0 -15
- data/lib/docker/template/error/invalid_repo_type.rb +0 -16
- data/lib/docker/template/error/invalid_targz_file.rb +0 -15
- data/lib/docker/template/error/no_rootfs_copy_dir.rb +0 -15
- data/lib/docker/template/error/no_rootfs_mkimg.rb +0 -15
- data/lib/docker/template/error/no_setup_context_found.rb +0 -15
- data/lib/docker/template/error/not_implemented.rb +0 -15
- data/lib/docker/template/error/repo_not_found.rb +0 -16
- data/lib/docker/template/interface.rb +0 -118
- data/lib/docker/template/patches.rb +0 -9
- data/lib/docker/template/patches/array.rb +0 -11
- data/lib/docker/template/patches/hash.rb +0 -71
- data/lib/docker/template/patches/object.rb +0 -9
- data/lib/docker/template/patches/pathname.rb +0 -46
- data/lib/docker/template/patches/string.rb +0 -9
- data/lib/docker/template/routable.rb +0 -28
- data/lib/docker/template/simple.rb +0 -49
- data/lib/docker/template/stream.rb +0 -63
- data/lib/docker/template/templates/rootfs.erb +0 -8
- data/lib/docker/template/util.rb +0 -54
- data/lib/docker/template/util/copy.rb +0 -77
- data/lib/docker/template/util/data.rb +0 -26
@@ -1,46 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
class Pathname
|
6
|
-
def in_path?(path)
|
7
|
-
path_str = path.is_a?(self.class) ? path.expanded_realpath.to_s : path.to_s
|
8
|
-
expanded_realpath.to_s.start_with?(path_str)
|
9
|
-
end
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
def write(data)
|
14
|
-
File.write(to_s, data)
|
15
|
-
end
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
def expanded_path
|
20
|
-
@expanded_path ||= begin
|
21
|
-
expand_path Dir.pwd
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
def expanded_realpath
|
28
|
-
@expanded_real_path ||= begin
|
29
|
-
expanded_path.realpath
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
def all_children
|
36
|
-
glob "**/*"
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
|
41
|
-
def glob(*args)
|
42
|
-
Dir.glob(join(*args)).map do |path|
|
43
|
-
self.class.new(path)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Routable
|
8
|
-
def route_to_hash(methods, hash, alt_key = nil)
|
9
|
-
methods = [methods] unless methods.is_a?(Array)
|
10
|
-
methods.each do |method|
|
11
|
-
class_eval <<-STR, __FILE__, __LINE__
|
12
|
-
def #{method}
|
13
|
-
#{alt_key ? "#{hash}['#{alt_key}']" : "#{hash}['#{method}']"}
|
14
|
-
end
|
15
|
-
STR
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def route_to_ivar(method, var, bool: false, revbool: false)
|
20
|
-
class_eval <<-STR, __FILE__, __LINE__
|
21
|
-
def #{method}#{"?" if bool || revbool}
|
22
|
-
#{revbool ? "!!!" : "!!" if bool || revbool}#{var}
|
23
|
-
end
|
24
|
-
STR
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
class Simple < Common
|
8
|
-
attr_reader :repo
|
9
|
-
def initialize(repo)
|
10
|
-
@repo = repo
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
def sync
|
16
|
-
copy_build_and_verify unless @context
|
17
|
-
Util.create_dockerhub_context(self, @context)
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
def unlink(img: false, sync: true)
|
23
|
-
@img.delete "force" => true if @img && img
|
24
|
-
@context.rmtree if @context && @context.directory?
|
25
|
-
self.sync if sync && @repo.syncable?
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
def setup_context
|
31
|
-
@context = @repo.tmpdir
|
32
|
-
@copy = @context.join("copy")
|
33
|
-
copy_dockerfile
|
34
|
-
@copy.mkdir
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
private
|
40
|
-
def copy_dockerfile
|
41
|
-
dockerfile = @repo.root.join("Dockerfile").read
|
42
|
-
data = Util::Data.new(:metadata => @repo.metadata)
|
43
|
-
data = ERB.new(dockerfile).result(data._binding)
|
44
|
-
context = @context.join("Dockerfile")
|
45
|
-
context.write(data)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
class Stream
|
8
|
-
def initialize
|
9
|
-
@lines = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
def log(part)
|
15
|
-
stream = JSON.parse(part)
|
16
|
-
return progress_bar(stream) if stream.any_keys?("progress", "progressDetail")
|
17
|
-
return $stdout.puts stream["status"] || stream["stream"] if stream.any_keys?("status", "stream")
|
18
|
-
return progress_error(stream) if stream.any_keys?("errorDetail", "error")
|
19
|
-
|
20
|
-
warn Ansi.red("Unhandled stream message")
|
21
|
-
$stderr.puts Ansi.red("Please file a bug ticket.")
|
22
|
-
$stdout.puts part
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
def progress_error(stream)
|
28
|
-
abort Ansi.red((stream["error"] || stream["errorDetail"]["message"]).capitalize)
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
private
|
34
|
-
def progress_bar(stream)
|
35
|
-
id = stream["id"]
|
36
|
-
unless id
|
37
|
-
return
|
38
|
-
end
|
39
|
-
|
40
|
-
before, diff = progress_diff(id)
|
41
|
-
$stdout.print before if before
|
42
|
-
str = stream["progress"] || stream["status"]
|
43
|
-
str = "#{id}: #{str}\r"
|
44
|
-
|
45
|
-
$stdout.print(Ansi.jump(str, both: diff))
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
private
|
51
|
-
def progress_diff(id)
|
52
|
-
if @lines.key?(id)
|
53
|
-
return nil, @lines.size - @lines[id]
|
54
|
-
end
|
55
|
-
|
56
|
-
@lines[id] = @lines.size
|
57
|
-
before = "\n" unless @lines.size == 1
|
58
|
-
# rubocop:disable RedundantReturn
|
59
|
-
return before, 0
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/docker/template/util.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Util
|
8
|
-
module_function
|
9
|
-
|
10
|
-
autoload :Copy, "docker/template/util/copy"
|
11
|
-
autoload :Data, "docker/template/util/data"
|
12
|
-
|
13
|
-
def notify_alias(aliased)
|
14
|
-
repo = aliased.repo
|
15
|
-
parent_repo = aliased.parent_repo
|
16
|
-
$stdout.puts Ansi.green("Aliasing #{repo} -> #{parent_repo}")
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
def notify_build(repo, rootfs: false)
|
22
|
-
img = rootfs ? repo.to_rootfs_s : repo.to_s
|
23
|
-
$stdout.puts Ansi.green("Building: #{img}")
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
|
28
|
-
def create_dockerhub_context(builder, context)
|
29
|
-
dir = builder.repo.root.join("tags", builder.repo.tag)
|
30
|
-
context = get_context(builder, context)
|
31
|
-
FileUtils.mkdir_p dir
|
32
|
-
|
33
|
-
$stdout.puts Ansi.yellow("Copying context for #{builder.repo}")
|
34
|
-
Util::Copy.file(readme_file(builder), dir)
|
35
|
-
Util::Copy.directory(context, dir)
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
def get_context(builder, context)
|
41
|
-
return context unless builder.aliased?
|
42
|
-
builder.repo.root.join("tags", builder.repo.aliased)
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
|
47
|
-
def readme_file(builder)
|
48
|
-
builder.repo.root.children.find do |val|
|
49
|
-
val.to_s =~ /readme/i
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Util
|
8
|
-
class Copy
|
9
|
-
def initialize(from, to)
|
10
|
-
@root = Template.root.realpath
|
11
|
-
@repos_root = Template.repo_is_root?? Template.root.realpath : Template.repos_root.realpath
|
12
|
-
@from = from.to_pathname
|
13
|
-
@to = to.to_pathname
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
def self.directory(from, to)
|
19
|
-
if from && to && File.exist?(from)
|
20
|
-
new(from, to).directory
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Copy a directory checking for symlinks and resolving them (only
|
25
|
-
# at the top level) if they are in the repos root, the root or the from
|
26
|
-
# path. The reason we check all three is because repos might be a
|
27
|
-
# symlink that resolves out of path so we need to allow symlinks
|
28
|
-
# from it. The same for the copy folder.
|
29
|
-
|
30
|
-
def directory
|
31
|
-
FileUtils.cp_r(@from.children, @to, :dereference_root => false)
|
32
|
-
@from.all_children.select(&:symlink?).each do |path|
|
33
|
-
path = @to.join(path.relative_path_from(@from))
|
34
|
-
resolved = path.realpath
|
35
|
-
|
36
|
-
unless in_path?(resolved)
|
37
|
-
raise Errno::EPERM, "#{path} not in #{@root}"
|
38
|
-
end
|
39
|
-
|
40
|
-
FileUtils.rm_r(path)
|
41
|
-
FileUtils.cp_r(resolved, path, :dereference_root => false)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
|
47
|
-
def self.file(from, to)
|
48
|
-
if to && from && File.exist?(from)
|
49
|
-
new(from, to).file
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
def file
|
56
|
-
return FileUtils.cp(@from, @to) unless @from.symlink?
|
57
|
-
|
58
|
-
resolved = @from.realpath
|
59
|
-
allowed = resolved.in_path?(@root)
|
60
|
-
raise Errno::EPERM, "#{resolved} not in #{@root}." unless allowed
|
61
|
-
FileUtils.cp(resolved, @to)
|
62
|
-
end
|
63
|
-
|
64
|
-
# Check to see if the path falls within the users roots, while
|
65
|
-
# getting the real path of the from root just incase it, itself is
|
66
|
-
# a symlink, we don't want it to fail because of that.
|
67
|
-
|
68
|
-
private
|
69
|
-
def in_path?(resolved)
|
70
|
-
resolved.in_path?(@repos_root) || \
|
71
|
-
resolved.in_path?(@from.realpath) || \
|
72
|
-
resolved.in_path?(@root)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Util
|
8
|
-
|
9
|
-
# Provides a way to encapsulate data for ERB processing so that we
|
10
|
-
# don't get full unfettered access to the entire binding from within
|
11
|
-
# our ERB processing context. Nobody wants that.
|
12
|
-
|
13
|
-
class Data
|
14
|
-
def initialize(vars)
|
15
|
-
vars.each do |key, val|
|
16
|
-
instance_variable_set("@#{key}", val)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def _binding
|
21
|
-
binding
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|