Class: Docker::Template::Repo

Inherits:
Object
  • Object
show all
Extended by:
Routable, Forwardable
Defined in:
lib/docker/template/repo.rb

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.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
# File 'lib/docker/template/repo.rb', line 22

def initialize()
  raise ArgumentError, "Metadata not a hash" unless .is_a?(Hash)

   = .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

#builderObject



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

Returns:

  • (Boolean)


63
64
65
# File 'lib/docker/template/repo.rb', line 63

def building_all?
  !.key?("tag")
end

#copy_dir(*path) ⇒ Object



56
57
58
59
# File 'lib/docker/template/repo.rb', line 56

def copy_dir(*path)
  dir = ["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

#metadataObject



147
148
149
150
151
152
153
# File 'lib/docker/template/repo.rb', line 147

def 
   ||= begin
     = Template.repo_root_for(name)
     = Template.config.read_config_from()
    .new().merge()
  end
end

#rootObject



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

Returns:

  • (Boolean)


44
45
46
# File 'lib/docker/template/repo.rb', line 44

def syncable?
  ["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)
  ["env"].as_hash.merge({
    "REPO" => name,
    "NAME" => name,
    "TAR_GZ" => tar_gz,
    "TYPE" => ["tags"][tag],
    "VERSION" => ["version"].fallback,
    "PKGS" => ["pkgs"].as_string_set,
    "RELEASE" => ["release"].fallback,
    "BUILD_TYPE" => type,
    "COPY" => copy_dir,
    "TAR" => tar_gz,
    "TAG" => tag
  }).to_env
end

#to_reposObject

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_hObject



94
95
96
97
98
99
100
101
102
# File 'lib/docker/template/repo.rb', line 94

def to_rootfs_h
  prefix = ["local_prefix"]

  {
    "tag"   => name,
    "repo"  => "#{prefix}/rootfs",
    "force" => true
  }
end

#to_rootfs_sObject



69
70
71
72
# File 'lib/docker/template/repo.rb', line 69

def to_rootfs_s
  prefix = ["local_prefix"]
  "#{prefix}/rootfs:#{name}"
end

#to_sObject



50
51
52
# File 'lib/docker/template/repo.rb', line 50

def to_s
  "#{user}/#{name}:#{tag}"
end

#to_tag_hObject



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