specinfra 2.12.7 → 2.13.0

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: 481871a1216b636632065d30fcf6b7596ba048aa
4
- data.tar.gz: 8b831e0e5643609a50d0c66316b3cb1066f1a854
3
+ metadata.gz: 78b5cc48f8d10d0b2de74d1981f298837b3aa3c3
4
+ data.tar.gz: e424f7e527599710fe4a7ff10690d53123250c2f
5
5
  SHA512:
6
- metadata.gz: 17573c8d4461b8cb06402f2ee75099f570b5a4cda08ff2f3e8217e2e2777558d9432241ea49d8e9a5bf17024701a1bf4adec5425e6c4b51cc8c1c6c9d6fe64db
7
- data.tar.gz: 7b4e8b108300c812afe9188943c4f11d641c9ad4ec55c65498bbd412e36249641da62e297af04e217b3000ffe995c25a40631ce7a63f2c1c7af7a161008cba3c
6
+ metadata.gz: 12002f9e969a4e35926c91c8fb1f9eff7eca6bc72b597c8fad3f47345254b0ac35654fbd3fea00db8a87437fa652bfe2435dcccdff770730a0820ca759d468aa
7
+ data.tar.gz: 2eb541ec4489faddd13fa2b699862fe31c015f4b849bbf7a0dcecd35a1eeedd639c8e71ae8076b58a29f9992526bc1a53c4ce69556d765518836b39276606070
@@ -7,9 +7,18 @@ module Specinfra::Backend
7
7
  fail "Docker client library is not available. Try installing `docker-api' gem."
8
8
  end
9
9
 
10
- @images = []
11
10
  ::Docker.url = Specinfra.configuration.docker_url
12
- @base_image = ::Docker::Image.get(Specinfra.configuration.docker_image)
11
+
12
+ if image = Specinfra.configuration.docker_image
13
+ @images = []
14
+ @base_image = ::Docker::Image.get(image)
15
+ create_and_start_container
16
+ ObjectSpace.define_finalizer(self, proc { cleanup_container })
17
+ elsif container = Specinfra.configuration.docker_container
18
+ @container = ::Docker::Container.get(container)
19
+ else
20
+ fail 'Please specify docker_image or docker_container.'
21
+ end
13
22
  end
14
23
 
15
24
  def run_command(cmd, opts={})
@@ -27,38 +36,44 @@ module Specinfra::Backend
27
36
  end
28
37
 
29
38
  def send_file(from, to)
39
+ if @base_image.nil?
40
+ fail 'Cannot call send_file without docker_image.'
41
+ end
42
+
30
43
  @images << current_image.insert_local('localPath' => from, 'outputPath' => to)
44
+ cleanup_container
45
+ create_and_start_container
31
46
  end
32
47
 
33
48
  private
34
49
 
50
+ def create_and_start_container
51
+ opts = { 'Image' => current_image.id }
52
+
53
+ if path = Specinfra.configuration.path
54
+ (opts['Env'] ||= {})['PATH'] = path
55
+ end
56
+
57
+ @container = ::Docker::Container.create(opts)
58
+ @container.start
59
+ end
60
+
61
+ def cleanup_container
62
+ @container.stop
63
+ @container.delete
64
+ end
65
+
35
66
  def current_image
36
67
  @images.last || @base_image
37
68
  end
38
69
 
39
70
  def docker_run!(cmd, opts={})
40
- opts = {
41
- 'Image' => current_image.id,
42
- 'Cmd' => %W{/bin/sh -c #{cmd}},
43
- }.merge(opts)
44
-
45
- if path = Specinfra::configuration::path
46
- (opts['Env'] ||= {})['PATH'] = path
47
- end
48
-
49
- container = ::Docker::Container.create(opts)
50
71
  begin
51
- container.start
52
- begin
53
- stdout, stderr = container.attach(:logs => true)
54
- result = container.wait
55
- return CommandResult.new :stdout => stdout.join, :stderr => stderr.join,
56
- :exit_status => result['StatusCode']
57
- rescue
58
- container.kill
59
- end
60
- ensure
61
- container.delete
72
+ stdout, stderr, status = @container.exec(['/bin/sh', '-c', cmd])
73
+ return CommandResult.new :stdout => stdout, :stderr => stderr,
74
+ :exit_status => status
75
+ rescue
76
+ @container.kill
62
77
  end
63
78
  end
64
79
  end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.12.7"
2
+ VERSION = "2.13.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.7
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh