eac_docker 0.8.1 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54c66f9c5d78f503cd8b905a9707f9f9e4ca009dbf25c302710ce7ae7491de9b
4
- data.tar.gz: '02049efabac40fd5d2d6ec91e5ea0cab0e04f56c25955dbeeea0feb067fe4a37'
3
+ metadata.gz: b7ab9fa3bac2e0412b72d2cc72bbfba976e201b41f7579b943c619c8dc100e5f
4
+ data.tar.gz: ff1730b169c326274ad6c928c503141c586907279fe1b90e720228fa62d64cfc
5
5
  SHA512:
6
- metadata.gz: 4027a6350739c55ab076729fd43072f57cad99d004462189929fe18971149234a2257e5ee72f25058a21d21c1bb7810d49945b1bc93999a9c2ff4d3b1dc43061
7
- data.tar.gz: 4d9130fe2d1827e3aa4cd2f2f438b34b06031122138cd3793063d2f533382160845fe6d8c403e3ba4b05483ff1f671253986336049f71b0911306cac561dddf6
6
+ metadata.gz: 0744a0dcee991434317cb8233ba18b7eb3f657ab625fb619ecd7d1e942b64db1f7e88e37bd82548f7ec3667e3ba9bbd80b8cb4172c57acda9b21be7bcf31208e
7
+ data.tar.gz: 774b285e7cfc47ec13506438f935170e39fea6869fda96a36026efabeb897fdd86993af09cf4eccd33b659480e905a17387320171a729a87fa42e8b54c86b403
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacDocker
4
+ class Container
5
+ # Verify if a container identified by {#id}, if present, or {#name} already exists
6
+ # (running or not).
7
+ class Exist
8
+ acts_as_instance_method name_mark: :'?'
9
+ common_constructor :container
10
+ delegate :id, :name, to: :container
11
+
12
+ # @return [Boolean]
13
+ def result # rubocop:disable Naming/PredicateMethod
14
+ ::EacDocker::Executables.docker.command(
15
+ 'ps', '--all', '--quiet', '--filter', filter
16
+ ).execute!.present?
17
+ end
18
+
19
+ # Filter used by {#result}: by {#id}, if present, or by {#name}.
20
+ #
21
+ # @return [String]
22
+ def filter
23
+ id.presence ? "id=#{id}" : "name=^/#{name}$"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacDocker
4
+ class Container
5
+ module Identifiers
6
+ common_concern do
7
+ immutable_accessor :name, type: :common
8
+ end
9
+
10
+ attr_reader :id
11
+
12
+ # Value that identifies the container to Docker commands: {#id}, if present, or {#name}.
13
+ #
14
+ # @return [String]
15
+ def identifier
16
+ id.presence || name.presence || raise('Neither `id` or `name` is present ' \
17
+ '- need at least one of them')
18
+ end
19
+
20
+ protected
21
+
22
+ attr_writer :id
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacDocker
4
+ class Container
5
+ class RunCommand
6
+ acts_as_instance_method
7
+ common_constructor :container, :extra_args, default: [[]]
8
+ delegate :capabilities, :command_args, :envs, :image, :interactive?, :name, :temporary?,
9
+ :tty?, :volumes, to: :container
10
+
11
+ # @return [EacRubyUtils::Envs::Command]
12
+ def result
13
+ ::EacDocker::Executables.docker.command('run', *all_args)
14
+ end
15
+
16
+ # @return [Array<String>]
17
+ def all_args
18
+ %w[boolean capabilities envs name volumes]
19
+ .inject([]) { |a, e| a + send("#{e}_args") } +
20
+ extra_args + [image.provide.id] + command_args
21
+ end
22
+
23
+ # @return [Array<String>]
24
+ def boolean_args
25
+ r = []
26
+ r << '--interactive' if interactive?
27
+ r << '--tty' if tty?
28
+ r << '--rm' if temporary?
29
+ r
30
+ end
31
+
32
+ # @return [Array<String>]
33
+ def capabilities_args
34
+ capabilities.flat_map { |capability| ['--cap-add', capability] }
35
+ end
36
+
37
+ # @return [Array<String>]
38
+ def envs_args
39
+ envs.flat_map { |name, value| ['--env', "#{name}=#{value}"] }
40
+ end
41
+
42
+ # @return [Array<String>]
43
+ def name_args
44
+ name.if_present([]) { |v| ['--name', v] }
45
+ end
46
+
47
+ # @return [Array<String>]
48
+ def volumes_args
49
+ volumes.flat_map { |volume| ['--volume', volume] }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacDocker
4
+ class Container
5
+ # Start an already existing container identified by {#id}, if present, or {#name}.
6
+ class StartCommand
7
+ acts_as_instance_method
8
+ common_constructor :container
9
+ delegate :identifier, :interactive?, :tty?, to: :container
10
+
11
+ # @return [EacRubyUtils::Envs::Command]
12
+ def result
13
+ ::EacDocker::Executables.docker.command('start', *start_args)
14
+ end
15
+
16
+ # @return [Array<String>]
17
+ def start_args
18
+ r = []
19
+ r << '--attach' if interactive? || tty?
20
+ r << '--interactive' if interactive?
21
+ r << identifier
22
+ r
23
+ end
24
+ end
25
+ end
26
+ end
@@ -6,7 +6,6 @@ module EacDocker
6
6
  immutable_accessor :interactive, :temporary, :tty, type: :boolean
