Sha256: d9634605e23b70b736fe5dd91ed6b30d3b2e0e809570a2215e8fdc21bc78c002

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

class DockerHelpers
  def initialize(compose_path)
    @compose_path = compose_path
    @compose = YAML.load(File.read(compose_path))
  end

  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

  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

  def add_service(name, definition)
    service = {}
    service[name] = YAML.load(definition)
    @compose['services'].merge!(service)
    save
  end

  private

  def save
    File.open(@compose_path, 'w') { |f| f.write @compose.to_yaml }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
potassium-5.2.0 lib/potassium/helpers/docker-helpers.rb