donce 0.1.0 → 0.2.1

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.
data/Gemfile.lock CHANGED
@@ -2,75 +2,26 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  donce (0.0.0)
5
- backtrace (> 0)
6
- os (> 0)
7
- qbash (> 0)
5
+ backtrace (~> 0.3)
6
+ os (~> 1.1)
7
+ qbash (~> 0.3)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (8.0.1)
13
- actionview (= 8.0.1)
14
- activesupport (= 8.0.1)
15
- nokogiri (>= 1.8.5)
16
- rack (>= 2.2.4)
17
- rack-session (>= 1.0.1)
18
- rack-test (>= 0.6.3)
19
- rails-dom-testing (~> 2.2)
20
- rails-html-sanitizer (~> 1.6)
21
- useragent (~> 0.16)
22
- actionview (8.0.1)
23
- activesupport (= 8.0.1)
24
- builder (~> 3.1)
25
- erubi (~> 1.11)
26
- rails-dom-testing (~> 2.2)
27
- rails-html-sanitizer (~> 1.6)
28
- activesupport (8.0.1)
29
- base64
30
- benchmark (>= 0.3)
31
- bigdecimal
32
- concurrent-ruby (~> 1.0, >= 1.3.1)
33
- connection_pool (>= 2.2.5)
34
- drb
35
- i18n (>= 1.6, < 2)
36
- logger (>= 1.4.2)
37
- minitest (>= 5.1)
38
- securerandom (>= 0.3)
39
- tzinfo (~> 2.0, >= 2.0.5)
40
- uri (>= 0.13.1)
41
12
  ansi (1.5.0)
42
- ast (2.4.2)
13
+ ast (2.4.3)
43
14
  backtrace (0.4.0)
44
- base64 (0.2.0)
45
- benchmark (0.4.0)
46
- bigdecimal (3.1.9)
47
15
  builder (3.3.0)
48
- concurrent-ruby (1.3.5)
49
- connection_pool (2.5.0)
50
- crass (1.0.6)
51
- date (3.4.1)
52
- diff-lcs (1.5.1)
53
16
  docile (1.4.1)
54
- drb (2.2.1)
55
17
  elapsed (0.0.1)
56
18
  loog (> 0)
57
19
  tago (> 0)
58
- erubi (1.13.1)
59
- i18n (1.14.7)
60
- concurrent-ruby (~> 1.0)
61
- io-console (0.8.0)
62
- irb (1.15.1)
63
- pp (>= 0.6.0)
64
- rdoc (>= 4.0.0)
65
- reline (>= 0.4.2)
66
- json (2.9.1)
20
+ json (2.10.2)
67
21
  language_server-protocol (3.17.0.4)
68
- logger (1.6.5)
69
- loofah (2.24.0)
70
- crass (~> 1.0.2)
71
- nokogiri (>= 1.12.0)
22
+ lint_roller (1.1.0)
72
23
  loog (0.6.0)
73
- minitest (5.25.4)
24
+ minitest (5.25.5)
74
25
  minitest-reporters (1.7.1)
75
26
  ansi
76
27
  builder
@@ -78,103 +29,48 @@ GEM
78
29
  ruby-progressbar
79
30
  minitest-retry (0.2.5)
80
31
  minitest (>= 5.0)
81
- nokogiri (1.18.2-arm64-darwin)
82
- racc (~> 1.4)
83
- nokogiri (1.18.2-x64-mingw-ucrt)
84
- racc (~> 1.4)
85
- nokogiri (1.18.2-x86_64-darwin)
86
- racc (~> 1.4)
87
- nokogiri (1.18.2-x86_64-linux-gnu)
88
- racc (~> 1.4)
89
32
  os (1.1.4)
90
- parallel (1.26.3)
91
- parser (3.3.7.1)
33
+ parallel (1.27.0)
34
+ parser (3.3.8.0)
92
35
  ast (~> 2.4.1)
93
36
  racc
94
- pp (0.6.2)
95
- prettyprint
96
- prettyprint (0.2.0)
97
- psych (5.2.3)
98
- date
99
- stringio
100
- qbash (0.3.2)
37
+ prism (1.4.0)
38
+ qbash (0.4.0)
101
39
  backtrace (> 0)
102
40
  elapsed (> 0)
103
41
  loog (> 0)
104
42
  tago (> 0)
105
43
  racc (1.8.1)
