Sha256: b61ba66a0af8ce1819544e610d114318325640fa1e02196e83a9005d16bdb2b6

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 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
      }
      res = @cmd_fact.build_image(@image_name, optss).run
      if res.success? 
        new_container(opts[:container_name], opts)
      else
        raise Error, "Error triggered during find existing image : #{res.err_stream}"
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dockdev-0.1.0 lib/dockdev/image.rb