donce 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
  SHA256:
3
- metadata.gz: ad7d3419ce887d6b42f6f92f6dc9ad8414b0c3c89c1fb0ef4600972ac54f754e
4
- data.tar.gz: a8d95d419418e037968ae4f659a5b538a8c67c44fee323974befefa7d5651b5c
3
+ metadata.gz: 87e27e95378a5ad34a9ba6a7ef7c8578efb3d24990998beada04097c1a46d5c1
4
+ data.tar.gz: 0ea31ae8977024be7abdbc164a3250a8eb907511ea24b5427b2eb3f8960b2912
5
5
  SHA512:
6
- metadata.gz: 22738b8cdd2b2eef8188c1e69dfea55a7d3b7317f73623fd2230cd65695dd033994f58a62fca0e549a5e846245c61b1ec0d870760d79becda4e4a769f62ba9dc
7
- data.tar.gz: 86ee931f8f8149192661d2541b19abbd58377dd8d6aa7fc5770fbe1fdc66819aeb8ff409224938b74acedf5a94b5d961c40439f4263d83cdf3eb1e84b9e24169
6
+ metadata.gz: df41062bb8aea186f7bafc2df0070d7abbf1238d2eea5270f49a62e1901a495b0d50afca4659b5314ea0ea0117a299241b8757369a07b5e384cd8595abf956f2
7
+ data.tar.gz: 2d6de2cde5d5df5dc3048bb7e9d68cc8b866ec76842f9ce7f9441a4b3b1f683a58e65428c558244c02ab2bcf1a6760606f1e63cea7a7c1a77f08778a18c59fd4
data/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/donce/blob/master/LICENSE.txt)
13
13
 
14
14
  This small Ruby library helps building temporary [Docker]
15
- images, run Docker containers, and clean up afterwards --- may be
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.3'
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(8)}"
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(8)}"
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
@@ -55,4 +55,9 @@ class TestDonce < Minitest::Test
55
55
  end
56
56
  assert(seen)
57
57
  end
58
+
59
+ def test_returns_stdout_from_daemon
60
+ stdout = donce(dockerfile: "FROM ubuntu\nCMD echo hello", log: Loog::NULL) { |_| sleep 0.1 }
61
+ assert_equal("hello\n", stdout)
62
+ end
58
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: donce
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
  - Yegor Bugayenko