Class: Docker::Template::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/template/common.rb

Direct Known Subclasses

Rootfs, Scratch, Simple

Constant Summary collapse

CopyMethods =
[
:setup_context, :copy_global,
:copy_all, :copy_type, :copy_tag, :build_context,
:verify_context].freeze

Instance Method Summary collapse

Instance Method Details

#aliased?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/docker/template/common.rb', line 24

def aliased?
  @repo.tag != @repo.aliased && !rootfs?
end

#buildObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/docker/template/common.rb', line 56

def build
  return Alias.new(self).build if aliased?

  Ansi.clear
  Util.notify_build(@repo, rootfs: rootfs?)
  copy_build_and_verify
  chdir_build
rescue SystemExit => exit_
  unlink img: true
  raise exit_
ensure
  if rootfs?
    unlink img: false else unlink
  end
end

#chdir_buildObject



74
75
76
77
78
79
80
# File 'lib/docker/template/common.rb', line 74

def chdir_build
  Dir.chdir(@context) do
    @img = Docker::Image.build_from_dir(".", &Stream.new.method(:log))
    @img.tag rootfs?? @repo.to_rootfs_h : @repo.to_tag_h
    push
  end
end

#parent_imgObject



45
46
47
48
49
50
51
52
# File 'lib/docker/template/common.rb', line 45

def parent_img
  return false unless aliased?
  @parent_img ||= Docker::Image.get(parent_repo.to_s)
rescue Docker::Error::NotFoundError
  if aliased?
    nil
  end
end

#parent_repoObject



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

def parent_repo
  return false unless aliased?
  @parent_repo ||= begin
    Repo.new(@repo.to_h.merge("tag" => @repo.aliased))
  end
end

#pushObject



13
14
15
16
17
18
19
20
# File 'lib/docker/template/common.rb', line 13

def push
  return if rootfs? || !Interface.push?

  Auth.auth!
  img = @img || Docker::Image.get(@repo.to_s)
  logger = Stream.new.method(:log)
  img.push(&logger)
end

#rootfs?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/docker/template/common.rb', line 30

def rootfs?
  false
end