Class: DockerHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/potassium/helpers/docker-helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(compose_path) ⇒ DockerHelpers

Returns a new instance of DockerHelpers.



2
3
4
5
# File 'lib/potassium/helpers/docker-helpers.rb', line 2

def initialize(compose_path)
  @compose_path = compose_path
  @compose = YAML.safe_load(File.read(compose_path))
end

Instance Method Details

#add_env(target_service, variable_key, variable_value) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/potassium/helpers/docker-helpers.rb', line 16

def add_env(target_service, variable_key, variable_value)
  service = @compose['services'][target_service]
  unless service['environment'].is_a? Hash
    service['environment'] = {}
  end
  service['environment'][variable_key] = variable_value
  save
end


7
8
9
10
11
12
13
14
# File 'lib/potassium/helpers/docker-helpers.rb', line 7

def add_link(target_service, linked_service)
  service = @compose['services'][target_service]
  unless service['links'].is_a? Array
    service['links'] = []
  end
  service['links'].push(linked_service)
  save
end

#add_service(name, definition) ⇒ Object



25
26
27
# File 'lib/potassium/helpers/docker-helpers.rb', line 25

def add_service(name, definition)
  add_leaf('services', name, definition)
end

#add_volume(name, definition = '') ⇒ Object



29
30
31
# File 'lib/potassium/helpers/docker-helpers.rb', line 29

def add_volume(name, definition = '')
  add_leaf('volumes', name, definition)
end