Sha256: 036f1e7dd8dce4e7214500aafb80075bd8436942119786058a30fb2c8219776b

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'teLogger'
require 'toolrack'
require 'docker/cli'

require_relative "dockdev/version"

require_relative 'dockdev/workspace'
require_relative 'dockdev/image'
require_relative 'dockdev/container'


module Dockdev
  class Error < StandardError; end
  # Your code goes here...

  def self.with_running_container(contName, opts = {})

    root = opts[:root]
    cmd = opts[:command]
    cont = Container.new(contName)
    if cont.has_container?
      if cont.running?
        cont.attach_and_exec(command: cmd)
      else
        cont.start_with_command(command: cmd)
      end
    else
      img = Image.new(contName)
      ws = opts[:workspace] || Dir.getwd
      wss = Workspace.new(ws)
      if img.has_image?
        img.new_container(cont.name, command: cmd)
      elsif wss.has_dockerfile?
        img.build(wss.dockerfile)
        img.new_container(cont.name, command: cmd)
      else
        raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dockdev-0.1.0 lib/dockdev.rb