106
- rack (3.1.9)
107
- rack-session (2.1.0)
108
- base64 (>= 0.1.0)
109
- rack (>= 3.0.0)
110
- rack-test (2.2.0)
111
- rack (>= 1.3)
112
- rackup (2.2.1)
113
- rack (>= 3)
114
- rails-dom-testing (2.2.0)
115
- activesupport (>= 5.0.0)
116
- minitest
117
- nokogiri (>= 1.6)
118
- rails-html-sanitizer (1.6.2)
119
- loofah (~> 2.21)
120
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
121
- railties (8.0.1)
122
- actionpack (= 8.0.1)
123
- activesupport (= 8.0.1)
124
- irb (~> 1.13)
125
- rackup (>= 1.0.0)
126
- rake (>= 12.2)
127
- thor (~> 1.0, >= 1.2.2)
128
- zeitwerk (~> 2.6)
129
44
  rainbow (3.1.1)
130
45
  rake (13.2.1)
131
- rdoc (6.11.0)
132
- psych (>= 4.0.0)
133
46
  regexp_parser (2.10.0)
134
- reline (0.6.0)
135
- io-console (~> 0.5)
136
- rexml (3.4.0)
137
- rspec-core (3.13.3)
138
- rspec-support (~> 3.13.0)
139
- rspec-expectations (3.13.3)
140
- diff-lcs (>= 1.2.0, < 2.0)
141
- rspec-support (~> 3.13.0)
142
- rspec-mocks (3.13.2)
143
- diff-lcs (>= 1.2.0, < 2.0)
144
- rspec-support (~> 3.13.0)
145
- rspec-rails (7.1.1)
146
- actionpack (>= 7.0)
147
- activesupport (>= 7.0)
148
- railties (>= 7.0)
149
- rspec-core (~> 3.13)
150
- rspec-expectations (~> 3.13)
151
- rspec-mocks (~> 3.13)
152
- rspec-support (~> 3.13)
153
- rspec-support (3.13.2)
154
- rubocop (1.71.2)
47
+ rexml (3.4.1)
48
+ rubocop (1.75.3)
155
49
  json (~> 2.3)
156
- language_server-protocol (>= 3.17.0)
50
+ language_server-protocol (~> 3.17.0.2)
51
+ lint_roller (~> 1.1.0)
157
52
  parallel (~> 1.10)
158
53
  parser (>= 3.3.0.2)
159
54
  rainbow (>= 2.2.2, < 4.0)
160
55
  regexp_parser (>= 2.9.3, < 3.0)
161
- rubocop-ast (>= 1.38.0, < 2.0)
56
+ rubocop-ast (>= 1.44.0, < 2.0)
162
57
  ruby-progressbar (~> 1.7)
163
58
  unicode-display_width (>= 2.4.0, < 4.0)
164
- rubocop-ast (1.38.0)
165
- parser (>= 3.3.1.0)
166
- rubocop-minitest (0.36.0)
167
- rubocop (>= 1.61, < 2.0)
168
- rubocop-ast (>= 1.31.1, < 2.0)
169
- rubocop-performance (1.23.1)
170
- rubocop (>= 1.48.1, < 2.0)
171
- rubocop-ast (>= 1.31.1, < 2.0)
172
- rubocop-rake (0.6.0)
173
- rubocop (~> 1.0)
174
- rubocop-rspec (3.4.0)
175
- rubocop (~> 1.61)
59
+ rubocop-ast (1.44.1)
60
+ parser (>= 3.3.7.2)
61
+ prism (~> 1.4)
62
+ rubocop-minitest (0.38.0)
63
+ lint_roller (~> 1.1)
64
+ rubocop (>= 1.75.0, < 2.0)
65
+ rubocop-ast (>= 1.38.0, < 2.0)
66
+ rubocop-performance (1.25.0)
67
+ lint_roller (~> 1.1)
68
+ rubocop (>= 1.75.0, < 2.0)
69
+ rubocop-ast (>= 1.38.0, < 2.0)
70
+ rubocop-rake (0.7.1)
71
+ lint_roller (~> 1.1)
72
+ rubocop (>= 1.72.1)
176
73
  ruby-progressbar (1.13.0)
177
- securerandom (0.4.1)
178
74
  simplecov (0.22.0)
179
75
  docile (~> 1.1)
180
76
  simplecov-html (~> 0.11)
@@ -184,44 +80,32 @@ GEM
184
80
  simplecov (~> 0.19)
185
81
  simplecov-html (0.13.1)
186
82
  simplecov_json_formatter (0.1.4)
