Class: Docker::Template::Repo

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

Instance Method Summary collapse

Constructor Details

#initialize(*hashes) ⇒ Repo



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/docker/template/repo.rb', line 12

def initialize(*hashes)
  @base_meta = hashes.compact
  @base_meta = @base_meta.reduce(:deep_merge)
  @base_meta.freeze

  unless root.exist?
    raise(
      Error::RepoNotFound, name
    )
  end
end

Instance Method Details

#aliasedObject

– Pulls out the repo this repo is aliasing it, this happens when you when you set the tag in the “alias” section of your ‘opts.yml`. –



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/docker/template/repo.rb', line 61

def aliased
  full = Parser.full_name?(
    meta.aliased_tag
  )

  if alias? && full
    self.class.new(to_h.merge(Parser.to_repo_hash(
      meta.aliased_tag
    )))

  elsif alias?
    self.class.new(to_h.merge({
      "tag" => meta.aliased_tag
    }))
  end

rescue Error::RepoNotFound => e
  unless full
    raise e
  end
end

#buildable?Boolean

Returns:

  • (Boolean)


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

def buildable?
  meta.build? && !meta["push_only"] && !meta["cache_only"] &&
    !meta[
      "clean_only"
    ]
end

#builderObject

– Initializes and returns the builder so that you can build the repo. –



86
87
88
89
90
91
92
# File 'lib/docker/template/repo.rb', line 86

def builder
  return @builder ||= begin
    Template::Builder.const_get(type.capitalize).new(
      self
    )
  end
end

#cache_dirObject

– The directory you wish to cache to (like ‘cache/`) or other. –



107
108
109
110
111
# File 'lib/docker/template/repo.rb', line 107

def cache_dir
  return root.join(
    meta["cache_dir"], tag
  )
end

#cacheable?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/docker/template/repo.rb', line 35

def cacheable?
  (meta["cache"] || meta["cache_only"]) &&
    !meta[
      "push_only"
    ]
end

#clean_cache?Boolean

Returns:

  • (Boolean)


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

def clean_cache?
  (meta["clean"] || meta["clean_only"])
end

#copy_dir(*path) ⇒ Object

– The directory you store your image data in (by default ‘copy/`.) –



116
117
118
119
120
121
# File 'lib/docker/template/repo.rb', line 116

def copy_dir(*path)
  dir = meta["copy_dir"]
  root.join(
    dir, *path
  )
end

#metaObject



192
193
194
195
196
197
198
# File 'lib/docker/template/repo.rb', line 192

def meta
  return @meta ||= begin
    Meta.new(
      @base_meta
    )
  end
end

#pushable?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/docker/template/repo.rb', line 26

def pushable?
  (meta["push"] || meta["push_only"]) &&
    !meta["cache_only"] && !meta[
      "clean_only"
    ]
end

#tmpdir(*args, root: Template.tmpdir) ⇒ Object



145
146
147
148
149
150
# File 'lib/docker/template/repo.rb', line 145

def tmpdir(*args, root: Template.tmpdir)
  args.unshift(user, name, tag)
  Pathutil.tmpdir(
    args, nil, root
  )
end

#tmpfile(*args, root: Template.tmpdir) ⇒ Object



154
155
156
157
158
159
# File 'lib/docker/template/repo.rb', line 154

def tmpfile(*args, root: Template.tmpdir)
  args.unshift(user, name, tag)
  Pathutil.tmpfile(
    args, nil, root
  )
end

#to_env(tar_gz: nil, copy_dir: nil) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/docker/template/repo.rb', line 202

def to_env(tar_gz: nil, copy_dir: nil)
  hash = meta["env"] || { "all" => {}}
  Meta.new(hash, :root => meta).merge({
    "REPO" => name,
    "TAR_GZ" => tar_gz,
    "GROUP" => meta.group,
    "DEBUG" => meta.debug?? "true" : "",
    "COPY_DIR" => copy_dir,
    "BUILD_TYPE" => type,
    "TAG" => tag
  })
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 that should be built. –



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/docker/template/repo.rb', line 166

def to_repos
  if Template.project?
    then Set.new([
      self
    ])

  else
    set = Set.new
    if @base_meta.key?("tag")
      set << self
    else
      tags.each do |tag|
        hash = Parser.from_tag_to_repo_hash(tag)
        hash = to_h.merge(hash)
        set << self.class.new(
          hash, @cli_opts
        )
      end
    end

    set
  end
end

#to_rootfs_hObject



135
136
137
138
139
140
141
# File 'lib/docker/template/repo.rb', line 135

def to_rootfs_h
  {
    "tag"   => name,
    "repo"  => "#{meta["local_prefix"]}/rootfs",
    "force" => true
  }
end

#to_s(rootfs: false) ⇒ Object

– Convert the repo into it’s final image name, however if you tell, us this is a rootfs build we will convert it into the rootfs name. –



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

def to_s(rootfs: false)
  prefix = meta["local_prefix"]
  return "#{user}/#{name}:#{tag}" unless rootfs
  "#{prefix}/rootfs:#{name}"
end

#to_tag_hObject



125
126
127
128
129
130
131
# File 'lib/docker/template/repo.rb', line 125

def to_tag_h
  {
    "tag"   => tag,
    "repo"  => "#{user}/#{name}",
    "force" => true
  }
end