Class: Rascal::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/rascal/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_name, name:, image:, env_variables: {}, services: [], volumes: [], before_shell: [], after_shell: [], working_dir: nil) ⇒ Environment

Returns a new instance of Environment.



5
6
7
8
9
10
11
12
13
14
15
# 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

Instance Attribute Details

#before_shellObject (readonly)

Returns the value of attribute before_shell.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def before_shell
  @before_shell
end

#containerObject (readonly)

Returns the value of attribute container.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def container
  @container
end

#env_variablesObject (readonly)

Returns the value of attribute env_variables.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def env_variables
  @env_variables
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def name
  @name
end

#networkObject (readonly)

Returns the value of attribute network.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def network
  @network
end

#servicesObject (readonly)

Returns the value of attribute services.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def services
  @services
end

#volumesObject (readonly)

Returns the value of attribute volumes.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def volumes
  @volumes
end

#working_dirObject (readonly)

Returns the value of attribute working_dir.



3
4
5
# File 'lib/rascal/environment.rb', line 3

def working_dir
  @working_dir
end

Instance Method Details

#clean(clean_volumes: false) ⇒ Object



30
31
32
33
34
# 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_shellObject



17
18
19
20
21
22
23
24
25
26
27
28
# 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: []) ⇒ Object



36
37
38
39
40
41
# File 'lib/rascal/environment.rb', line 36

def update(skip: [])
  [
    *@services.collect { |s| s.update(skip: skip) },
    *@container.update(skip: skip),
  ]
end