Sha256: b783d8a50406add627f83308851b64105fa72681dba55891fb0f268afd331cdd

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

require 'docker/cli'

module Dockdev
  class Image
    include TR::CondUtils

    def initialize(name)
      @image_name = name
      @cmd_fact = Docker::Cli::CommandFactory.new
    end

    def has_image?
      res = @cmd_fact.find_image(@image_name).run
      if res.success?
        not res.is_out_stream_empty?
      else
        raise Error, "Error triggered during find existing image : #{res.err_stream}"
      end
    end

    def new_container(cont_name, opts = {})
      optss = {
        interactive: true,
        tty: true,
        container_name: cont_name
      }
      optss.merge!(opts)
      @cmd_fact.create_container_from_image(@image_name, optss).run
    end

    def build(dockerfile, opts = {})
      optss = {  
        context_root: opts[:root],
        dockerfile: dockerfile
      }
      optss.merge!(opts)
      @cmd_fact.build_image(@image_name, optss).run
    end

    def destroy
      res = @cmd_fact.delete_image(@image_name).run
      if res.success?
        not res.is_out_stream_empty?
      else
        raise Error, "Error triggered during deleting image : #{res.err_stream}"
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dockdev-0.4.0 lib/dockdev/image.rb
dockdev-0.3.6 lib/dockdev/image.rb
dockdev-0.3.5 lib/dockdev/image.rb
dockdev-0.3.4 lib/dockdev/image.rb
dockdev-0.3.3 lib/dockdev/image.rb
dockdev-0.3.2 lib/dockdev/image.rb
dockdev-0.3.1 lib/dockdev/image.rb
dockdev-0.3.0 lib/dockdev/image.rb
dockdev-0.2.0 lib/dockdev/image.rb