henk 0.1.0 → 0.2.0

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2Y3ZDhjZjRkZDUxMDI0ZDdkNTkxMGQwNDdkMzlmMGY1NjE0ZDk0Nw==
5
- data.tar.gz: !binary |-
6
- MWY4ZTQ3MDZlOGU4MTJjZjY5NTlkYjViMDc1MTk2ZjkxODlmZTUwNQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- Nzk0OGFkOWIyYzRhY2ZkN2Q5YTQ4MzhlMjI3YmUyMmI1NTNkYTRlMWI0NWEz
10
- NDg1ZjQ4YWE1NTQzNzhmZjFmMzAzMzRmMjk5ZGNhNDU3OGY2MTM4NWFkMjIz
11
- OTE1M2I1N2IyNmU5Mzc4MjZkZGM4ZDIxNDRhNWY3OGIyYmUxMTE=
12
- data.tar.gz: !binary |-
13
- NDgzZjQyMTZiYTRmNWQ2M2YwNDhkMTM2ZTVjZjcxYzA4MGU1MTFmNWI5N2Zm
14
- MGMzZjI0ZTI4N2YyMGI3ZmYyYmYzZWM0ZWFkZWI3YjZlMmI3NTNkYzIzMjA2
15
- OGFhOThlYzIyNzdkY2YyMTZiODRiY2QwMmY0ZDI5MWJiZDZlMTQ=
2
+ SHA1:
3
+ metadata.gz: 676f2827414421809ad632dfced0f94c1fc1b665
4
+ data.tar.gz: 22513230d990a8a07736055dc66292b441fb1791
5
+ SHA512:
6
+ metadata.gz: 6305f1d4bd9c27dc93af5dbd60e414d236e2570845c258f6e28a1017077c713c94775249e32a0868d0f1e128a14fac99918d7c74d5b440f973131215bd85ec98
7
+ data.tar.gz: ad8340b7e82509dae6172cea3a4ea977451e7a2ab9fde7b0ddd34cddf9bb574fb45abd9417017198b17e9b1bfda3aff720553bfb70d5781b7feac1f65528f48d
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in henk.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
data/lib/henk/commands.rb CHANGED
@@ -12,7 +12,6 @@ module Henk
12
12
  lines = lines.map { |line| line.split(/ +/) }
13
13
 
14
14
  raise "'docker images' output not as expected" unless
15
- lines.first.length == 5 &&
16
15
  lines.first[0..1] == %w(REPOSITORY TAG)
17
16
 
18
17
  line = lines.find { |l| l[0..1].join(':') == name}
@@ -44,5 +43,9 @@ module Henk
44
43
 
45
44
  execute 'docker', 'tag', *command_options, image, repository, *tag
46
45
  end
46
+
47
+ def kill(*containers)
48
+ execute('docker', 'kill', *containers)
49
+ end
47
50
  end
48
51
  end
data/lib/henk/instance.rb CHANGED
@@ -6,6 +6,14 @@ module Henk
6
6
  class Instance
7
7
  include Commands
8
8
 
9
+ def initialize
10
+ @running_containers = []
11
+ end
12
+
13
+ def running_containers
14
+ @running_containers.to_enum
15
+ end
16
+
9
17
  # Block is passed exit status object
10
18
  def on_subshell_error(&block)
11
19
  @subshell_error_block = block
@@ -63,5 +71,14 @@ module Henk
63
71
  sheller_result = execute(*arguments)
64
72
  sheller_result.stdout.chomp.split("\n") if sheller_result.exit_status.success?
65
73
  end
74
+
75
+ private
76
+
77
+ def while_container_running(container)
78
+ @running_containers << container
79
+ yield
80
+ ensure
81
+ @running_containers.delete(container)
82
+ end
66
83
  end
67
84
  end
data/lib/henk/step.rb CHANGED
@@ -21,7 +21,9 @@ module Henk
21
21
  container = @henk.execute_for_word(*@arguments)
22
22
  return unless container
23
23
 
24
- container_exit = @henk.wait(container)
24
+ container_exit = @henk.send(:while_container_running, container) do
25
+ @henk.wait(container)
26
+ end
25
27
 
26
28
  @after_wait_block.call(container, container_exit) if @after_wait_block
27
29
 
