class Rascal::Environment

Attributes

before_shell[R]
container[R]
env_variables[R]
name[R]
network[R]
services[R]
volumes[R]
working_dir[R]

Public Class Methods

new(full_name, name:, image:, env_variables: {}, services: [], volumes: [], before_shell: [], after_shell: [], working_dir: nil) click to toggle source
# File lib/rascal/environment.rb, line 5
def initialize(full_name, name:, image:, env_variables: {}, services: [], volumes: [], before_shell: [], after_shell: [], working_dir: nil)
  @name = name
  @network = Docker::Network.new(full_name)
  @container = Docker::Container.new(full_name, image)
  @env_variables = env_variables
  @services = services
  @volumes = volumes
  @working_dir = working_dir
  @before_shell = before_shell
  @after_shell = after_shell
end

Public Instance Methods

clean(clean_volumes: false) click to toggle source
# File lib/rascal/environment.rb, line 30
def clean(clean_volumes: false)
  @services.each(&:clean)
  @network.clean
  @volumes.each(&:clean) if clean_volumes
end
run_shell() click to toggle source
# File lib/rascal/environment.rb, line 17
def run_shell
  download_missing
  start_services
  command = [*@before_shell, 'bash', *@after_shell].join(';')
  @container.run_and_attach('bash', '-c', command,
    env: @env_variables,
    network: @network,
    volumes: @volumes,
    working_dir: @working_dir,
    allow_failure: true
  )
end
update(skip: []) click to toggle source
# File lib/rascal/environment.rb, line 36
def update(skip: [])
  [
    *@services.collect { |s| s.update(skip: skip) },
    *@container.update(skip: skip),
  ]
end

Private Instance Methods

download_missing() click to toggle source
# File lib/rascal/environment.rb, line 45
def download_missing
  @container.download_missing
  @services.each(&:download_missing)
end
start_services() click to toggle source
# File lib/rascal/environment.rb, line 50
def start_services
  @network.create unless @network.exists?
  @services.each { |s| s.start_if_stopped(network: @network) }
end