Class: Panoramix::Plugin::DockerImageBase
- Defined in:
- lib/panoramix/plugin/docker_image_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
-
#clobber ⇒ Object
Action clobber for this task.
-
#created? ⇒ Boolean
Has this image already been created.
-
#initialize(dst, host) ⇒ DockerImageBase
constructor
A new instance of DockerImageBase.
- #ps(message) ⇒ Object
-
#timestamp ⇒ Object
Return timestamp of the image.
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
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
9 10 11 |
# File 'lib/panoramix/plugin/docker_image_base.rb', line 9 def dst @dst end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
11 12 13 |
# File 'lib/panoramix/plugin/docker_image_base.rb', line 11 def env @env end |
#tag ⇒ Object (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
#clobber ⇒ Object
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
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() puts "#{message}: #{@dst}" info = created? if info puts "Timestamp: #{timestamp}" puts info else puts "Timestamp: Not created" end puts end |
#timestamp ⇒ Object
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 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 |