lib/dockdev.rb in dockdev-0.4.0 vs lib/dockdev.rb in dockdev-0.4.1
- old
+ new
@@ -13,10 +13,12 @@
require_relative 'dockdev/image'
require_relative 'dockdev/container'
require_relative 'dockdev/dockdev_config'
+require_relative 'dockdev/user_config'
+
module Dockdev
include TR::CondUtils
class Error < StandardError; end
# Your code goes here...
@@ -24,14 +26,16 @@
# main entry points to start docker
def self.with_running_container(contName, opts = {})
pmt = TTY::Prompt.new
root = opts[:root]
- cmd = opts[:command]
+ cmd = opts[:command] || ""
ddConf = load_config(root)
+ user_config = opts[:user_config]
+
cont = Container.new(contName)
if cont.has_container?
logger.debug "Container '#{contName}' already exist. Just run the container"
if cont.running?
@@ -49,10 +53,14 @@
wss = Workspace.new(ws)
# root directory is mounted by default
ddConf.add_mount(root, File.join(ddConf.workdir,File.basename(root)))
+ if user_config.has_key?(:network)
+ ddConf.network = user_config.network
+ end
+
ctx = Dockdev::Context::ContextManager.instance.get_context(root)
logger.debug("Found context : #{ctx}")
ctx.each do |name, cctx|
@@ -107,9 +115,23 @@
# image already exist!
# Since reach here means container doesn't exist yet.
# Proceed to create container
param = { command: cmd, mounts: ddConf.mounts, ports: ddConf.ports }
+ if not_empty?(ddConf.network)
+ cmd_fact = Docker::Cli::CommandFactory.new
+ res = cmd_fact.create_network(ddConf.network).run
+ if res.success? and not res.is_out_stream_empty?
+ param[:network] = ddConf.network
+ else
+ err = res.err_stream
+ if err =~ /already exist/
+ param[:network] = ddConf.network
+ else
+ raise Error, "\n Failed to create network. Error was : #{res.err_stream}\n"
+ end
+ end
+ end
img.new_container(cont.name, param)
#if img.has_image?
#
# # has image but no container