Module: Dockdev

Includes:
TR::CondUtils
Defined in:
lib/dockdev.rb,
lib/dockdev/image.rb,
lib/dockdev/context.rb,
lib/dockdev/version.rb,
lib/dockdev/container.rb,
lib/dockdev/workspace.rb,
lib/dockdev/context/rubygems.rb

Defined Under Namespace

Modules: Context Classes: Container, Error, Image, Workspace

Constant Summary collapse

VERSION =
"0.3.4"

Class Method Summary collapse

Class Method Details

.destroy(contName, opts = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dockdev.rb', line 63

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

  cont = Container.new(contName)
  if cont.has_container?
    cont.stop if cont.running?
    cont.destroy
  end

  img = Image.new(contName)
  if img.has_image?
    img.destroy
  end

end

.logger(tag = nil, &block) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dockdev.rb', line 78

def self.logger(tag = nil, &block)
  if @_logger.nil?
    @_logger = TeLogger::Tlogger.new(STDOUT)
  end

  if block
    if not_empty?(tag)
      @_logger.with_tag(tag, &block)
    else
      @_logger.with_tag(@_logger.tag, &block)
    end
  else
    if is_empty?(tag)
      @_logger.tag = :dockdev
      @_logger
    else
      # no block but tag is given? hmm
      @_logger.tag = tag
      @_logger
    end
  end
end

.with_running_container(contName, opts = {}) ⇒ Object

Your code goes here…



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dockdev.rb', line 20

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

  root = opts[:root]
  cmd = opts[:command]

  ctx = Dockdev::Context::ContextManager.instance.get_context(root)
  logger.debug("Found context : #{ctx}")

  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] || root
    wss = Workspace.new(ws)
    if img.has_image?
      mount = { root => File.join("/opt",File.basename(root)) }
      if not ctx.nil?
        mount = ctx.process_mount(mount)
        logger.debug "Mount points by context : #{mount}"
      end

      img.new_container(cont.name, command: cmd, mounts: mount)
    elsif wss.has_dockerfile?
      img.build(wss.dockerfile)
      
      mount = { root => File.join("/opt",File.basename(root)) }
      if not ctx.nil?
        mount = ctx.process_mount(mount)
        logger.debug "Mount points by context : #{mount}"
      end

      img.new_container(cont.name, command: cmd, mounts: mount)
    else
      raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n".red
    end
  end
end