donce 0.4.0 → 0.6.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/Gemfile.lock +10 -8
- data/donce.gemspec +1 -1
- data/lib/donce.rb +23 -18
- 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: 794fd321c85b3efd46c082e5555c69dfe4d97cd2eaed233b812f50dfb4453f47
|
|
4
|
+
data.tar.gz: b8f59039bc21dc5e585ebba73bf825fdcfb30d249f77879d0e50666c9b5514c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: babea47d7f7d8b6c13541102167cea6b88e9e48be2d2233535b417cfd0144946a04a710b64eebd4ecffa894e3c88320e1def531f33d2d406ca5f9cbb4f867e26
|
|
7
|
+
data.tar.gz: fc734444357b9b2e7a6cd4b460b5ccad6f6316fee65f182345e0b2143e1b7398fa96fc64eba08759744fe4a528ed17be48ae0c0e26b830a8c7a327dbf439c905
|
data/Gemfile.lock
CHANGED
|
@@ -15,15 +15,17 @@ GEM
|
|
|
15
15
|
builder (3.3.0)
|
|
16
16
|
date (3.5.1)
|
|
17
17
|
docile (1.4.1)
|
|
18
|
-
elapsed (0.2.
|
|
18
|
+
elapsed (0.2.2)
|
|
19
19
|
loog (~> 0.6)
|
|
20
20
|
tago (~> 0.1)
|
|
21
|
+
ellipsized (0.3.0)
|
|
21
22
|
erb (6.0.1)
|
|
22
23
|
json (2.18.0)
|
|
23
24
|
language_server-protocol (3.17.0.5)
|
|
24
25
|
lint_roller (1.1.0)
|
|
25
26
|
logger (1.7.0)
|
|
26
|
-
loog (0.
|
|
27
|
+
loog (0.7.2)
|
|
28
|
+
ellipsized
|
|
27
29
|
logger (~> 1.0)
|
|
28
30
|
minitest (6.0.1)
|
|
29
31
|
prism (~> 1.5)
|
|
@@ -32,18 +34,18 @@ GEM
|
|
|
32
34
|
builder
|
|
33
35
|
minitest (>= 5.0)
|
|
34
36
|
ruby-progressbar
|
|
35
|
-
minitest-retry (0.3.
|
|
37
|
+
minitest-retry (0.3.1)
|
|
36
38
|
minitest (>= 5.0)
|
|
37
39
|
os (1.1.4)
|
|
38
40
|
parallel (1.27.0)
|
|
39
|
-
parser (3.3.10.
|
|
41
|
+
parser (3.3.10.1)
|
|
40
42
|
ast (~> 2.4.1)
|
|
41
43
|
racc
|
|
42
|
-
prism (1.
|
|
44
|
+
prism (1.8.0)
|
|
43
45
|
psych (5.3.1)
|
|
44
46
|
date
|
|
45
47
|
stringio
|
|
46
|
-
qbash (0.
|
|
48
|
+
qbash (0.7.1)
|
|
47
49
|
backtrace (> 0)
|
|
48
50
|
elapsed (> 0)
|
|
49
51
|
loog (> 0)
|
|
@@ -51,7 +53,7 @@ GEM
|
|
|
51
53
|
racc (1.8.1)
|
|
52
54
|
rainbow (3.1.1)
|
|
53
55
|
rake (13.3.1)
|
|
54
|
-
rdoc (7.0
|
|
56
|
+
rdoc (7.1.0)
|
|
55
57
|
erb
|
|
56
58
|
psych (>= 4.0.0)
|
|
57
59
|
tsort
|
|
@@ -93,7 +95,7 @@ GEM
|
|
|
93
95
|
simplecov-html (0.13.2)
|
|
94
96
|
simplecov_json_formatter (0.1.4)
|
|
95
97
|
stringio (3.2.0)
|
|
96
|
-
tago (0.
|
|
98
|
+
tago (0.7.0)
|
|
97
99
|
tsort (0.2.0)
|
|
98
100
|
unicode-display_width (3.2.0)
|
|
99
101
|
unicode-emoji (~> 4.1)
|
data/donce.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
10
10
|
s.required_ruby_version = '>=3.0'
|
|
11
11
|
s.name = 'donce'
|
|
12
|
-
s.version = '0.
|
|
12
|
+
s.version = '0.6.0'
|
|
13
13
|
s.license = 'MIT'
|
|
14
14
|
s.summary = 'Builds and starts temporary Docker containers'
|
|
15
15
|
s.description =
|
data/lib/donce.rb
CHANGED
|
@@ -57,7 +57,8 @@ module Kernel
|
|
|
57
57
|
# (if array is provided, it will be concatenated)
|
|
58
58
|
# @param [String] home The directory with Dockerfile and all other necessary files
|
|
59
59
|
# @param [String] image The name of Docker image, e.g. "ubuntu:22.04"
|
|
60
|
-
# @param [
|
|
60
|
+
# @param [IO] stdout The stdout destination
|
|
61
|
+
# @param [IO] stderr The stderr destination
|
|
61
62
|
# @param [String|Array<String>] args List of extra arguments for the +docker+ command
|
|
62
63
|
# @param [Hash<String,String>] env Environment variables going into the container
|
|
63
64
|
# @param [Hash<String,String>] volumes Local to container volumes mapping
|
|
@@ -70,8 +71,8 @@ module Kernel
|
|
|
70
71
|
# @yield [String] Container ID if block is given (runs container in daemon mode)
|
|
71
72
|
# @yieldparam [String] id The ID of the running container
|
|
72
73
|
# @yieldreturn [void] The container will be stopped after the block execution
|
|
73
|
-
def donce(dockerfile: nil, image: nil, home: nil,
|
|
74
|
-
timeout: 60, volumes: {}, ports: {}, build_args: {})
|
|
74
|
+
def donce(dockerfile: nil, image: nil, home: nil, stdout: $stdout, stderr: $stdout, args: '', env: {}, root: false,
|
|
75
|
+
command: '', timeout: 60, volumes: {}, ports: {}, build_args: {})
|
|
75
76
|
raise 'Either use "dockerfile" or "home"' if dockerfile && home
|
|
76
77
|
raise 'Either use "dockerfile" or "image"' if dockerfile && image
|
|
77
78
|
raise 'Either use "image" or "home"' if home && image
|
|
@@ -79,9 +80,11 @@ module Kernel
|
|
|
79
80
|
raise 'The "timeout" must be an integer or nil' unless timeout.nil? || timeout.is_a?(Integer)
|
|
80
81
|
raise 'The "volumes" is nil' if volumes.nil?
|
|
81
82
|
raise 'The "volumes" must be a Hash' unless volumes.is_a?(Hash)
|
|
82
|
-
raise 'The "
|
|
83
|
+
raise 'The "stdout" is nil' if stdout.nil?
|
|
84
|
+
raise 'The "stderr" is nil' if stderr.nil?
|
|
83
85
|
raise 'The "args" is nil' if args.nil?
|
|
84
|
-
raise 'The "args" must be a String' unless args.is_a?(String)
|
|
86
|
+
raise 'The "args" must be a String or Array' unless args.is_a?(String) || args.is_a?(Array)
|
|
87
|
+
args = args.join(' ') if args.is_a?(Array)
|
|
85
88
|
raise 'The "env" is nil' if env.nil?
|
|
86
89
|
raise 'The "env" must be a Hash' unless env.is_a?(Hash)
|
|
87
90
|
raise 'The "command" is nil' if command.nil?
|
|
@@ -110,20 +113,21 @@ module Kernel
|
|
|
110
113
|
Dir.mktmpdir do |tmp|
|
|
111
114
|
dockerfile = dockerfile.join("\n") if dockerfile.is_a?(Array)
|
|
112
115
|
File.write(File.join(tmp, 'Dockerfile'), dockerfile)
|
|
113
|
-
qbash("#{docker} build #{a} #{Shellwords.escape(tmp)}",
|
|
116
|
+
qbash("#{docker} build #{a} #{Shellwords.escape(tmp)}", stdout:, stderr:)
|
|
114
117
|
end
|
|
115
118
|
elsif home
|
|
116
|
-
qbash("#{docker} build #{a} #{Shellwords.escape(home)}",
|
|
119
|
+
qbash("#{docker} build #{a} #{Shellwords.escape(home)}", stdout:, stderr:)
|
|
117
120
|
else
|
|
118
121
|
raise 'Either "dockerfile" or "home" must be provided'
|
|
119
122
|
end
|
|
120
123
|
i
|
|
121
124
|
end
|
|
122
125
|
container = "donce-#{SecureRandom.hex(6)}"
|
|
123
|
-
|
|
126
|
+
out = nil
|
|
124
127
|
code = 0
|
|
125
128
|
cmd = [
|
|
126
|
-
docker,
|
|
129
|
+
docker,
|
|
130
|
+
'run',
|
|
127
131
|
('--detach' if block_given?),
|
|
128
132
|
'--name', Shellwords.escape(container),
|
|
129
133
|
("--add-host #{donce_host}:host-gateway" unless OS.linux?),
|
|
@@ -137,36 +141,37 @@ module Kernel
|
|
|
137
141
|
].compact.join(' ')
|
|
138
142
|
begin
|
|
139
143
|
begin
|
|
140
|
-
|
|
144
|
+
out, code =
|
|
141
145
|
Timeout.timeout(timeout) do
|
|
142
146
|
qbash(
|
|
143
147
|
cmd,
|
|
144
|
-
|
|
148
|
+
stdout:,
|
|
149
|
+
stderr:,
|
|
145
150
|
accept: nil,
|
|
146
151
|
both: true,
|
|
147
152
|
env:
|
|
148
153
|
)
|
|
149
154
|
end
|
|
150
155
|
unless code.zero?
|
|
151
|
-
log.error(stdout)
|
|
152
156
|
raise \
|
|
153
157
|
"Failed to run #{cmd} " \
|
|
154
|
-
"(exit code is ##{code}, stdout has #{
|
|
158
|
+
"(exit code is ##{code}, stdout has #{out.split("\n").count} lines)"
|
|
155
159
|
end
|
|
156
160
|
yield container if block_given?
|
|
157
161
|
ensure
|
|
158
162
|
logs = qbash(
|
|
159
163
|
"#{docker} logs #{Shellwords.escape(container)}",
|
|
160
164
|
level: code.zero? ? Logger::DEBUG : Logger::ERROR,
|
|
161
|
-
|
|
165
|
+
stdout:,
|
|
166
|
+
stderr:
|
|
162
167
|
)
|
|
163
|
-
|
|
164
|
-
qbash("#{docker} rm --force #{Shellwords.escape(container)}",
|
|
168
|
+
out = logs if block_given?
|
|
169
|
+
qbash("#{docker} rm --force #{Shellwords.escape(container)}", stdout:, stderr:)
|
|
165
170
|
end
|
|
166
|
-
|
|
171
|
+
out
|
|
167
172
|
ensure
|
|
168
173
|
Timeout.timeout(10) do
|
|
169
|
-
qbash("#{docker} rmi #{img}",
|
|
174
|
+
qbash("#{docker} rmi #{img}", stdout:, stderr:) unless image
|
|
170
175
|
end
|
|
171
176
|
end
|
|
172
177
|
end
|