class Drydocker::Monitor
Class to actually run the monitor and tests
Attributes
config[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/drydocker.rb, line 44 def initialize(config) @config = config end
Public Instance Methods
clean_containers()
click to toggle source
# File lib/drydocker.rb, line 58 def clean_containers fail "No docker found" if File.which("docker").nil? return unless system(docker_check_cmd) config.logger.debug("cleaning up previous containers") `docker kill #{config.name}` `docker rm #{config.name}` end
listen()
click to toggle source
# File lib/drydocker.rb, line 48 def listen run_or_start listener = Listen.to(config.path) do |modified, added, removed| config.logger.info("triggering change: #{modified + added + removed}") run_or_start end listener.start # not blocking config.logger.info("now listening") end
run_or_start()
click to toggle source
# File lib/drydocker.rb, line 66 def run_or_start system(docker_check_cmd) ? start : run end
Private Instance Methods
command()
click to toggle source
# File lib/drydocker.rb, line 109 def command config.command.nil? ? "" : config.command end
docker_check_cmd()
click to toggle source
# File lib/drydocker.rb, line 88 def docker_check_cmd "docker ps -a | grep #{config.name} >/dev/null" end
docker_cmd()
click to toggle source
# File lib/drydocker.rb, line 92 def docker_cmd "docker run -it -w /app" end
docker_run_cmd()
click to toggle source
# File lib/drydocker.rb, line 72 def docker_run_cmd %W( #{docker_cmd} #{env_flags} #{name_opt} #{path_opt} #{entrypoint_opt} #{config.image} sh -c #{command} ).reject { |x| x == "" }.join(" ") end
docker_start_cmd()
click to toggle source
# File lib/drydocker.rb, line 84 def docker_start_cmd "docker start -ai #{config.name}" end
entrypoint_opt()
click to toggle source
# File lib/drydocker.rb, line 100 def entrypoint_opt return "" if config.entrypoint.nil? "--entrypoint #{config.entrypoint.shellescape}" end
env_flags()
click to toggle source
# File lib/drydocker.rb, line 80 def env_flags "-e RUBYOPT -e SPEC_OPTS -e RSPEC_OPTS" end
name_opt()
click to toggle source
# File lib/drydocker.rb, line 96 def name_opt "--name #{config.name}" end
path_opt()
click to toggle source
# File lib/drydocker.rb, line 105 def path_opt "-v #{config.path}:/app" end
run()
click to toggle source
# File lib/drydocker.rb, line 113 def run config.logger.debug(docker_run_cmd) system(docker_run_cmd) end
start()
click to toggle source
# File lib/drydocker.rb, line 118 def start config.logger.debug(docker_start_cmd) system(docker_start_cmd) end