flock-sandbox 0.0.3 → 0.0.4

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: 3de9da61d626a83aaa24178f54488223ecb7d119
4
- data.tar.gz: 7c31c7b0d67b953ee53072879b67fae9f2a2f8eb
3
+ metadata.gz: 02562d9d82cdcc051d9c3074d7e71bfc9d57cc89
4
+ data.tar.gz: f89140d1379185138d646b7f201c5d3620092e61
5
5
  SHA512:
6
- metadata.gz: 999b1985a5c72b11af0a349239cf1d3455cc27542b1e57bfce463f7a2899882fe53b5f056a2fdf61dd4f96f3a366311c66c913ee0dda33ce2ea6f4131009c8ed
7
- data.tar.gz: 0c788ba6b893f811b7a5d8ee739d4caf741effd239b2ffaeb693e5e0edb03ec897a3677a1a3a6b2f53826a0a7af9cc715069e0fe112a90e41e22a6944ce24f02
6
+ metadata.gz: 7b9d427fe15bc727fba261206363f2ba5c027d9dc0fc63ebf0fc190e1f65c7cc6c6ab58ee85b28ea9fdd9cbe38043f0c2700e349e0476c55127b959ae1864eb0
7
+ data.tar.gz: 1f5c2fb865d4d9159ee83349873a081e18178c135780e3fe0019ca22b95ce46d46b89b8365b78cd678eb7f9b54ae8335f3f2689e2e26d8cad1c87b3a48853a53
data/lib/flock/sandbox.rb CHANGED
@@ -25,6 +25,8 @@ module Flock
25
25
  Docker.new(definition).run
26
26
  when "vagrant"
27
27
  Vagrant.new(definition).run
28
+ when "docker-stop"
29
+ DockerStop.new(definition).run
28
30
  end
29
31
  end
30
32
 
@@ -74,42 +76,72 @@ module Flock
74
76
  def run
75
77
  containers = []
76
78
  begin
77
- @definition.containers.each do |c|
78
- puts "Start container #{c[:name]} (#{c[:image]})"
79
- ::Docker::Image.create('fromImage' => c[:image])
80
- container = ::Docker::Container.create('Image' => c[:image],
81
- 'name' => c[:name],
82
- 'Env' => c[:envs],
83
- 'HostConfig' => {'Links' => c[:links]})
84
- containers << container
85
- container.start
79
+ unless ENV['ONLY_SCRIPTS']
80
+ @definition.containers.each do |c|
81
+ puts "Start container #{c[:name]} (#{c[:image]})"
82
+ ::Docker::Image.create('fromImage' => c[:image])
83
+ container = ::Docker::Container.create('Image' => c[:image],
84
+ 'name' => c[:name],
85
+ 'Env' => c[:envs],
86
+ 'HostConfig' => {'Links' => c[:links]})
87
+ containers << container
88
+ container.start
89
+ end
86
90
  end
87
- @definition.scripts.each do |c|
88
- puts "Run script #{c[:name]} (#{c[:image]} #{c[:cmd].inspect})"
89
- ::Docker::Image.create('fromImage' => c[:image])
90
- container = ::Docker::Container.create('Cmd' => c[:cmd],
91
- 'Image' => c[:image],
92
- 'Env' => c[:envs],
93
- 'HostConfig' => {'Links' => c[:links]})
94
- containers << container
95
- container.start
96
- res = container.wait
97
- logs = container.logs(stdout: true, stderr: true)
98
- puts logs
99
- if res['StatusCode'] != 0
100
- puts "Error in script #{c[:name]}: error code #{res['StatusCode']}"
101
- exit res['StatusCode']
91
+ if ENV['MANUAL_SCRIPTS']
92
+ @definition.scripts.each do |c|
93
+ puts "docker run #{(c[:links] || []).map { |v| "--link #{v}" } * " " } #{(c[:envs] || []).map { |e| "-e #{e}" } * " " } #{c[:image]} #{c[:cmd] * ' '}"
94
+ end
95
+ else
96
+ @definition.scripts.each do |c|
97
+ puts "Run script #{c[:name]} (#{c[:image]} #{c[:cmd].inspect})"
98
+ ::Docker::Image.create('fromImage' => c[:image])
99
+ container = ::Docker::Container.create('Cmd' => c[:cmd],
100
+ 'Image' => c[:image],
101
+ 'Env' => c[:envs],
102
+ 'HostConfig' => {'Links' => c[:links]})
103
+ containers << container
104
+ container.start
105
+ res = container.wait(1200)
106
+ logs = container.logs(stdout: true, stderr: true)
107
+ puts logs
108
+ if res['StatusCode'] != 0
109
+ puts "Error in script #{c[:name]}: error code #{res['StatusCode']}"
110
+ exit res['StatusCode']
111
+ end
102
112
  end
103
113
  end
104
114
  ensure
105
- containers.each do |c|
106
- c.kill
107
- c.delete
115
+ unless ENV['MANUAL_SCRIPTS']
116
+ containers.each do |c|
117
+ c.kill
118
+ c.delete
119
+ end
108
120
  end
109
121
  end
110
122
  end
111
123
  end
112
124
 
125
+ class DockerStop
126
+
127
+ def initialize(definition)
128
+ @definition = definition
129
+ end
130
+
131
+ def run
132
+ @definition.containers.each do |c|
133
+ cont = begin
134
+ ::Docker::Container.get(c[:name])
135
+ rescue ::Docker::Error::NotFoundError
136
+ end
137
+ next unless c
138
+ puts "Stop #{c[:name]}"
139
+ cont.kill
140
+ cont.delete
141
+ end
142
+ end
143
+ end
144
+
113
145
  class Vagrant
114
146
  def initialize(definition)
115
147
  @definition = definition
@@ -1,5 +1,5 @@
1
1
  module Flock
2
2
  module Sandbox
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flock-sandbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Rudenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api