eac_docker 0.8.0 → 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: fb76d84d03b5ac717ad2ff9d7fab59de8399402fea4148105cf795b7012f76f3
4
- data.tar.gz: 2151150c28e034afe331b8c07cfc0c3aea4165b495a98eb174610a3d7de19688
3
+ metadata.gz: b7ab9fa3bac2e0412b72d2cc72bbfba976e201b41f7579b943c619c8dc100e5f
4
+ data.tar.gz: ff1730b169c326274ad6c928c503141c586907279fe1b90e720228fa62d64cfc
5
5
  SHA512:
6
- metadata.gz: cfb9ee8645109d9a41a9fce41214455b65ad62f05c095bfba27787c07e8f040f727a232b12202dbb623faca3788cdf764e2ea928d6e8b706509f822e5e04d09c
7
- data.tar.gz: 1a0d46709c2af0b410dcfc47db46c356b295634ddf03514a0d860a95d343fc89331a0bfc9a9330beedfd20fcb5b77b32d36d1e558a91cc6c066ab8feea03d379
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
 
@@ -32,7 +32,7 @@ module EacDocker
32
32
  end
33
33
 
34
34
  def write_in_provide_dir
35
- template.apply(variables_source, provide_dir)
35
+ eac_template.apply(variables_source, provide_dir)
36
36
  end
37
37
 
38
38
  private
@@ -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.0'
4
+ VERSION = '0.9.0'
5
5
  end
data/lib/eac_docker.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils'
4
- EacRubyUtils::RootModuleSetup.perform __FILE__
5
-
6
- module EacDocker
3
+ require 'eac_ruby_base1'
4
+ EacRubyBase1::RootModuleSetup.perform __FILE__ do
5
+ require 'eac_templates'
7
6
  end
8
-
9
- require 'eac_templates'
metadata CHANGED
@@ -1,77 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
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: 2025-08-14 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
- name: eac_ruby_utils
13
+ name: eac_ruby_base1
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0.128'
18
+ version: '0.1'
20
19
  - - ">="
21
20
  - !ruby/object:Gem::Version
22
- version: 0.128.2
21
+ version: 0.1.1
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - "~>"
28
27
  - !ruby/object:Gem::Version
29
- version: '0.128'
28
+ version: '0.1'
30
29
  - - ">="
31
30
  - !ruby/object:Gem::Version
32
- version: 0.128.2
31
+ version: 0.1.1
33
32
  - !ruby/object:Gem::Dependency
34
33
  name: eac_templates
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
36
  - - "~>"
38
37
  - !ruby/object:Gem::Version
39
- version: '0.8'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 0.8.1
38
+ version: '0.9'
43
39
  type: :runtime
44
40
  prerelease: false
45
41
  version_requirements: !ruby/object:Gem::Requirement
46
42
  requirements:
47
43
  - - "~>"
48
44
  - !ruby/object:Gem::Version
49
- version: '0.8'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 0.8.1
45
+ version: '0.9'
53
46
  - !ruby/object:Gem::Dependency
54
47
  name: eac_ruby_gem_support
55
48
  requirement: !ruby/object:Gem::Requirement
56
49
  requirements:
57
50
  - - "~>"
58
51
  - !ruby/object:Gem::Version
59
- version: '0.12'
52
+ version: '0.15'
60
53
  type: :development
61
54
  prerelease: false
62
55
  version_requirements: !ruby/object:Gem::Requirement
63
56
  requirements:
64
57
  - - "~>"
65
58
  - !ruby/object:Gem::Version
66
- version: '0.12'
67
- description:
68
- email:
59
+ version: '0.15'
69
60
  executables: []
70
61
  extensions: []
71
62
  extra_rdoc_files: []
72
63
  files:
73
64
  - lib/eac_docker.rb
74
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
75
70
  - lib/eac_docker/debug.rb
76
71
  - lib/eac_docker/executables.rb
77
72
  - lib/eac_docker/images/base.rb
@@ -82,10 +77,8 @@ files:
82
77
  - lib/eac_docker/rspec/setup.rb
83
78
  - lib/eac_docker/rspec/stub_image.rb
84
79
  - lib/eac_docker/version.rb
85
- homepage:
86
80
  licenses: []
87
81
  metadata: {}
88
- post_install_message:
89
82
  rdoc_options: []
90
83
  require_paths:
91
84
  - lib
@@ -93,15 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
86
  requirements:
94
87
  - - ">="
95
88
  - !ruby/object:Gem::Version
96
- version: '2.7'
89
+ version: '3.2'
97
90
  required_rubygems_version: !ruby/object:Gem::Requirement
98
91
  requirements:
99
92
  - - ">="
100
93
  - !ruby/object:Gem::Version
101
94
  version: '0'
102
95
  requirements: []
103
- rubygems_version: 3.1.6
104
- signing_key:
96
+ rubygems_version: 3.6.9
105
97
  specification_version: 4
106
98
  summary: Put here de description.
107
99
  test_files: []