data/lib/henk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Henk
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: henk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Stratmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-27 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- version_requirements: !ruby/object:Gem::Requirement
14
+ name: sheller
15
+ requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ! '>='
17
+ - - '>='
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
19
20
  type: :runtime
20
21
  prerelease: false
21
- name: sheller
22
- requirement: !ruby/object:Gem::Requirement
22
+ version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Henk is a ruby wrapper around the docker CLI
@@ -40,7 +40,6 @@ files:
40
40
  - lib/henk.rb
41
41
  - lib/henk/commands.rb
42
42
  - lib/henk/instance.rb
43
- - lib/henk/old.rb
44
43
  - lib/henk/sequence.rb
45
44
  - lib/henk/step.rb
46
45
  - lib/henk/version.rb
@@ -53,19 +52,18 @@ require_paths:
53
52
  - lib
54
53
  required_ruby_version: !ruby/object:Gem::Requirement
55
54
  requirements:
56
- - - ! '>='
55
+ - - '>='
57
56
  - !ruby/object:Gem::Version
58
57
  version: '0'
59
58
  required_rubygems_version: !ruby/object:Gem::Requirement
60
59
  requirements:
61
- - - ! '>='
60
+ - - '>='
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  requirements: []
65
64
  rubyforge_project:
66
- rubygems_version: 2.0.5
65
+ rubygems_version: 2.0.14
67
66
  signing_key:
68
67
  specification_version: 4
69
68
  summary: a ruby wrapper around the docker CLI
70
69
  test_files: []
71
- has_rdoc:
data/lib/henk/old.rb DELETED
@@ -1,96 +0,0 @@
1
- require 'sheller'
2
-
3
- module Henk
4
- extend self
5
-
6
- def spawn(*arguments, &block)
7
- block ||= method(:default_error_handler)
8
-
9
- result = Sheller.execute(*arguments)
10
-
11
- block.call(arguments, result) unless result.exit_status.success?
12
-
13
- result
14
- end
15
-
16
- def spawn_for_id(*arguments, &block)
17
- sheller_result = spawn(*arguments, &block)
18
-
19
- sheller_result.stdout.chomp if sheller_result.exit_status.success?
20
- end
21
-
22
- def default_error_handler(sheller_arguments, sheller_result)
23
- raise "Subshell invocation #{sheller_arguments.join ' '} failed, exit status #{sheller_result.exit_status}"
24
- end
25
-
26
- def pull(name, &block)
27
- spawn('docker', 'pull', name, &block)
28
- end
29
-
30
- # can we make good use of this in Sequence?
31
- def wait(container, &block)
32
- exit_code_string = spawn_for_id('docker', 'wait', container, &block)
33
-
34
- yield exit_code_string if block_given? && exit_code_string != '0'
35
-
36
- exit_code_string
37
- end
38
-
39
- def commit(container, &block)
40
- spawn_for_id('docker', 'commit', container, &block)
41
- end
42
-
43
- class Sequence
44
- include Henk
45
-
46
- attr_reader :image
47
-
48
- def log_spawn(&block)
49
- @log_spawn_block = block
50
- end
51
-
52
- def on_error(&block)
53
- @error_block = block
54
- end
55
-
56
- def on_bad_exit(&block)
57
- @bad_exit_block = block
58
- end
59
-
60
- def after_wait(&block)
61
- @after_wait_block = block
62
- end
63
-
64
- def spawn(*arguments, &block)
65
- @log_spawn_block.call(Sheller.command(*arguments)) if @log_spawn_block
66
- super
67
- end
68
-
69
- def step(*arguments)
70
- @image = nil
71
-
72
- container = spawn_for_id(*arguments, &@error_block)
73
- return unless container
74
-
75
- wait_result = spawn('docker', 'wait', container)
76
- return unless wait_result.exit_status.success?
77
-
78
- exit_code_string = wait_result.stdout.chomp
79
-
80
- @after_wait_block.call(container, exit_code_string) if @after_wait_block
81
-
82
- unless exit_code_string == '0'
83
- bad_exit_block.call(exit_code_string)
84
- return
85
- end
86
-
87
- @image = commit(container, &@error_block)
88
- end
89
-
90
- def bad_exit_block
91
- @bad_exit_block ||= Proc.new do |exit_code_string|
92
- raise "Container exited with code #{exit_code_string}"
93
- end
94
- end
95
- end
96
- end