percheron 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 351631398d6695f7c3f4ff15567e095bbea8cc0c
4
- data.tar.gz: bf3a8b1f2ab2582027dce70a300be3c7c7044665
3
+ metadata.gz: 60e75ad43ed6c18a865ea07d76f9fa2b1d893eed
4
+ data.tar.gz: 54207bfa168a15d727ba18bba758bf40d4d885f6
5
5
  SHA512:
6
- metadata.gz: df85d70b9c88b68ae7822cc3ed35e7eb88b72772256e60e3cb9e3b46d04e56c786119705151e9b3aaf666530b0cc173142253a9d3f6cd5cb7abe7a2bf6edc1fe
7
- data.tar.gz: 8fcc500b642f047838c430f2089852054d300cf34040749fd87a4616f859aa159016e312ab3f2f0beda7205798f735cd2bfd2edb7dc82b5d5a2b633a4c1c9694
6
+ metadata.gz: af2d8a877d52f2a51b76c69b809b6773b26d7a22ac3e6acbb4dcce2673257d9302fc9d2079d5af7564f9e92ce8150d859ed16d4c512195f5832ca89bc7ba9afd
7
+ data.tar.gz: ad859eabacf9550306947c969dff212fb7aa9b2bb888ab87acc20bb6a4ed1e208f303a04a6cf55a27cc6d75f84df48a92d76e85ffa048e335e1569a3c0fb0a30
data/README.md CHANGED
@@ -53,6 +53,10 @@ $ gem install percheron
53
53
 
54
54
  TODO
55
55
 
56
+ ## Demo
57
+
58
+ [![asciicast](https://asciinema.org/a/19216.png)](https://asciinema.org/a/19216)
59
+
56
60
  ## Debugging
57
61
 
58
62
  To debug Percheron, set the `DEBUG=true` environment variable.
@@ -3,29 +3,34 @@ module Percheron
3
3
  class Shell
4
4
  include Base
5
5
 
6
- DEFAULT_SHELL = '/bin/sh'
6
+ DEFAULT_COMMAND = '/bin/sh'
7
7
  DOCKER_CLIENT = 'docker'
8
8
 
9
- def initialize(container, shell: DEFAULT_SHELL)
9
+ def initialize(container, command: DEFAULT_COMMAND)
10
10
  @container = container
11
- @shell = shell
11
+ @command = command
12
12
  end
13
13
 
14
14
  def execute!
15
- $logger.debug "Executing #{shell} on '#{container.name}' container"
16
15
  exec! if valid?
17
16
  end
18
17
 
19
18
  private
20
19
 
21
- attr_reader :container, :shell
20
+ attr_reader :container
22
21
 
23
22
  def valid?
24
23
  Validators::DockerClient.new.valid?
25
24
  end
26
25
 
26
+ def command
27
+ "sh -c '%s'" % @command
28
+ end
29
+
27
30
  def exec!
28
- system('%s exec -ti %s %s' % [ DOCKER_CLIENT, container.full_name, shell ])
31
+ cmd = '%s exec -ti %s %s' % [ DOCKER_CLIENT, container.full_name, command ]
32
+ $logger.debug "Executing '#{cmd}' on '#{container.name}' container"
33
+ system(cmd)
29
34
  end
30
35
  end
31
36
  end
@@ -12,6 +12,7 @@ module Percheron
12
12
 
13
13
  private
14
14
 
15
+ # FIXME: Dupe?
15
16
  def list
16
17
  Stack.get(config, stack_name).each do |_, stack|
17
18
  puts("\n", Percheron::Formatters::Stack::Table.new(stack).generate)
@@ -58,6 +59,8 @@ module Percheron
58
59
  stack.restart!(container_names: [ *container_names ])
59
60
  nil
60
61
  end
62
+
63
+ alias_method :status, :list
61
64
  end
62
65
  end
63
66
  end
@@ -4,11 +4,11 @@ module Percheron
4
4
 
5
5
  parameter('STACK_NAME', 'stack name', required: true)
6
6
  parameter('CONTAINER_NAME', 'container name', required: true)
7
- option('--shell', 'SHELL', 'Shell to use', default: Percheron::Actions::Shell::DEFAULT_SHELL)
7
+ option('--command', 'COMMAND', 'command', default: Percheron::Actions::Shell::DEFAULT_COMMAND)
8
8
 
9
9
  def execute
10
10
  super
11
- stack.shell!(container_name, shell: shell)
11
+ stack.shell!(container_name, command: command)
12
12
  rescue Errors::DockerClientInvalid => e
13
13
  signal_usage_error(e.message)
14
14
  end
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module Percheron
2
4
  module Formatters
3
5
  module Stack
@@ -5,6 +7,7 @@ module Percheron
5
7
 
6
8
  def initialize(stack)
7
9
  @stack = stack
10
+ @queue = Queue.new
8
11
  end
9
12
 
10
13
  def generate
@@ -13,7 +16,7 @@ module Percheron
13
16
 
14
17
  private
15
18
 
16
- attr_reader :stack
19
+ attr_reader :stack, :queue
17
20
 
18
21
  def title
19
22
  stack.name
@@ -31,21 +34,42 @@ module Percheron
31
34
  ]
32
35
  end
33
36
 
34
- # rubocop:disable Metrics/MethodLength
35
37
  def rows
38
+ resp = {}
39
+ queue_jobs(resp)
40
+ process_queue!
41
+ sort_rows(resp)
42
+ end
43
+
44
+ def queue_jobs(resp)
36
45
  stack.containers.map do |_, container|
37
- [
38
- container.name,
39
- container.id,
40
- startable(container),
41
- container.ip,
42
- container.ports.join(', '),
43
- container.volumes.join(', '),
44
- (container.built_version == '0.0.0') ? '' : container.built_version
45
- ]
46
+ queue << Thread.new { resp[Time.now.to_f] = row_for(container) }
46
47
  end
47
48
  end
48
- # rubocop:enable Metrics/MethodLength
49
+
50
+ def process_queue!
51
+ queue.length.times { queue.pop.join }
52
+ end
53
+
54
+ def sort_rows(resp)
55
+ resp.sort.map { |_, row| row.flatten }
56
+ end
57
+
58
+ def row_for(container)
59
+ [
60
+ container.name,
61
+ container.id,
62
+ startable(container),
63
+ container.ip,
64
+ container.ports.join(', '),
65
+ container.volumes.join(', '),
66
+ version(container)
67
+ ]
68
+ end
69
+
70
+ def version(container)
71
+ (container.built_version == '0.0.0') ? '' : container.built_version
72
+ end
49
73
 
50
74
  def startable(container)
51
75
  if container.startable?
@@ -32,8 +32,8 @@ module Percheron
32
32
  end
33
33
  end
34
34
 
35
- def shell!(container_name, shell: Percheron::Actions::Shell::DEFAULT_SHELL)
36
- Actions::Shell.new(container_from_name(container_name), shell: shell).execute!
35
+ def shell!(container_name, command: Percheron::Actions::Shell::DEFAULT_COMMAND)
36
+ Actions::Shell.new(container_from_name(container_name), command: command).execute!
37
37
  end
38
38
 
39
39
  def logs!(container_name, follow: false)
@@ -1,3 +1,3 @@
1
1
  module Percheron
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percheron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash McKenzie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp