Class: Gembrew::DockerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/gembrew/docker_runner.rb

Constant Summary collapse

IMAGE =
'homebrew/brew:main'
TAP_PATH =
'/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/gembrew/homebrew-tap'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path: Pathname.pwd, command_runner: nil) ⇒ DockerRunner

Returns a new instance of DockerRunner.



10
11
12
13
# File 'lib/gembrew/docker_runner.rb', line 10

def initialize(project_path: Pathname.pwd, command_runner: nil)
  @project_path = Pathname(project_path).expand_path
  @command_runner = command_runner || method(:run_command)
end

Instance Attribute Details

#project_pathObject (readonly)

Returns the value of attribute project_path.



8
9
10
# File 'lib/gembrew/docker_runner.rb', line 8

def project_path
  @project_path
end

Instance Method Details

#call(*command, interactive: false, pristine: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gembrew/docker_runner.rb', line 15

def call(*command, interactive: false, pristine: false)
  docker_command = ['docker', 'run', '--rm', '--init', '--name', container_name]
  docker_command << '--pull=always' if pristine
  docker_command << '-it' if interactive
  docker_command.concat environment(interactive: interactive, pristine: pristine)
  unless pristine
    docker_command.push '--workdir', '/work'
    docker_command.push '--volume', "#{project_path}:/work"
    docker_command.push '--volume', "#{project_path}:#{TAP_PATH}"
  end
  docker_command << IMAGE
  docker_command.concat command
  command_runner.call(*docker_command, chdir: project_path)
end