187
- stringio (3.1.2)
188
- tago (0.0.2)
189
- thor (1.3.2)
190
- tzinfo (2.0.6)
191
- concurrent-ruby (~> 1.0)
83
+ tago (0.1.0)
192
84
  unicode-display_width (3.1.4)
193
85
  unicode-emoji (~> 4.0, >= 4.0.4)
194
86
  unicode-emoji (4.0.4)
195
- uri (1.0.2)
196
- useragent (0.16.11)
197
87
  yard (0.9.37)
198
- zeitwerk (2.7.1)
199
88
 
200
89
  PLATFORMS
201
- arm64-darwin-22
202
90
  arm64-darwin-23
203
91
  arm64-darwin-24
92
+ ruby
204
93
  x64-mingw-ucrt
205
- x86_64-darwin-20
206
- x86_64-darwin-21
207
- x86_64-linux
208
94
 
209
95
  DEPENDENCIES
210
96
  donce!
211
97
  loog (> 0)
212
- minitest (= 5.25.4)
213
- minitest-reporters (= 1.7.1)
214
- minitest-retry (= 0.2.5)
215
- rake (= 13.2.1)
216
- rspec-rails (= 7.1.1)
217
- rubocop (= 1.71.2)
218
- rubocop-minitest (= 0.36.0)
219
- rubocop-performance (= 1.23.1)
98
+ minitest (~> 5.25)
99
+ minitest-reporters (~> 1.7)
100
+ minitest-retry (~> 0.2)
101
+ rake (~> 13.2)
102
+ rubocop (~> 1.75)
103
+ rubocop-minitest (> 0)
104
+ rubocop-performance (> 0)
220
105
  rubocop-rake (> 0)
221
- rubocop-rspec (= 3.4.0)
222
- simplecov (= 0.22.0)
223
- simplecov-cobertura (= 2.1.0)
224
- yard (= 0.9.37)
106
+ simplecov (~> 0.22)
107
+ simplecov-cobertura (~> 2.1)
108
+ yard (~> 0.9)
225
109
 
226
110
  BUNDLED WITH
227
111
  2.5.16
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2025 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # Builds Docker image, runs it, and kills
2
2
 
