Class: Avm::EacGenericBase0::Sources::Docker::Runner
- Inherits:
-
Object
- Object
- Avm::EacGenericBase0::Sources::Docker::Runner
- Defined in:
- lib/avm/eac_generic_base0/sources/docker/runner.rb
Constant Summary collapse
- CONTAINER_SOURCE_PATH =
'/app'
Instance Method Summary collapse
- #bash_command_args ⇒ Object
- #command_args ⇒ Object
- #container_exist? ⇒ Boolean
-
#container_name ⇒ String
Name that identifies the container associated with the source, so it can be found and reused on the next run.
- #default_command_args ⇒ Object
- #docker_container ⇒ Object
- #docker_image ⇒ EacDocker::Images::Base
- #new_container? ⇒ Boolean
- #run ⇒ void
-
#run_container ⇒ void
Create and run a new container.
- #start_banner ⇒ void
-
#start_container ⇒ void
Start the existing container associated with the source.
Instance Method Details
#bash_command_args ⇒ Object
35 36 37 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 35 def bash_command_args %w[/bin/bash] end |
#command_args ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 39 def command_args if parsed.command_arg.any? parsed.command_arg else default_command_args end end |
#container_exist? ⇒ Boolean
48 49 50 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 48 memoize def container_exist? docker_container.exist? end |
#container_name ⇒ String
Name that identifies the container associated with the source, so it can be found and reused on the next run.
56 57 58 59 60 61 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 56 def container_name [ self.class.name.parameterize, runner_context.call(:subject).path.to_s.parameterize ].join('_') end |
#default_command_args ⇒ Object
63 64 65 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 63 def default_command_args bash_command_args end |
#docker_container ⇒ Object
67 68 69 70 71 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 67 def docker_container docker_image.container .volume(runner_context.call(:subject).path, CONTAINER_SOURCE_PATH) .interactive(true).tty(true).command_args(command_args).name(container_name) end |
#docker_image ⇒ EacDocker::Images::Base
74 75 76 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 74 def docker_image raise_abstract_method __method__ end |
#new_container? ⇒ Boolean
79 80 81 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 79 def new_container? parsed.new? || !container_exist? end |
#run ⇒ void
This method returns an undefined value.
21 22 23 24 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 21 def run new_container? ? run_container : start_container end |
#run_container ⇒ void
This method returns an undefined value.
Create and run a new container.
86 87 88 89 90 91 92 93 94 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 86 def run_container if container_exist? infom "Remove existing container \"#{container_name}\"..." docker_container.remove.execute! end infom "Creating container \"#{container_name}\"..." docker_container.run_command.system! end |
#start_banner ⇒ void
This method returns an undefined value.
27 28 29 30 31 32 33 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 27 def infov 'Image', docker_image infov 'Container name', container_name infov 'Container exist?', container_exist? infov 'New container?', new_container? infov 'Command', ::Shellwords.join(command_args) end |
#start_container ⇒ void
This method returns an undefined value.
Start the existing container associated with the source.
99 100 101 102 |
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 99 def start_container infom "Starting existing container \"#{container_name}\"..." docker_container.start_command.system! end |