Class: Avm::EacGenericBase0::Sources::Docker::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/eac_generic_base0/sources/docker/runner.rb

Constant Summary collapse

CONTAINER_SOURCE_PATH =
'/app'

Instance Method Summary collapse

Instance Method Details

#bash_command_argsObject



35
36
37
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 35

def bash_command_args
  %w[/bin/bash]
end

#command_argsObject



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

Returns:

  • (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_nameString

Name that identifies the container associated with the source, so it can be found and reused on the next run.

Returns:

  • (String)


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_argsObject



63
64
65
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 63

def default_command_args
  bash_command_args
end

#docker_containerObject



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_imageEacDocker::Images::Base

Returns:

  • (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

Returns:

  • (Boolean)


79
80
81
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 79

def new_container?
  parsed.new? || !container_exist?
end

#runvoid

This method returns an undefined value.



21
22
23
24
# File 'lib/avm/eac_generic_base0/sources/docker/runner.rb', line 21

def run
  start_banner
  new_container? ? run_container : start_container
end

#run_containervoid

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_bannervoid

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 start_banner
  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_containervoid

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