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 +4 -4
- data/lib/flock/sandbox.rb +59 -27
- data/lib/flock/sandbox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02562d9d82cdcc051d9c3074d7e71bfc9d57cc89
|
4
|
+
data.tar.gz: f89140d1379185138d646b7f201c5d3620092e61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
106
|
-
c
|
107
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|