class Panoramix::Plugin::DockerImageBase

Attributes

dst[R]
env[R]
tag[R]

Public Class Methods

new(dst, host) click to toggle source
# 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

Public Instance Methods

clobber() click to toggle source

Action clobber for this task

# 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?() click to toggle source

Has this image already been created

# 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) click to toggle source
# 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
timestamp() click to toggle source

Return timestamp of the image

# 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