7
7
  immutable_accessor :env, type: :hash
8
8
  immutable_accessor :capability, :command_arg, :volume, type: :array
9
- attr_reader :id
10
9
 
11
10
  common_constructor :image
12
11
 
@@ -29,8 +28,7 @@ module EacDocker
29
28
  end
30
29
 
31
30
  def on_detached
32
- command = ::EacDocker::Executables.docker.command(*(%w[run --detach] + run_command_args))
33
- self.id = command.execute!.strip
31
+ self.id = run_command(%w[--detach]).execute!.strip
34
32
  begin
35
33
  yield(self)
36
34
  ensure
@@ -42,42 +40,17 @@ module EacDocker
42
40
  immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
43
41
  end
44
42
 
45
- def run_command
46
- ::EacDocker::Executables.docker.command('run', *run_command_args)
47
- end
48
-
49
- def run_command_args
50
- %w[boolean capabilities envs volumes]
51
- .inject([]) { |a, e| a + send("run_command_#{e}_args") } +
52
- [image.provide.id] + command_args
43
+ # Force removal of the container identified by {#id}, if present, or {#name}.
44
+ #
45
+ # @return [String] output of the "docker rm" command.
46
+ def remove_command
47
+ ::EacDocker::Executables.docker.command('rm', '--force', identifier)
53
48
  end
54
49
 
55
50
  def stop
56
51
  ::EacDocker::Executables.docker.command('stop', id).execute!
57
52
  end
58
53
 
59
- private
60
-
61
- attr_writer :id
62
-
63
- def run_command_boolean_args
64
- r = []
65
- r << '--interactive' if interactive?
66
- r << '--tty' if tty?
67
- r << '--rm' if temporary?
68
- r
69
- end
70
-
71
- def run_command_capabilities_args
72
- capabilities.flat_map { |capability| ['--cap-add', capability] }
73
- end
74
-
75
- def run_command_volumes_args
76
- volumes.flat_map { |volume| ['--volume', volume] }
77
- end
78
-
79
- def run_command_envs_args
80
- envs.flat_map { |name, value| ['--env', "#{name}=#{value}"] }
81
- end
54
+ require_sub __FILE__, require_mode: :kernel, include_modules: true
82
55
  end
83
56
  end
@@ -5,12 +5,18 @@ module EacDocker
5
5
  class Named < ::EacDocker::Images::Base
6
6
  common_constructor :source_tag
7
7
 
8
+ # @return [Boolean]
9
+ def exist?
10
+ ::EacDocker::Executables.docker.command('image', 'inspect', source_tag).execute
11
+ .fetch(:exit_code).zero?
12
+ end
13
+
8
14
  def id
9
15
  source_tag
10
16
  end
11
17
 
12
18
  def provide
13
- provide_command.execute!
19
+ provide_command.execute! unless exist?
14
20
  self
15
21
  end
16
22
 
@@ -18,13 +18,13 @@ module EacDocker
18
18
  internal_container
19
19
  end
20
20
 
21
- def on_container(&block)
21
+ def on_container(&)
22
22
  raise 'A container was already created' if internal_container.present?
23
23
 
24
24
  build_container.on_detached do |container|
25
25
  self.internal_container = container
26
26
  begin
27
- run_callbacks(:on_container, &block)
27
+ run_callbacks(:on_container, &)
28
28
  ensure
29
29
  self.internal_container = nil
30
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacDocker
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-07-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: eac_ruby_base1
@@ -50,22 +49,24 @@ dependencies:
50
49
  requirements:
51
50
  - - "~>"
52
51
  - !ruby/object:Gem::Version
53
- version: '0.14'
52
+ version: '0.15'
54
53
  type: :development
55
54
  prerelease: false
56
55
  version_requirements: !ruby/object:Gem::Requirement
57
56
  requirements:
58
57
  - - "~>"
59
58
  - !ruby/object:Gem::Version
60
- version: '0.14'
61
- description:
62
- email:
59
+ version: '0.15'
63
60
  executables: []
64
61
  extensions: []
65
62
  extra_rdoc_files: []
66
63
  files:
67
64
  - lib/eac_docker.rb
68
65
  - lib/eac_docker/container.rb
66
+ - lib/eac_docker/container/exist.rb
67
+ - lib/eac_docker/container/identifiers.rb
68
+ - lib/eac_docker/container/run_command.rb
69
+ - lib/eac_docker/container/start_command.rb
69
70
  - lib/eac_docker/debug.rb
70
71
  - lib/eac_docker/executables.rb
71
72
  - lib/eac_docker/images/base.rb
@@ -76,10 +77,8 @@ files:
76
77
  - lib/eac_docker/rspec/setup.rb
77
78
  - lib/eac_docker/rspec/stub_image.rb
78
79
  - lib/eac_docker/version.rb
79
- homepage:
80
80
  licenses: []
81
81
  metadata: {}
82
- post_install_message:
83
82
  rdoc_options: []
84
83
  require_paths:
85
84
  - lib
@@ -94,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
93
  - !ruby/object:Gem::Version
95
94
  version: '0'
96
95
  requirements: []
97
- rubygems_version: 3.4.19
98
- signing_key:
96
+ rubygems_version: 3.6.9
99
97
  specification_version: 4
100
98
  summary: Put here de description.
101
99
  test_files: []