donce 0.0.5 → 0.2.0
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/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +3 -20
- data/.github/workflows/codecov.yml +4 -20
- data/.github/workflows/copyrights.yml +3 -19
- data/.github/workflows/markdown-lint.yml +3 -19
- data/.github/workflows/pdd.yml +3 -19
- data/.github/workflows/rake.yml +4 -20
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/xcop.yml +3 -19
- data/.github/workflows/yamllint.yml +3 -19
- data/.gitignore +7 -5
- data/.rubocop.yml +4 -20
- data/.rultor.yml +4 -20
- data/.yamllint.yml +2 -19
- data/Gemfile +13 -31
- data/Gemfile.lock +45 -157
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +22 -4
- data/REUSE.toml +34 -0
- data/Rakefile +2 -24
- data/donce.gemspec +7 -24
- data/lib/donce.rb +24 -30
- data/test/test__helper.rb +20 -24
- data/test/test_donce.rb +39 -22
- metadata +19 -20
- data/.simplecov +0 -39
data/Gemfile.lock
CHANGED
@@ -2,75 +2,26 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
donce (0.0.0)
|
5
|
-
backtrace (
|
6
|
-
os (
|
7
|
-
qbash (
|
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.
|
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
|
-
|
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
|
-
|
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.
|
24
|
+
minitest (5.25.5)
|
74
25
|
minitest-reporters (1.7.1)
|
75
26
|
ansi
|
76
27
|
builder
|
@@ -78,103 +29,51 @@ 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
33
|
parallel (1.26.3)
|
91
|
-
parser (3.3.7.
|
34
|
+
parser (3.3.7.4)
|
92
35
|
ast (~> 2.4.1)
|
93
36
|
racc
|
94
|
-
|
95
|
-
|
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
|
-
|
135
|
-
|
136
|
-
rexml (3.4.0)
|
137
|
-
rspec-core (3.13.2)
|
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.0)
|
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.2)
|
155
49
|
json (~> 2.3)
|
156
|
-
language_server-protocol (
|
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.
|
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.
|
165
|
-
parser (>= 3.3.
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
rubocop (>= 1.
|
171
|
-
|
172
|
-
|
173
|
-
rubocop (
|
174
|
-
|
175
|
-
|
59
|
+
rubocop-ast (1.44.0)
|
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)
|
73
|
+
rubocop-rspec (3.5.0)
|
74
|
+
lint_roller (~> 1.1)
|
75
|
+
rubocop (~> 1.72, >= 1.72.1)
|
176
76
|
ruby-progressbar (1.13.0)
|
177
|
-
securerandom (0.4.1)
|
178
77
|
simplecov (0.22.0)
|
179
78
|
docile (~> 1.1)
|
180
79
|
simplecov-html (~> 0.11)
|
@@ -184,44 +83,33 @@ GEM
|
|
184
83
|
simplecov (~> 0.19)
|
185
84
|
simplecov-html (0.13.1)
|
186
85
|
simplecov_json_formatter (0.1.4)
|
187
|
-
|
188
|
-
tago (0.0.2)
|
189
|
-
thor (1.3.2)
|
190
|
-
tzinfo (2.0.6)
|
191
|
-
concurrent-ruby (~> 1.0)
|
86
|
+
tago (0.1.0)
|
192
87
|
unicode-display_width (3.1.4)
|
193
88
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
194
89
|
unicode-emoji (4.0.4)
|
195
|
-
uri (1.0.2)
|
196
|
-
useragent (0.16.11)
|
197
90
|
yard (0.9.37)
|
198
|
-
zeitwerk (2.7.1)
|
199
91
|
|
200
92
|
PLATFORMS
|
201
|
-
arm64-darwin-22
|
202
93
|
arm64-darwin-23
|
203
94
|
arm64-darwin-24
|
95
|
+
ruby
|
204
96
|
x64-mingw-ucrt
|
205
|
-
x86_64-darwin-20
|
206
|
-
x86_64-darwin-21
|
207
|
-
x86_64-linux
|
208
97
|
|
209
98
|
DEPENDENCIES
|
210
99
|
donce!
|
211
100
|
loog (> 0)
|
212
|
-
minitest (
|
213
|
-
minitest-reporters (
|
214
|
-
minitest-retry (
|
215
|
-
rake (
|
216
|
-
|
217
|
-
rubocop (
|
218
|
-
rubocop-
|
219
|
-
rubocop-performance (= 1.23.1)
|
101
|
+
minitest (~> 5.25)
|
102
|
+
minitest-reporters (~> 1.7)
|
103
|
+
minitest-retry (~> 0.2)
|
104
|
+
rake (~> 13.2)
|
105
|
+
rubocop (~> 1.75)
|
106
|
+
rubocop-minitest (> 0)
|
107
|
+
rubocop-performance (> 0)
|
220
108
|
rubocop-rake (> 0)
|
221
|
-
rubocop-rspec (
|
222
|
-
simplecov (
|
223
|
-
simplecov-cobertura (
|
224
|
-
yard (
|
109
|
+
rubocop-rspec (> 0)
|
110
|
+
simplecov (~> 0.22)
|
111
|
+
simplecov-cobertura (~> 2.1)
|
112
|
+
yard (~> 0.9)
|
225
113
|
|
226
114
|
BUNDLED WITH
|
227
115
|
2.5.16
|
data/LICENSE.txt
CHANGED
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
@@ -11,7 +11,7 @@
|
|
11
11
|
[](https://hitsofcode.com/view/github/yegor256/donce)
|
12
12
|
[](https://github.com/yegor256/donce/blob/master/LICENSE.txt)
|
13
13
|
|
14
|
-
This small Ruby library helps
|
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
|
-
|
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
|
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.
|
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'
|
@@ -56,8 +39,3 @@ RuboCop::RakeTask.new(:rubocop) do |task|
|
|
56
39
|
task.fail_on_error = true
|
57
40
|
task.requires << 'rubocop-rspec'
|
58
41
|
end
|
59
|
-
|
60
|
-
desc 'Run benchmark script'
|
61
|
-
task :benchmark do
|
62
|
-
ruby 'benchmarks/simple.rb'
|
63
|
-
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.0
|
12
|
+
s.version = '0.2.0'
|
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', '
|
46
|
-
s.add_dependency 'os', '
|
47
|
-
s.add_dependency 'qbash', '
|
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.
|
@@ -68,37 +53,46 @@ module Kernel
|
|
68
53
|
|
69
54
|
# Build Docker image (or use existing one), run Docker container, and then clean up.
|
70
55
|
#
|
71
|
-
# @param [String] dockerfile The content of the +Dockerfile+
|
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:
|
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
|
77
62
|
# @param [Hash<String,String>] volumes Local to container volumes mapping
|
78
63
|
# @param [Hash<String,String>] ports Local to container port mapping
|
64
|
+
# @param [Hash<String,String>] build_args Arguments for +docker build+ as +--build-arg+ may need
|
79
65
|
# @param [Boolean] root Let user inside the container be "root"?
|
80
66
|
# @param [String|Array<String>] command The command for the script inside the container
|
81
67
|
# @param [Integer] timeout Maximum seconds to spend on each +docker+ call
|
82
68
|
# @return [String] The stdout of the container
|
83
69
|
def donce(dockerfile: nil, image: nil, home: nil, log: $stdout, args: '', env: {}, root: false, command: '',
|
84
|
-
timeout:
|
70
|
+
timeout: 60, volumes: {}, ports: {}, build_args: {})
|
85
71
|
raise 'Either use "dockerfile" or "home"' if dockerfile && home
|
86
72
|
raise 'Either use "dockerfile" or "image"' if dockerfile && image
|
87
73
|
raise 'Either use "image" or "home"' if home && image
|
88
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)
|
89
76
|
docker = ENV['DONCE_SUDO'] ? 'sudo docker' : 'docker'
|
90
77
|
img =
|
91
78
|
if image
|
92
79
|
image
|
93
80
|
else
|
94
81
|
i = "donce-#{SecureRandom.hex(6)}"
|
82
|
+
a = [
|
83
|
+
"--tag #{i}",
|
84
|
+
build_args.map { |k, v| "--build-arg #{Shellwords.escape("#{k}=#{v}")}" }.join(' ')
|
85
|
+
].join(' ')
|
95
86
|
if dockerfile
|
96
87
|
Dir.mktmpdir do |tmp|
|
88
|
+
dockerfile = dockerfile.join("\n") if dockerfile.is_a?(Array)
|
97
89
|
File.write(File.join(tmp, 'Dockerfile'), dockerfile)
|
98
|
-
qbash("#{docker} build #{Shellwords.escape(tmp)}
|
90
|
+
qbash("#{docker} build #{a} #{Shellwords.escape(tmp)}", log:)
|
99
91
|
end
|
92
|
+
elsif home
|
93
|
+
qbash("#{docker} build #{a} #{Shellwords.escape(home)}", log:)
|
100
94
|
else
|
101
|
-
|
95
|
+
raise 'Either "dockerfile" or "home" must be provided'
|
102
96
|
end
|
103
97
|
i
|
104
98
|
end
|
@@ -109,13 +103,13 @@ module Kernel
|
|
109
103
|
begin
|
110
104
|
cmd = [
|
111
105
|
docker, 'run',
|
112
|
-
block_given? ? '
|
106
|
+
block_given? ? '--detach' : nil,
|
113
107
|
'--name', Shellwords.escape(container),
|
114
108
|
OS.linux? ? nil : "--add-host #{donce_host}:host-gateway",
|
115
109
|
args,
|
116
|
-
env.map { |k, v| "
|
117
|
-
ports.map { |k, v| "
|
118
|
-
volumes.map { |k, v| "
|
110
|
+
env.map { |k, v| "--env #{Shellwords.escape("#{k}=#{v}")}" }.join(' '),
|
111
|
+
ports.map { |k, v| "--publish #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
|
112
|
+
volumes.map { |k, v| "--volume #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
|
119
113
|
root ? nil : "--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}",
|
120
114
|
Shellwords.escape(img),
|
121
115
|
command
|
@@ -144,7 +138,7 @@ module Kernel
|
|
144
138
|
log:
|
145
139
|
)
|
146
140
|
stdout = logs if block_given?
|
147
|
-
qbash("#{docker} rm
|
141
|
+
qbash("#{docker} rm --force #{Shellwords.escape(container)}", log:)
|
148
142
|
end
|
149
143
|
stdout
|
150
144
|
ensure
|
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.
|
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
|
|