Sha256: 18afe50a3cf10c4627db9f3c2db49f64cbf2b5d3b45fd16be7a29dc3f95d7260

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require 'construi/container'

module Construi

  class Image
    private_class_method :new

    def initialize(image)
      @image = image.refresh!
    end

    def id
      @image.id
    end

    def delete
      @image.delete
    end

    def tagged?
      @image.info['RepoTags'] != '<none>:<none>'
    end

    def run(cmd)
      Container.run(self, cmd)
    end

    def self.create(image)
      wrap Docker::Image.create('fromImage' => image)
    end

    def self.wrap(image)
      new image
    end

    def self.use(image)
      begin
        i = create(image)
        yield i
      ensure
        i.delete unless i.tagged?
      end
    end
  end

  class IntermediateImage
    private_class_method :new

    def initialize(image)
      @image = image
    end

    def run(cmd)
      map { |i| i.run(cmd) }
    end

    def map
      update(yield @image)
    end

    def update(image)
      @image.delete unless @image.tagged?
      @image = image
    end

    def delete
      @image.delete unless @image.tagged?
    end

    def self.seed(image)
      new image
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
construi-0.5.0 lib/construi/image.rb
construi-0.4.0 lib/construi/image.rb
construi-0.2.0 lib/construi/image.rb
construi-0.1.0 lib/construi/image.rb