donce 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3870e1c444a1259a5cb5d3a2b32e73d66dba22e8bf1a519ba377d6a520d1637c
4
- data.tar.gz: d19607fe2d7090bfa106b5858e051442b5b7d48839b479ef2df49c8c38f90d2f
3
+ metadata.gz: 458248c2903f4159ae8e840d9f79173fa5cfccaea2ef74de4ec8896fa2204be6
4
+ data.tar.gz: 54e651309713b136eac4f40c77db3840aadb95e626cfe861ccfc0d76e50e06b8
5
5
  SHA512:
6
- metadata.gz: 85863c16fd11008e5fd302724ddd23314cd7519e10803292a39a58312a8371e8345509dac4878cab32afd5198bd65079e03f2f496b701635d84af619fe7bfc45
7
- data.tar.gz: 618eb11dd8880fbcdd08863fcfa332d7567bb1d405e6cf3e268398d6f3cb5123169867ecefe4a308e4b40d609bb03285593c4a98acea98437bb2f68d3b656ffd
6
+ metadata.gz: 407378f5c2d8285092e468c7472fdc778558a5b4525c37eba2226a49b2e10debbe4943338030fb351ac28f3b285b7adf480f26335d9ffd5b18458204d3053f01
7
+ data.tar.gz: 84a740834b4e6c4277c9680ea85c0c124c1fdbefc6c5af33146ba6a70360be0781be1dfbe466aa69414cd3af99e0c3b31abb0172ef531524871f2e160db60d4d
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.1'
29
+ s.version = '0.0.2'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Builds and starts temporary Docker containers'
32
32
  s.description =
data/lib/donce.rb CHANGED
@@ -48,9 +48,8 @@ require 'shellwords'
48
48
  # background execution of the container (in daemon mode):
49
49
  #
50
50
  # def test_runs_daemon
51
- # donce(dockerfile: "FROM ubuntu\nCMD sleep 9999") do |id, host|
51
+ # donce(dockerfile: "FROM ubuntu\nCMD sleep 9999") do |id|
52
52
  # refute_empty(id) # the ID of the container
53
- # refute_empty(host) # the hostname of it
54
53
  # end
55
54
  # end
56
55
  #
@@ -61,6 +60,12 @@ require 'shellwords'
61
60
  # Copyright:: Copyright (c) 2025 Yegor Bugayenko
62
61
  # License:: MIT
63
62
  module Kernel
63
+ # The name of the localhost inside Docker container.
64
+ # @return [String] The hostname
65
+ def donce_host
66
+ OS.linux? ? '172.17.0.1' : 'host.docker.internal'
67
+ end
68
+
64
69
  # Build Docker image (or use existing one), run Docker container, and then clean up.
65
70
  #
66
71
  # @param [String] dockerfile The content of the +Dockerfile+
@@ -72,6 +77,7 @@ module Kernel
72
77
  # @param [Boolean] root Let user inside the container be "root"?
73
78
  # @param [String|Array<String>] command The command for the script inside the container
74
79
  # @param [Integer] timeout Maximum seconds to spend on each +docker+ call
80
+ # @return [String] The stdout of the container
75
81
  def donce(dockerfile: nil, image: nil, home: nil, log: $stdout, args: '', env: {}, root: false, command: '',
76
82
  timeout: 10)
77
83
  raise 'Either use "dockerfile" or "home"' if dockerfile && home
@@ -93,7 +99,6 @@ module Kernel
93
99
  i
94
100
  end
95
101
  container = "donce-#{SecureRandom.hex(8)}"
96
- host = OS.linux? ? '172.17.0.1' : 'host.docker.internal'
97
102
  begin
98
103
  stdout = nil
99
104
  code = 0
@@ -102,7 +107,7 @@ module Kernel
102
107
  docker, 'run',
103
108
  block_given? ? '-d' : '',
104
109
  '--name', Shellwords.escape(container),
105
- OS.linux? ? '' : "--add-host #{host}:host-gateway",
110
+ OS.linux? ? '' : "--add-host #{donce_host}:host-gateway",
106
111
  args,
107
112
  env.map { |k, v| "-e #{Shellwords.escape("#{k}=#{v}")}" }.join(' '),
108
113
  root ? '' : "--user=#{Shellwords.escape("#{Process.uid}:#{Process.gid}")}",
@@ -126,7 +131,7 @@ module Kernel
126
131
  "(exit code is ##{code}, stdout has #{stdout.split("\n").count} lines)"
127
132
  end
128
133
  if block_given?
129
- r = yield container, host
134
+ r = yield container
130
135
  return r
131
136
  end
132
137
  ensure
data/test/test_donce.rb CHANGED
@@ -36,10 +36,9 @@ class TestDonce < Minitest::Test
36
36
 
37
37
  def test_runs_daemon
38
38
  seen = false
39
- donce(dockerfile: "FROM ubuntu\nCMD while true; do sleep 1; echo sleeping; done", log: Loog::NULL) do |id, host|
39
+ donce(dockerfile: "FROM ubuntu\nCMD while true; do sleep 1; echo sleeping; done", log: Loog::NULL) do |id|
40
40
  seen = true
41
41
  refute_empty(id)
42
- refute_empty(host)
43
42
  end
44
43
  assert(seen)
45
44
  end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko