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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/donce.gemspec +1 -1
  3. data/lib/donce.rb +9 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87e27e95378a5ad34a9ba6a7ef7c8578efb3d24990998beada04097c1a46d5c1
4
- data.tar.gz: 0ea31ae8977024be7abdbc164a3250a8eb907511ea24b5427b2eb3f8960b2912
3
+ metadata.gz: 44c678f3ea8b379cf1d76ef37954ad59a3b4bb508001576972b799196859f547
4
+ data.tar.gz: a669642f9ddc4a45e04f8d00f9a2bda74fd2ae62f40717626b1ab2fd992f627a
5
5
  SHA512:
6
- metadata.gz: df41062bb8aea186f7bafc2df0070d7abbf1238d2eea5270f49a62e1901a495b0d50afca4659b5314ea0ea0117a299241b8757369a07b5e384cd8595abf956f2
7
- data.tar.gz: 2d6de2cde5d5df5dc3048bb7e9d68cc8b866ec76842f9ce7f9441a4b3b1f683a58e65428c558244c02ab2bcf1a6760606f1e63cea7a7c1a77f08778a18c59fd4
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.4'
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? ? '' : "--add-host #{donce_host}:host-gateway",
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
- root ? '' : "--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}",
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(
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko