henk 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in henk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thomas Stratmann
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Henk
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'henk'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install henk
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/henk.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'henk/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "henk"
8
+ gem.version = Henk::VERSION
9
+ gem.authors = ["Thomas Stratmann"]
10
+ gem.email = ["thomas.stratmann@9elements.com"]
11
+ gem.description = %q{Henk is a ruby wrapper around the docker CLI}
12
+ gem.summary = %q{a ruby wrapper around the docker CLI}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency 'sheller'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,25 @@
1
+ module Henk
2
+ module Commands
3
+ def pull(name)
4
+ execute('docker', 'pull', name)
5
+ end
6
+
7
+ def resolve_image_name(name)
8
+ result = execute_for_word('docker', 'images', '-q', name)
9
+ result unless result.empty?
10
+ end
11
+
12
+ def wait(container)
13
+ result = execute_for_word('docker', 'wait', container)
14
+ result &&= Integer(result)
15
+ end
16
+
17
+ def commit(container)
18
+ execute_for_word('docker', 'commit', container)
19
+ end
20
+
21
+ def logs(container)
22
+ execute('docker', 'logs', container)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ require 'henk/commands'
2
+ require 'henk/step'
3
+ require 'henk/sequence'
4
+
5
+ module Henk
6
+ class Instance
7
+ include Commands
8
+
9
+ # Block is passed exit status object
10
+ def on_subshell_error(&block)
11
+ @subshell_error_block = block
12
+ end
13
+
14
+ # Block is passed script
15
+ def before_subshell(&block)
16
+ @before_subshell_block = block
17
+ end
18
+
19
+ # Block is passed sheller result. Called regardless of error status
20
+ def after_subshell(&block)
21
+ @after_subshell_block = block
22
+ end
23
+
24
+ def run_commit(*args)
25
+ step = Step.new(self, *args)
26
+ yield step if block_given?
27
+ step.perform!
28
+ step
29
+ end
30
+
31
+ def sequence(&block)
32
+ seq = Sequence.new(self)
33
+ if block.arity.zero?
34
+ seq.instance_eval(&block)
35
+ else
36
+ yield seq
37
+ end
38
+ end
39
+
40
+ def execute(*arguments)
41
+ @before_subshell_block.call(Sheller.command(*arguments)) if @before_subshell_block
42
+
43
+ result = Sheller.execute(*arguments)
44
+
45
+ unless result.exit_status.success?
46
+ block = @subshell_error_block || Proc.new do |status|
47
+ raise "Subshell exited with status #{status}"
48
+ end
49
+ block.call(result.exit_status)
50
+ end
51
+
52
+ @after_subshell_block.call(result) if @after_subshell_block
53
+
54
+ result
55
+ end
56
+
57
+ def execute_for_word(*arguments)
58
+ sheller_result = execute(*arguments)
59
+ sheller_result.stdout.chomp if sheller_result.exit_status.success?
60
+ end
61
+ end
62
+ end
data/lib/henk/old.rb ADDED
@@ -0,0 +1,96 @@
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
@@ -0,0 +1,30 @@
1
+ require 'henk/step'
2
+
3
+ module Henk
4
+ class Sequence
5
+ attr_reader :image
6
+
7
+ def initialize(henk)
8
+ @henk = henk
9
+ end
10
+
11
+ # called with container id (string) and exit code (numeric)
12
+ def after_wait(&block)
13
+ @after_wait_block = block
14
+ end
15
+
16
+ # called with container id (string) and exit code (numeric)
17
+ def on_bad_exit(&block)
18
+ @bad_exit_block = block
19
+ end
20
+
21
+ def step(*args)
22
+ result = Step.new(@henk, *args)
23
+ result.after_wait(&@after_wait_block) if @after_wait_block
24
+ result.on_bad_exit(&@bad_exit_block) if @bad_exit_block
25
+ result.perform!
26
+ @image = result.image
27
+ result
28
+ end
29
+ end
30
+ end
data/lib/henk/step.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Henk
2
+ class Step
3
+ attr_reader :image
4
+
5
+ def initialize(henk, *args)
6
+ @henk = henk
7
+ @arguments = args
8
+ end
9
+
10
+ # called with container id (string) and exit code (numeric)
11
+ def after_wait(&block)
12
+ @after_wait_block = block
13
+ end
14
+
15
+ # called with container id (string) and exit code (numeric)
16
+ def on_bad_exit(&block)
17
+ @bad_exit_block = block
18
+ end
19
+
20
+ def perform!
21
+ container = @henk.execute_for_word(*@arguments)
22
+ return unless container
23
+
24
+ container_exit = @henk.wait(container)
25
+
26
+ @after_wait_block.call(container, container_exit) if @after_wait_block
27
+
28
+ unless container_exit.zero?
29
+ block = @bad_exit_block || Proc.new do
30
+ raise "Container #{container} exited with code #{container_exit}"
31
+ end
32
+ block.call(container, container_exit)
33
+ end
34
+
35
+ @image = @henk.commit(container)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Henk
2
+ VERSION = "0.0.1"
3
+ end
data/lib/henk.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "henk/version"
2
+
3
+ require "henk/instance"
4
+
5
+ require 'sheller'
6
+
7
+ module Henk
8
+ def self.new
9
+ Instance.new
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: henk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Stratmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sheller
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Henk is a ruby wrapper around the docker CLI
31
+ email:
32
+ - thomas.stratmann@9elements.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - henk.gemspec
43
+ - lib/henk.rb
44
+ - lib/henk/commands.rb
45
+ - lib/henk/instance.rb
46
+ - lib/henk/old.rb
47
+ - lib/henk/sequence.rb
48
+ - lib/henk/step.rb
49
+ - lib/henk/version.rb
50
+ homepage: ''
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.23
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: a ruby wrapper around the docker CLI
74
+ test_files: []