donce 0.0.4 → 0.0.5
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/donce.gemspec +1 -1
- data/lib/donce.rb +9 -5
- 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: 44c678f3ea8b379cf1d76ef37954ad59a3b4bb508001576972b799196859f547
|
4
|
+
data.tar.gz: a669642f9ddc4a45e04f8d00f9a2bda74fd2ae62f40717626b1ab2fd992f627a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e66afd723eaef2ce89b2ec88418f9be91ef25ddbe0054015d707cdaf178086f68e0e78337c5305fbd752fc92434782212f61fe8e0f2f5bc8220c1f586668522
|
7
|
+
data.tar.gz: 819b0e6086390e483cb54b0b42ac007c2f2bdc0f39fd7170325abcfc53bc1cdd98b7df821474c46078401f5bc0d0faedb90e5e929b8a95202a049cfbd280a550
|
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.5'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Builds and starts temporary Docker containers'
|
32
32
|
s.description =
|
data/lib/donce.rb
CHANGED
@@ -74,12 +74,14 @@ module Kernel
|
|
74
74
|
# @param [Logger] log The logging destination, can be +$stdout+
|
75
75
|
# @param [String|Array<String>] args List of extra arguments for the +docker+ command
|
76
76
|
# @param [Hash<String,String>] env Environment variables going into the container
|
77
|
+
# @param [Hash<String,String>] volumes Local to container volumes mapping
|
78
|
+
# @param [Hash<String,String>] ports Local to container port mapping
|
77
79
|
# @param [Boolean] root Let user inside the container be "root"?
|
78
80
|
# @param [String|Array<String>] command The command for the script inside the container
|
79
81
|
# @param [Integer] timeout Maximum seconds to spend on each +docker+ call
|
80
82
|
# @return [String] The stdout of the container
|
81
83
|
def donce(dockerfile: nil, image: nil, home: nil, log: $stdout, args: '', env: {}, root: false, command: '',
|
82
|
-
timeout: 10)
|
84
|
+
timeout: 10, volumes: {}, ports: {})
|
83
85
|
raise 'Either use "dockerfile" or "home"' if dockerfile && home
|
84
86
|
raise 'Either use "dockerfile" or "image"' if dockerfile && image
|
85
87
|
raise 'Either use "image" or "home"' if home && image
|
@@ -107,15 +109,17 @@ module Kernel
|
|
107
109
|
begin
|
108
110
|
cmd = [
|
109
111
|
docker, 'run',
|
110
|
-
block_given? ? '-d' :
|
112
|
+
block_given? ? '-d' : nil,
|
111
113
|
'--name', Shellwords.escape(container),
|
112
|
-
OS.linux? ?
|
114
|
+
OS.linux? ? nil : "--add-host #{donce_host}:host-gateway",
|
113
115
|
args,
|
114
116
|
env.map { |k, v| "-e #{Shellwords.escape("#{k}=#{v}")}" }.join(' '),
|
115
|
-
|
117
|
+
ports.map { |k, v| "-p #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
|
118
|
+
volumes.map { |k, v| "-v #{Shellwords.escape("#{k}:#{v}")}" }.join(' '),
|
119
|
+
root ? nil : "--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}",
|
116
120
|
Shellwords.escape(img),
|
117
121
|
command
|
118
|
-
].join(' ')
|
122
|
+
].compact.join(' ')
|
119
123
|
stdout, code =
|
120
124
|
Timeout.timeout(timeout) do
|
121
125
|
qbash(
|