Class: Panoramix::Plugin::DockerUp
- Defined in:
- lib/panoramix/plugin/docker_up.rb
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Instance Method Summary collapse
-
#clobber ⇒ Object
Action clobber for this task.
-
#created? ⇒ Boolean
Has this image already been created.
- #id ⇒ Object
-
#initialize(dst, src, env, host) ⇒ DockerUp
constructor
A new instance of DockerUp.
-
#logs ⇒ Object
Print docker-compose project logs.
-
#needed?(timestamps) ⇒ Boolean
When this instance needs to be executed.
-
#ps ⇒ Object
Print docker-compose ps.
-
#rm ⇒ Object
Action rm for this task.
-
#run_default ⇒ Object
Default action for this task.
- #start ⇒ Object
- #stop ⇒ Object
-
#timestamp ⇒ Object
Return current timestamp for the container.
Methods inherited from Base
Constructor Details
#initialize(dst, src, env, host) ⇒ DockerUp
Returns a new instance of DockerUp.
15 16 17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
11 12 13 |
# File 'lib/panoramix/plugin/docker_up.rb', line 11 def dst @dst end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
13 14 15 |
# File 'lib/panoramix/plugin/docker_up.rb', line 13 def env @env end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
12 13 14 |
# File 'lib/panoramix/plugin/docker_up.rb', line 12 def src @src end |
Instance Method Details
#clobber ⇒ Object
Action clobber for this task
48 49 50 |
# 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? ⇒ Boolean
Has this image already been created
37 38 39 40 |
# 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 ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/panoramix/plugin/docker_up.rb', line 81 def id info = created? if info containers = info.split("\n") puts containers end end |
#logs ⇒ Object
Print docker-compose project logs
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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) ⇒ Boolean
When this instance needs to be executed
53 54 55 56 |
# File 'lib/panoramix/plugin/docker_up.rb', line 53 def needed? this_time = .any? { |t| t > this_time } end |
#ps ⇒ Object
Print docker-compose ps
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/panoramix/plugin/docker_up.rb', line 109 def ps puts "Service: #{@dst}" if created? puts "Timestamp: #{}" info = shell("docker-compose -p #{@dst} -f #{@src} ps", true, @env)[:out] puts info else puts "Timestamp: Not created" end puts end |
#rm ⇒ Object
Action rm for this task
43 44 45 |
# File 'lib/panoramix/plugin/docker_up.rb', line 43 def rm clobber end |
#run_default ⇒ Object
Default action for this task
59 60 61 62 63 64 65 66 67 |
# File 'lib/panoramix/plugin/docker_up.rb', line 59 def run_default # Raise an exception if already has been created if created? = I18n.t('errors.docker_up.cluster_deployed', {:id => @dst}) raise(DockerUpExceptionError, ) end # Run docker-compose up otherwise shell("docker-compose -p #{dst} -f #{@src} up -d", false, @env) end |
#start ⇒ Object
75 76 77 78 79 |
# 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 ⇒ Object
69 70 71 72 73 |
# 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 ⇒ Object
Return current timestamp for the container
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/panoramix/plugin/docker_up.rb', line 25 def 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 |