Class: Panoramix::Plugin::DockerImageBase

Inherits:
Base
  • Object
show all
Defined in:
lib/panoramix/plugin/docker_image_base.rb

Direct Known Subclasses

DockerBuild, DockerImage

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#needed?, #run_default, #shell

Constructor Details

#initialize(dst, host) ⇒ DockerImageBase

Returns a new instance of DockerImageBase.



13
14
15
16
17
18
# File 'lib/panoramix/plugin/docker_image_base.rb', line 13

def initialize(dst, host)
  @dst = dst
  @tag = "latest"
  @env = Hash.new
  @env["DOCKER_HOST"] = "tcp://#{host}" if host
end

Instance Attribute Details

#dstObject (readonly)

Returns the value of attribute dst.



9
10
11
# File 'lib/panoramix/plugin/docker_image_base.rb', line 9

def dst
  @dst
end

#envObject (readonly)

Returns the value of attribute env.



11
12
13
# File 'lib/panoramix/plugin/docker_image_base.rb', line 11

def env
  @env
end

#tagObject (readonly)

Returns the value of attribute tag.



10
11
12
# File 'lib/panoramix/plugin/docker_image_base.rb', line 10

def tag
  @tag
end

Instance Method Details

#clobberObject

Action clobber for this task



47
48
49
50
51
52
53
# File 'lib/panoramix/plugin/docker_image_base.rb', line 47

def clobber
  info = created?
  if info
    id = info.split(" ")[0]
    shell("docker rmi -f #{id}", false, @env)
  end 
end

#created?Boolean

Has this image already been created

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/panoramix/plugin/docker_image_base.rb', line 34

def created?
  return @created if @created
  
  info = shell("docker images", true, @env)[:out]

  images_list = info.split("\n")
  images_list.shift
  image_info = images_list.select {|img| img.match(/#{@dst}\s+#{@tag}/) }

  @created = info = info.empty? ? nil: image_info[0]
end

#ps(message) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/panoramix/plugin/docker_image_base.rb', line 55

def ps(message)
  puts "#{message}: #{@dst}"
  info = created?
  if info
    puts "Timestamp: #{timestamp}"
    puts info
  else
    puts "Timestamp: Not created"
  end
  puts
end

#timestampObject

Return timestamp of the image



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/panoramix/plugin/docker_image_base.rb', line 21

def timestamp
  info =  created?
  if info
    # Get image timestamp
    id = info.split(" ")[0]
    time = shell("docker inspect -f {{.Created}} #{id}", true, @env)[:out]
    return Time.parse(time)
  else
    return Time.at 0
  end
end