buncker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c771a48ad5d8e26e4e39f719f2794fb1217eb395
4
- data.tar.gz: aa6f0de4b943b434373b3b923f9e6077220402fe
3
+ metadata.gz: edb0ab76169ff8f781ae8d4a12f3709e41ef20dc
4
+ data.tar.gz: 39945d9f50f70e26ba10759cb5a6a91e3e039997
5
5
  SHA512:
6
- metadata.gz: 08dc4ca482374699e3f10142ac6074a5efa14046ed25b2bafaef6a0ae1c989604145b91d6462280dd6c8a84b3daf1d80eb3fdd9339f4de344e62469850c241dd
7
- data.tar.gz: 3ec0efc7fef9d8271697bc3d071c56fbcd30627b99cc4c5ed0e5228f92d906ffa91694d3f9fde0b1e19a511df8181a1944a88fe6b8f2fd25c8aa68051fbbc999
6
+ metadata.gz: 3e5f46a878f45073a2ac882df67edae4e7d5146a0560c4ab2a294bb3dd4b8880fd521b199f68c5e42139bbca22bd427a3fb61979e55ec7cb6a5f7b3a4696922a
7
+ data.tar.gz: b326d9ae0dec35911fd8e310e129c349bbe2398a5ec52e9d76f97d89f5c55b5a136327a4f9dac1caf2a7fa3a9064a29564148dbd686c63f56dc19bccaa998f03
data/NEWS ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.2
2
+
3
+ * Fixes for remote docker (eg. boot2docker)
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'buncker/patches'
6
+
3
7
  require 'docker'
4
8
  require 'fileutils'
5
9
  require 'pathname'
@@ -7,64 +11,70 @@ require 'pathname'
7
11
  name, tag = ARGV
8
12
 
9
13
  cachedir = Pathname.pwd + '.buncker/cache'
10
- cidfile = Pathname.pwd + '.buncker/cid'
11
14
 
12
15
  FileUtils.mkdir_p cachedir
13
- FileUtils.rm_f cidfile
14
16
 
15
- slugpath = Pathname.pwd + '.buncker/slug'
17
+ build_sh = File.expand_path("../../build/build.sh", __FILE__)
18
+
19
+ def create_container opts
20
+ Docker::Container.create opts
21
+ rescue Docker::Error::NotFoundError
22
+ # try to pull
23
+ warn "Image #{image = opts['Image']} not found, trying to pull"
24
+ Docker::Image.create fromImage: image
25
+ Docker::Container.create opts
26
+ end
16
27
 
