class RubyYacht::Runner::RunContainers

This class provides a command for running all the images in new containers.

It will also remove any existing containers with conflicting names.

Public Class Methods

command() click to toggle source

THe name of the command.

# File lib/ruby_yacht/runner/run_containers.rb, line 7
def self.command; 'run_containers'; end
description() click to toggle source

The short description of the command.

# File lib/ruby_yacht/runner/run_containers.rb, line 10
def self.description; 'Runs containers for all the apps'; end

Public Instance Methods

dns_server_flags() click to toggle source

This method gets the flags for defining DNS server config when running a container.

# File lib/ruby_yacht/runner/run_containers.rb, line 36
def dns_server_flags
  flags = []
  if @project.dns_server
    flags += @project.dns_server.servers.map { |server| "--dns=#{server}" }
    flags += @project.dns_server.search_domains.map { |domain| "--dns-search=#{domain}" }
  end
  flags
end
remove_container(container_name) click to toggle source

This method removes a container.

### Parameters

  • **container_name: String** The full name of the container.

# File lib/ruby_yacht/runner/run_containers.rb, line 88
def remove_container(container_name)  
  IO.popen("docker rm -f #{container_name}", err: :close) {}
end
run() click to toggle source

This method runs the logic of the command.

# File lib/ruby_yacht/runner/run_containers.rb, line 13
def run
  projects.each do |project|
    @project = project
    @network = project.system_prefix
    
    project.databases.select(&:local?).each do |database|
      run_container database
    end
    
    project.apps.each do |app|
      run_container app
    end

    project.web_servers.each do |web_server|
      run_container web_server
    end
  end
  
  true
end
run_container(server) click to toggle source

This method runs a container.

It will also remove any existing containers with conflicting names.

### Parameters

  • **server: App/Database/WebServer** The server we are running a

    container for.
# File lib/ruby_yacht/runner/run_containers.rb, line 68
def run_container(server)
  container_name = server.container_name
  remove_container container_name
  
  flags = ["-d"]
  flags += dns_server_flags
  flags += volume_flags(server)
  flags << "-p #{server.port}:80" if server.is_a?(RubyYacht::WebServer)
  flags << "--net=#{@network}"
  flags << "--net-alias=#{container_name}"

  flag_text = flags.join(' ')
  docker "run #{flag_text} --name=#{container_name} #{container_name}"
end
volume_flags(server) click to toggle source

This method gets the flags for mapping the code volume to a local path for a container.

### Parameters

  • **server: App/Database/WebServer** The server we are running a

    container for.
# File lib/ruby_yacht/runner/run_containers.rb, line 52
def volume_flags(server)
  if @project.check_out_locally && server.is_a?(RubyYacht::App)
    return ["-v $PWD/../#{server.name}:/var/code"]
  else
    return []
  end
end