Class: Docker::Template::Repo
Overview
-
A repo is not an image but a parent name w/ a tag.
-
An image is the final result of a build on a repo, and is associated.
-
Think of an image as the binary of the source in the repo.
Instance Method Summary
collapse
Methods included from Routable
route_to_hash, route_to_ivar
Constructor Details
#initialize(base_metadata) ⇒ Repo
Returns a new instance of Repo.
22
23
24
25
26
27
28
29
|
# File 'lib/docker/template/repo.rb', line 22
def initialize(base_metadata)
raise ArgumentError, "Metadata not a hash" unless base_metadata.is_a?(Hash)
@base_metadata = base_metadata.freeze
@sync_allowed = type == "simple" ? true : false
raise Error::InvalidRepoType, type unless Template.config.build_types.include?(type)
raise Error::RepoNotFound, name unless root.exist?
end
|
Instance Method Details
31
32
33
34
|
# File 'lib/docker/template/repo.rb', line 31
def builder
const = Template.const_get(type.capitalize)
const.new(self)
end
|
#building_all? ⇒ Boolean
63
64
65
|
# File 'lib/docker/template/repo.rb', line 63
def building_all?
!@base_metadata.key?("tag")
end
|
#copy_dir(*path) ⇒ Object
56
57
58
59
|
# File 'lib/docker/template/repo.rb', line 56
def copy_dir(*path)
dir = metadata["copy_dir"]
root.join(dir, *path)
end
|
#disable_sync! ⇒ Object
38
39
40
|
# File 'lib/docker/template/repo.rb', line 38
def disable_sync!
@sync_allowed = false
end
|
147
148
149
150
151
152
153
|
# File 'lib/docker/template/repo.rb', line 147
def metadata
@metadata ||= begin
metadata = Template.repo_root_for(name)
metadata = Template.config.read_config_from(metadata)
Metadata.new(metadata).merge(@base_metadata)
end
end
|
76
77
78
79
80
|
# File 'lib/docker/template/repo.rb', line 76
def root
@root ||= begin
Template.repo_root_for(name)
end
end
|
#syncable? ⇒ Boolean
44
45
46
|
# File 'lib/docker/template/repo.rb', line 44
def syncable?
metadata["dockerhub_copy"] && @sync_allowed
end
|
#tmpdir(*prefixes, root: nil) ⇒ Object
106
107
108
109
110
|
# File 'lib/docker/template/repo.rb', line 106
def tmpdir(*prefixes, root: nil)
prefixes = [user, name, tag] + prefixes
args = ["#{prefixes.join("-")}-", root].delete_if(&:nil?)
Pathname.new(Dir.mktmpdir(*args))
end
|
#tmpfile(*prefixes, root: nil) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/docker/template/repo.rb', line 114
def tmpfile(*prefixes, root: nil)
prefixes = [user, name, tag] + prefixes
ext = prefixes.pop if prefixes.last =~ /\A\./
prefixes = ["#{prefixes.join("-")}-"]
prefixes = ext ? prefixes.push(ext) : prefixes.first
args = [prefixes, root].delete_if(&:nil?)
Pathname.new(Tempfile.new(*args))
end
|
#to_env_hash(tar_gz: nil, copy_dir: nil) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/docker/template/repo.rb', line 157
def to_env_hash(tar_gz: nil, copy_dir: nil)
metadata["env"].as_hash.merge({
"REPO" => name,
"NAME" => name,
"TAR_GZ" => tar_gz,
"TYPE" => metadata["tags"][tag],
"VERSION" => metadata["version"].fallback,
"PKGS" => metadata["pkgs"].as_string_set,
"RELEASE" => metadata["release"].fallback,
"BUILD_TYPE" => type,
"COPY" => copy_dir,
"TAR" => tar_gz,
"TAG" => tag
}).to_env
end
|
If a tag was given then it returns [self] and if a tag was not sent it then goes on to detect the type and split itself accordingly returning multiple AKA all repos to be built.
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/docker/template/repo.rb', line 127
def to_repos
if building_all?
set = Set.new
base = to_h
tags.each do |tag|
base = base.merge("tag" => tag)
set << self.class.new(base)
end
set
else
Set.new([
self
])
end
end
|
#to_rootfs_h ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/docker/template/repo.rb', line 94
def to_rootfs_h
prefix = metadata["local_prefix"]
{
"tag" => name,
"repo" => "#{prefix}/rootfs",
"force" => true
}
end
|
#to_rootfs_s ⇒ Object
69
70
71
72
|
# File 'lib/docker/template/repo.rb', line 69
def to_rootfs_s
prefix = metadata["local_prefix"]
"#{prefix}/rootfs:#{name}"
end
|
50
51
52
|
# File 'lib/docker/template/repo.rb', line 50
def to_s
"#{user}/#{name}:#{tag}"
end
|
84
85
86
87
88
89
90
|
# File 'lib/docker/template/repo.rb', line 84
def to_tag_h
{
"tag" => tag,
"repo" => "#{user}/#{name}",
"force" => true
}
end
|