17
- archive = `git archive HEAD`;
18
- builder = Docker::Container.create(
28
+ builder = create_container(
19
29
  'Image' => 'conjurinc/buncker:build',
20
30
  'Volumes' => {
21
- '/app/vendor' => {}
31
+ '/app/vendor' => {},
22
32
  },
23
33
  'OpenStdin' => true,
24
34
  'StdinOnce' => true,
25
35
  )
36
+ builder.start 'Binds' => ["#{cachedir}:/app/vendor"]
26
37
 
27
- builder.start 'Binds' => "#{cachedir}:/app/vendor"
28
-
29
- slug = File.open slugpath, 'w'
30
-
31
- builder.attach(
32
- stdin: StringIO.new(archive),
33
- stdout: true,
34
- stderr: true,
35
- logs: true,
36
- ) do |stream, chunk|
37
- case stream
38
- when :stdout
39
- slug.write chunk
40
- else
41
- print chunk
42
- end
43
- end;
44
-
45
- builder.wait
46
- builder.remove
47
-
48
- slug.close
49
-
50
- target = Docker::Container.create(
38
+ target = create_container(
51
39
  'Image' => 'conjurinc/buncker',
52
40
  'OpenStdin' => true,
53
41
  'StdinOnce' => true,
54
- 'Cmd' => %w(tar xC/)
42
+ 'Cmd' => %w(tar xvC/)
55
43
  )
56
-
57
44
  target.start
58
45
 
59
- target.attach(
60
- stdin: File.open(slugpath),
61
- stdout: true,
62
- stderr: true,
63
- logs: true,
64
- ) do |stream, chunk|
65
- print chunk
46
+ # fork the builder
47
+ open "|-", 'r' do |builder_pipe|
48
+ if builder_pipe.nil?
49
+ # in the child
50
+ builder.attach(
51
+ stdin: open('| git archive HEAD', 'r'),
52
+ stdout: true,
53
+ stderr: true,
54
+ logs: true,
55
+ ) do |stream, chunk|
56
+ case stream
57
+ when :stdout
58
+ # push to target
59
+ $stdout.write chunk
60
+ else
61
+ $stderr.print chunk
62
+ end
63
+ end;
64
+ builder.wait
65
+ else
66
+ target.attach(
67
+ stdin: builder_pipe,
68
+ stdout: true,
69
+ stderr: true,
70
+ logs: true,
71
+ ) do |stream, chunk|
72
+ print chunk
73
+ end
74
+ target.wait
75
+ end
66
76
  end
67
77
 
68
- target.wait
78
+ builder.remove
69
79
  target.commit repo: name, tag: tag
70
80
  target.remove
@@ -34,7 +34,27 @@ bundle install --deployment --without development test cucumber appliance >&2
34
34
  bundle clean >&2
35
35
 
36
36
  cd /
37
- tar c app
37
+ tar cv \
38
+ --exclude 'app/vendor/bundle/ruby/*/build_info' \
39
+ --exclude 'app/vendor/bundle/ruby/*/cache' \
40
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/doc' \
41
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/doc-api' \
42
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/examples' \
43
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/guides' \
44
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/java' \
45
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/spec' \
46
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/test' \
47
+ --exclude 'app/vendor/bundle/ruby/*/gems/*/tests' \
48
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/doc' \
49
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/doc-api' \
50
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/examples' \
51
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/guides' \
52
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/java' \
53
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/spec' \
54
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/test' \
55
+ --exclude 'app/vendor/bundle/ruby/*/bundler/gems/*/tests' \
56
+ --exclude '.git' \
57
+ app
38
58
 
39
59
  # some echo here is required, otherwise clients break connection prematurely
40
60
  echo Slug built successfully. >&2
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency "docker-api", "~> 1.17"
20
+ # freeze version because of the monkey patch
21
+ spec.add_runtime_dependency "docker-api", "= 1.17"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.7"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1 @@
1
+ require 'buncker/patches/docker'
@@ -0,0 +1,49 @@
1
+ require 'docker'
2
+ require 'docker/util'
3
+
4
+ class Docker::Container
5
+ # the original doesn't work with SSL sockets
6
+ # due to inability to close just one half of them
7
+ #
8
+ # work around that by opening a separate connection for stdin
9
+
10
+ alias_method :orig_attach, :attach
11
+
12
+ def attach(options = {}, &block)
13
+ if (stdin = options.delete(:stdin))
14
+ stdin_thread = stream_stdin stdin
15
+ end
16
+
17
+ orig_attach options, &block
18
+ stdin_thread.join
19
+ end
20
+
21
+ private
22
+
23
+ # clones a connection and launches a thread to stream stdin
24
+ def stream_stdin stdin
25
+ conn = Docker::Connection.new connection.url, connection.options
26
+
27
+ Thread.new do
28
+ conn.post(
29
+ path_for(:attach),
30
+ { stream: true, stdout: false, stderr: false, stdin: true },
31
+ hijack_block: Docker::Util.hijack_stdin_for(stdin)
32
+ )
33
+ end
34
+ end
35
+ end
36
+
37
+ module Docker::Util
38
+ module_function
39
+
40
+ # hijack only for stdin (to work with SSL sockets)
41
+ def hijack_stdin_for(stdin)
42
+ lambda do |socket|
43
+ debug "hijack_stdin: copying stdin => socket"
44
+ IO.copy_stream stdin, socket
45
+ debug "hijack_stdin: closing hijacked write socket"
46
+ socket.close
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Buncker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buncker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Rzepecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.17'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - Gemfile
65
65
  - LICENSE
66
66
  - Makefile
67
+ - NEWS
67
68
  - README.md
68
69
  - Rakefile
69
70
  - app/Dockerfile
@@ -74,6 +75,8 @@ files:
74
75
  - build/build.sh
75
76
  - buncker.gemspec
76
77
  - lib/buncker.rb
78
+ - lib/buncker/patches.rb
79
+ - lib/buncker/patches/docker.rb
77
80
  - lib/buncker/version.rb
78
81
  homepage: https://github.com/conjurinc/buncker
79
82
  licenses: