Sha256: 9fe07d17c497827e071a25c8b97688e88b8f496fc80cc07075e6f219e16812e5

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 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, env)
      Container.run(self, cmd, env)
    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, env)
      map { |i| i.run(cmd, env) }
    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

10 entries across 10 versions & 1 rubygems

Version Path
construi-0.30.0 lib/construi/image.rb
construi-0.29.0 lib/construi/image.rb
construi-0.27.0 lib/construi/image.rb
construi-0.25.0 lib/construi/image.rb
construi-0.23.0 lib/construi/image.rb
construi-0.21.0 lib/construi/image.rb
construi-0.19.0 lib/construi/image.rb
construi-0.8.0 lib/construi/image.rb
construi-0.7.0 lib/construi/image.rb
construi-0.6.0 lib/construi/image.rb