3
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/donce)](http://www.rultor.com/p/yegor256/donce)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/donce)](https://www.rultor.com/p/yegor256/donce)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/donce/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/donce/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/donce)](http://www.0pdd.com/p?name=yegor256/donce)
8
- [![Gem Version](https://badge.fury.io/rb/donce.svg)](http://badge.fury.io/rb/donce)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/donce)](https://www.0pdd.com/p?name=yegor256/donce)
8
+ [![Gem Version](https://badge.fury.io/rb/donce.svg)](https://badge.fury.io/rb/donce)
9
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/donce.svg)](https://codecov.io/github/yegor256/donce?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/donce/master/frames)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/donce/master/frames)
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/donce)](https://hitsofcode.com/view/github/yegor256/donce)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/donce/blob/master/LICENSE.txt)
13
13
 
14
- This small Ruby library helps building temporary [Docker]
14
+ This small Ruby library helps to build temporary [Docker]
15
15
  images, runs Docker containers, and cleans up afterwards — it may be
16
16
  convenient for automated tests (for example, with [Minitest]):
17
17
 
@@ -38,15 +38,33 @@ stdout = donce(image: 'ubuntu', command: 'sleep 9999') do |id|
38
38
  end
39
39
  ```
40
40
 
41
- That's it.
41
+ ## Parameters
42
+
43
+ Here's a list of the available parameters for `donce`:
44
+
45
+ * `dockerfile`: Content of the Dockerfile (string or array of strings)
46
+ * `home`: Directory with Dockerfile and all other necessary files
47
+ * `image`: Name of a Docker image to use (e.g. "ubuntu:22.04")
48
+ * `log`: Logging destination (defaults to $stdout)
49
+ * `args`: Extra arguments for the docker command
50
+ * `env`: Environment variables mapping for the container
51
+ * `volumes`: Local to container volumes mapping
52
+ * `ports`: Local to container port mapping
53
+ * `build_args`: Arguments for docker build (--build-arg)
54
+ * `root`: Let user inside the container be "root" (default: false)
55
+ * `command`: The command to execute in the container
56
+ * `timeout`: Maximum seconds to spend on each docker call (default: 10)
57
+
58
+ The function `donce_host()` returns the hostname of the host machine that
59
+ can be used from within the container.
42
60
 
43
61
  ## How to contribute
44
62
 
45
63
  Read
46
64
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
47
- Make sure you build is green before you contribute
65
+ Make sure your build is green before you contribute
48
66
  your pull request. You will need to have
49
- [Ruby](https://www.ruby-lang.org/en/) 3.2+ and
67
+ [Ruby](https://www.ruby-lang.org/en/) 3.0+ and
50
68
  [Bundler](https://bundler.io/) installed. Then:
51
69
 
52
70
  ```bash
data/REUSE.toml ADDED
@@ -0,0 +1,34 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ "**.json",
8
+ "**.md",
9
+ "**.txt",
10
+ "**/*.csv",
11
+ "**/*.jpg",
12
+ "**/*.json",
13
+ "**/*.md",
14
+ "**/*.pdf",
15
+ "**/*.png",
16
+ "**/*.svg",
17
+ "**/*.txt",
18
+ "**/*.vm",
19
+ "**/.DS_Store",
20
+ "**/.gitignore",
21
+ "**/.pdd",
22
+ "**/CNAME",
23
+ "**/Gemfile.lock",
24
+ ".DS_Store",
25
+ ".gitattributes",
26
+ ".gitignore",
27
+ ".pdd",
28
+ "Gemfile.lock",
29
+ "README.md",
30
+ "renovate.json",
31
+ ]
32
+ precedence = "override"
33
+ SPDX-FileCopyrightText = "Copyright (c) 2024-2025 Yegor Bugayenko"
34
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2025 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'rubygems'
24
7
  require 'rake'
@@ -54,10 +37,4 @@ require 'rubocop/rake_task'
54
37
  desc 'Run RuboCop on all directories'
55
38
  RuboCop::RakeTask.new(:rubocop) do |task|
56
39
  task.fail_on_error = true
57
- task.requires << 'rubocop-rspec'
58
- end
59
-
60
- desc 'Run benchmark script'
61
- task :benchmark do
62
- ruby 'benchmarks/simple.rb'
63
40
  end
data/donce.gemspec CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2025 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'English'
24
7
 
@@ -26,7 +9,7 @@ Gem::Specification.new do |s|
26
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
10
  s.required_ruby_version = '>=3.0'
28
11
  s.name = 'donce'
29
- s.version = '0.1.0'
12
+ s.version = '0.2.1'
30
13
  s.license = 'MIT'
31
14
  s.summary = 'Builds and starts temporary Docker containers'
32
15
  s.description =
@@ -35,15 +18,15 @@ Gem::Specification.new do |s|
35
18
  'up, deleting them both. This may be helpful for automated testing, ' \
36
19
  'when you test how your code might behave in an isolated environment. ' \
37
20
  'This may also be helpful when you need a custom Docker image with a ' \
38
- 'tool inside, but Testcontainers don\' have such an image.'
21
+ 'tool inside, but Testcontainers don\'t have such an image.'
39
22
  s.authors = ['Yegor Bugayenko']
40
23
  s.email = 'yegor256@gmail.com'
41
24
  s.homepage = 'http://github.com/yegor256/donce.rb'
42
25
  s.files = `git ls-files`.split($RS)
43
26
  s.rdoc_options = ['--charset=UTF-8']
44
27
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
- s.add_dependency 'backtrace', '>0'
46
- s.add_dependency 'os', '>0'
47
- s.add_dependency 'qbash', '>0'
28
+ s.add_dependency 'backtrace', '~> 0.3'
29
+ s.add_dependency 'os', '~> 1.1'
30
+ s.add_dependency 'qbash', '~> 0.3'
48
31
  s.metadata['rubygems_mfa_required'] = 'true'
49
32
  end
data/lib/donce.rb CHANGED
@@ -1,30 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2025 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'logger'
24
7
  require 'os'
25
8
  require 'qbash'
26
9
  require 'securerandom'
27
10
  require 'shellwords'
11
+ require 'timeout'
12
+ require 'tmpdir'
28
13
 
29
14
  # Execute Docker container and clean up afterwards.
30
15
  #
@@ -57,7 +42,7 @@ require 'shellwords'
57
42
  # variable to any value.
58
43
  #
59
44
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
60
- # Copyright:: Copyright (c) 2025 Yegor Bugayenko
45
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
61
46
  # License:: MIT
62
47
  module Kernel
63
48
  # The name of the localhost inside Docker container.
@@ -70,7 +55,7 @@ module Kernel
70
55
  #
71
56
  # @param [String] dockerfile The content of the +Dockerfile+ (if array is provided, it will be concatenated)
72
57
  # @param [String] home The directory with Dockerfile and all other necessary files
73
- # @param [String] image The name of Docker image, e.g. "ubuntu:24.04"
58
+ # @param [String] image The name of Docker image, e.g. "ubuntu:22.04"
74
59
  # @param [Logger] log The logging destination, can be +$stdout+
75
60
  # @param [String|Array<String>] args List of extra arguments for the +docker+ command
76
61
  # @param [Hash<String,String>] env Environment variables going into the container
@@ -82,11 +67,12 @@ module Kernel
82
67
  # @param [Integer] timeout Maximum seconds to spend on each +docker+ call
83
68
  # @return [String] The stdout of the container
84
69
  def donce(dockerfile: nil, image: nil, home: nil, log: $stdout, args: '', env: {}, root: false, command: '',
85
- timeout: 10, volumes: {}, ports: {}, build_args: {})
70
+ timeout: 60, volumes: {}, ports: {}, build_args: {})
86
71
  raise 'Either use "dockerfile" or "home"' if dockerfile && home
87
72
  raise 'Either use "dockerfile" or "image"' if dockerfile && image
88
73
  raise 'Either use "image" or "home"' if home && image
89
74
  raise 'Either "dockerfile", or "home", or "image" must be provided' if !dockerfile && !home && !image
75
+ raise 'The "timeout" must be an integer or nil' unless timeout.nil? || timeout.is_a?(Integer)
90
76
  docker = ENV['DONCE_SUDO'] ? 'sudo docker' : 'docker'
91
77
  img =
92
78
  if image
@@ -96,7 +82,7 @@ module Kernel
96
82
  a = [
97
83
  "--tag #{i}",
98
84
  build_args.map { |k, v| "--build-arg #{Shellwords.escape("#{k}=#{v}")}" }.join(' ')
99
- ].join(' ')
85
+ ].compact.join(' ')
100
86
  if dockerfile
101
87
  Dir.mktmpdir do |tmp|
102
88
  dockerfile = dockerfile.join("\n") if dockerfile.is_a?(Array)
@@ -114,20 +100,20 @@ module Kernel
114
100
  begin
115
101
  stdout = nil
116
102
  code = 0
103
+ cmd = [
104
+ docker, 'run',
105
+ ('--detach' if block_given?),
106
+ '--name', Shellwords.escape(container),
107
+ ("--add-host #{donce_host}:host-gateway" if OS.linux?),
108
+ args,
109
+ env.map { |k, v| "--env #{Shellwords.escape("#{k}=#{v}")}" }.join(' '),
110
+ ports.map { |k, v| "--publish #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
111
+ volumes.map { |k, v| "--volume #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
112
+ ("--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}" if root),
113
+ Shellwords.escape(img),
114
+ command
115
+ ].compact.join(' ')
117
116
  begin
118
- cmd = [
119
- docker, 'run',
120
- block_given? ? '--detach' : nil,
121
- '--name', Shellwords.escape(container),
122
- OS.linux? ? nil : "--add-host #{donce_host}:host-gateway",
123
- args,
124
- env.map { |k, v| "--env #{Shellwords.escape("#{k}=#{v}")}" }.join(' '),
125
- ports.map { |k, v| "--publish #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
126
- volumes.map { |k, v| "--volume #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
127
- root ? nil : "--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}",
128
- Shellwords.escape(img),
129
- command
130
- ].compact.join(' ')
131
117
  stdout, code =
132
118
  Timeout.timeout(timeout) do
133
119
  qbash(
data/test/test__helper.rb CHANGED
@@ -1,36 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2025 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  $stdout.sync = true
24
7
 
25
8
  require 'simplecov'
26
- SimpleCov.external_at_exit = true
27
- SimpleCov.start
28
-
29
9
  require 'simplecov-cobertura'
30
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
10
+ unless SimpleCov.running
11
+ SimpleCov.command_name('test')
12
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
13
+ [
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ SimpleCov::Formatter::CoberturaFormatter
16
+ ]
17
+ )
18
+ SimpleCov.minimum_coverage 80
19
+ SimpleCov.minimum_coverage_by_file 80
20
+ SimpleCov.start do
21
+ add_filter 'test/'
22
+ add_filter 'vendor/'
23
+ add_filter 'target/'
24
+ track_files 'lib/**/*.rb'
25
+ track_files '*.rb'
26
+ end
27
+ end
31
28
 
32
29
  require 'minitest/autorun'
33
-
34
30
  require 'minitest/reporters'
35
31
  Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
36
32