donce 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/donce.gemspec +1 -1
- data/lib/donce.rb +5 -7
- data/test/test_donce.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87e27e95378a5ad34a9ba6a7ef7c8578efb3d24990998beada04097c1a46d5c1
|
4
|
+
data.tar.gz: 0ea31ae8977024be7abdbc164a3250a8eb907511ea24b5427b2eb3f8960b2912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df41062bb8aea186f7bafc2df0070d7abbf1238d2eea5270f49a62e1901a495b0d50afca4659b5314ea0ea0117a299241b8757369a07b5e384cd8595abf956f2
|
7
|
+
data.tar.gz: 2d6de2cde5d5df5dc3048bb7e9d68cc8b866ec76842f9ce7f9441a4b3b1f683a58e65428c558244c02ab2bcf1a6760606f1e63cea7a7c1a77f08778a18c59fd4
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
[](https://github.com/yegor256/donce/blob/master/LICENSE.txt)
|
13
13
|
|
14
14
|
This small Ruby library helps building temporary [Docker]
|
15
|
-
images,
|
15
|
+
images, runs Docker containers, and cleans up afterwards — it may be
|
16
16
|
convenient for automated tests (for example, with [Minitest]):
|
17
17
|
|
18
18
|
```ruby
|
@@ -29,6 +29,15 @@ class MyTest < Minitest::Test
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
+
It's possible to run Docker image in a background mode too:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
stdout = donce(image: 'ubuntu', command: 'sleep 9999') do |id|
|
36
|
+
# The "id" is the container id
|
37
|
+
# The "donce_host()" is the hostname of it
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
32
41
|
That's it.
|
33
42
|
|
34
43
|
## How to contribute
|
data/donce.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=3.0'
|
28
28
|
s.name = 'donce'
|
29
|
-
s.version = '0.0.
|
29
|
+
s.version = '0.0.4'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Builds and starts temporary Docker containers'
|
32
32
|
s.description =
|
data/lib/donce.rb
CHANGED
@@ -89,7 +89,7 @@ module Kernel
|
|
89
89
|
if image
|
90
90
|
image
|
91
91
|
else
|
92
|
-
i = "donce-#{SecureRandom.hex(
|
92
|
+
i = "donce-#{SecureRandom.hex(6)}"
|
93
93
|
if dockerfile
|
94
94
|
Dir.mktmpdir do |tmp|
|
95
95
|
File.write(File.join(tmp, 'Dockerfile'), dockerfile)
|
@@ -100,7 +100,7 @@ module Kernel
|
|
100
100
|
end
|
101
101
|
i
|
102
102
|
end
|
103
|
-
container = "donce-#{SecureRandom.hex(
|
103
|
+
container = "donce-#{SecureRandom.hex(6)}"
|
104
104
|
begin
|
105
105
|
stdout = nil
|
106
106
|
code = 0
|
@@ -132,16 +132,14 @@ module Kernel
|
|
132
132
|
"Failed to run #{cmd} " \
|
133
133
|
"(exit code is ##{code}, stdout has #{stdout.split("\n").count} lines)"
|
134
134
|
end
|
135
|
-
if block_given?
|
136
|
-
r = yield container
|
137
|
-
return r
|
138
|
-
end
|
135
|
+
yield container if block_given?
|
139
136
|
ensure
|
140
|
-
qbash(
|
137
|
+
logs = qbash(
|
141
138
|
"#{docker} logs #{Shellwords.escape(container)}",
|
142
139
|
level: code.zero? ? Logger::DEBUG : Logger::ERROR,
|
143
140
|
log:
|
144
141
|
)
|
142
|
+
stdout = logs if block_given?
|
145
143
|
qbash("#{docker} rm -f #{Shellwords.escape(container)}", log:)
|
146
144
|
end
|
147
145
|
stdout
|
data/test/test_donce.rb
CHANGED