class Panoramix::Plugin::DockerUp
Attributes
dst[R]
env[R]
src[R]
Public Class Methods
new(dst, src, env, host)
click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 15 def initialize(dst, src, env, host) @dst = dst @src = src @env = env @env = parse_env @env.keys @env["DOCKER_HOST"] = "tcp://#{host}" unless host.nil? end
Public Instance Methods
clobber()
click to toggle source
Action clobber for this task
# File lib/panoramix/plugin/docker_up.rb, line 48 def clobber shell("docker-compose -p #{@dst} -f #{@src} kill; docker-compose -p #{@dst} -f #{@src} rm -v --force", false, @env) if created? end
created?()
click to toggle source
Has this image already been created
# File lib/panoramix/plugin/docker_up.rb, line 37 def created? info = shell("docker-compose -p #{@dst} -f #{@src} ps -q", true, @env)[:out] @created = info = info.empty? ? nil: info end
id()
click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 81 def id info = created? if info containers = info.split("\n") puts containers end end
logs()
click to toggle source
Print docker-compose project logs
# File lib/panoramix/plugin/docker_up.rb, line 90 def logs info = created? if info containers = info.split("\n") colors = ['red', 'green','yellow','blue','magenta','cyan'] containers.each do |c| out = shell("docker logs #{c} | tail -n 200", true, @env) name = shell("docker inspect -f {{.Name}} #{c}", true, @env)[:out] name.gsub!("\n", "") name.gsub!("/", "") name = eval %& "#{name} >".#{colors.first}& colors.push colors.shift out[:out].split("\n").each{ |out| puts name + out } out[:err].split("\n").each{ |out| puts name + out } end end end
needed?(timestamps)
click to toggle source
When this instance needs to be executed
# File lib/panoramix/plugin/docker_up.rb, line 53 def needed? timestamps this_time = timestamp timestamps.any? { |t| t > this_time } end
ps()
click to toggle source
Print docker-compose ps
# File lib/panoramix/plugin/docker_up.rb, line 109 def ps puts "Service: #{@dst}" if created? puts "Timestamp: #{timestamp}" info = shell("docker-compose -p #{@dst} -f #{@src} ps", true, @env)[:out] puts info else puts "Timestamp: Not created" end puts end
rm()
click to toggle source
Action rm for this task
# File lib/panoramix/plugin/docker_up.rb, line 43 def rm clobber end
run_default()
click to toggle source
Default action for this task
# File lib/panoramix/plugin/docker_up.rb, line 59 def run_default # Raise an exception if already has been created if created? message = I18n.t('errors.docker_up.cluster_deployed', {:id => @dst}) raise(DockerUpExceptionError, message) end # Run docker-compose up otherwise shell("docker-compose -p #{dst} -f #{@src} up -d", false, @env) end
start()
click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 75 def start if created? shell("docker-compose -p #{dst} -f #{@src} up -d", false, @env) end end
stop()
click to toggle source
# File lib/panoramix/plugin/docker_up.rb, line 69 def stop if created? shell("docker-compose -p #{dst} -f #{@src} stop", false, @env) end end
timestamp()
click to toggle source
Return current timestamp for the container
# File lib/panoramix/plugin/docker_up.rb, line 25 def timestamp info = created? if info id = info.split("\n").first.strip time = shell("docker inspect -f {{.Created}} #{id}", true, @env)[:out] return Time.parse(time) else Time.at 0 end end